Skip to content

Commit

Permalink
refactor: changed all post variable name to node
Browse files Browse the repository at this point in the history
  • Loading branch information
tobi-bams committed Oct 18, 2023
1 parent 30b89c0 commit 7ca551e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/components/App/SideBar/Latest/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ type Props = {

// eslint-disable-next-line no-underscore-dangle
const _View = ({ isSearchResult }: Props) => {
const [postCount, setPostCount] = useUserStore((s) => [s.postCount, s.setPostCount])
const [nodeCount, setNodeCount] = useUserStore((s) => [s.nodeCount, s.setNodeCount])
const [fetchData] = [useDataStore((s) => s.fetchData)]

async function getLatest() {
if (postCount < 1) {
if (nodeCount < 1) {
return
}

await fetchData()
setPostCount('CLEAR')
setNodeCount('CLEAR')
}

return (
Expand All @@ -36,7 +36,7 @@ const _View = ({ isSearchResult }: Props) => {
</span>
</div>
<div className="button_container">
<button onClick={getLatest} type="button">{`New Node (${postCount})`}</button>
<button onClick={getLatest} type="button">{`New Node (${nodeCount})`}</button>
</div>
</div>
)}
Expand Down
12 changes: 6 additions & 6 deletions src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const Version = styled(Flex)`
export const App = () => {
const { open } = useModal('budgetExplanation')

const [setBudget, setPostCount] = useUserStore((s) => [s.setBudget, s.setPostCount])
const [setBudget, setNodeCount] = useUserStore((s) => [s.setBudget, s.setNodeCount])

const [
setSidebarOpen,
Expand Down Expand Up @@ -153,9 +153,9 @@ export const App = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [graphStyle])

const handleNewPost = useCallback(() => {
setPostCount('INCREMENT')
}, [setPostCount])
const handleNewNode = useCallback(() => {
setNodeCount('INCREMENT')
}, [setNodeCount])

// setup socket
useEffect(() => {
Expand All @@ -164,11 +164,11 @@ export const App = () => {
}

if (socket) {
socket.on('newpost', handleNewPost)
socket.on('newnode', handleNewNode)

isSocketSet.current = true
}
}, [socket, handleNewPost])
}, [socket, handleNewNode])

return (
<AppProviders>
Expand Down
14 changes: 7 additions & 7 deletions src/stores/useUserStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ export type UserStore = {
setPubKey: (val: string) => void
budget: number | null
setBudget: (val: number | null) => void
postCount: number
setPostCount: (action: ActionType) => void
nodeCount: number
setNodeCount: (action: ActionType) => void
}

const defaultData: Omit<UserStore, 'setIsAdmin' | 'setPubKey' | 'setBudget' | 'setPostCount'> = {
const defaultData: Omit<UserStore, 'setIsAdmin' | 'setPubKey' | 'setBudget' | 'setNodeCount'> = {
isAdmin: false,
pubKey: '',
budget: 0,
postCount: 0,
nodeCount: 0,
}

export const useUserStore = create<UserStore>((set) => ({
...defaultData,
setIsAdmin: (isAdmin) => set({ isAdmin }),
setPubKey: (pubKey) => set({ pubKey }),
setBudget: (budget) => set({ budget }),
setPostCount: (action: ActionType) =>
setNodeCount: (action: ActionType) =>
set((state) => {
if (action === 'INCREMENT') {
return { postCount: state.postCount + 1 }
return { nodeCount: state.nodeCount + 1 }
}

return { postCount: 0 }
return { nodeCount: 0 }
}),
}))

0 comments on commit 7ca551e

Please sign in to comment.