Skip to content

Instantly share code, notes, and snippets.

@covelitein
Created September 19, 2023 21:59
Show Gist options
  • Save covelitein/af525c04ae5c5610da6a8e9b48c6072d to your computer and use it in GitHub Desktop.
Save covelitein/af525c04ae5c5610da6a8e9b48c6072d to your computer and use it in GitHub Desktop.
dappworks
import { createGlobalState } from 'react-hooks-global-state'
const { setGlobalState, useGlobalState, getGlobalState } = createGlobalState({
connectedAccount: '',
currentUser: null,
createModal: 'scale-0',
updateModal: 'scale-0',
deleteModal: 'scale-0',
payoutModal: 'scale-0',
jobs: [],
jobListing: null,
myjobs: [],
mygigs: [],
mybidjobs: [],
job: null,
bidders: [],
freelancers: [],
freelancer: null,
status: null,
recentConversations: [],
messages: [],
})
const truncate = (text, startChars, endChars, maxLength) => {
if (text.length > maxLength) {
let start = text.substring(0, startChars)
let end = text.substring(text.length - endChars, text.length)
while (start.length + end.length < maxLength) {
start = start + '.'
}
return start + end
}
return text
}
const formatDate = (timestamp) => {
const date = new Date(timestamp)
const options = {
year: 'numeric',
month: 'long',
day: 'numeric',
}
return date.toLocaleDateString(undefined, options)
}
const timestampToDate = (timestamp) => {
const date = new Date(timestamp)
const options = {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
}
return date.toLocaleDateString('en-US', options)
}
export {
setGlobalState,
useGlobalState,
getGlobalState,
truncate,
formatDate,
timestampToDate,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment