Skip to content

Commit

Permalink
removed debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
mkbeefcake committed Dec 5, 2022
1 parent 40114a8 commit d301b49
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 39 deletions.
12 changes: 1 addition & 11 deletions packages/ui/src/app/pages/Election/Election.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { useHistory } from 'react-router-dom'
import { PageHeaderRow, PageHeaderWrapper, PageLayout } from '@/app/components/PageLayout'
import { ButtonsGroup, CopyButtonTemplate } from '@/common/components/buttons'
import { LinkIcon } from '@/common/components/icons'
import { LinkSymbol } from '@/common/components/icons/symbols'
import { Loading } from '@/common/components/Loading'
import { MainPanel } from '@/common/components/page/PageContent'
import { PageTitle } from '@/common/components/page/PageTitle'
import { BlockDurationStatistics, StatisticItem, Statistics } from '@/common/components/statistics'
import { TextHuge, TextMedium } from '@/common/components/typography'
import { TextHuge } from '@/common/components/typography'
import { camelCaseToText } from '@/common/helpers'
import { useCustomEvent } from '@/common/hooks/useCustomEvent'
import { useRefetchQueries } from '@/common/hooks/useRefetchQueries'
import { MILLISECONDS_PER_BLOCK } from '@/common/model/formatters'
import { getUrl } from '@/common/utils/getUrl'
Expand Down Expand Up @@ -58,14 +56,6 @@ export const Election = () => {
}
}, [electionStage])

const { onceEvent } = useCustomEvent()

useEffect(() => {
onceEvent('RefreshElectionPageEvent', () => {
history.go(0)
})
}, [])

if (isLoadingElectionStage) {
return <PageLayout header={null} main={<Loading />} />
}
Expand Down
25 changes: 0 additions & 25 deletions packages/ui/src/common/hooks/useCustomEvent.ts

This file was deleted.

12 changes: 12 additions & 0 deletions packages/ui/src/common/hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,23 @@ export const useLocalStorage = <T>(key?: string) => {
setState(getItem(key))
}, [key])

useEffect(() => {
const handleEventOnce = (event: any) => {
setState(getItem(key))
}

document.addEventListener(`storage_event_${key}`, handleEventOnce)
return () => {
document.removeEventListener(`storage_event_${key}`, handleEventOnce)
}
}, [])

const dispatch = useCallback(
(setStateAction: T | ((prevState?: T) => T)) => {
const value = isFunction(setStateAction) ? setStateAction(getItem(key)) : setStateAction
setState(value)
setItem(key, value)
document.dispatchEvent(new CustomEvent(`storage_event_${key}`, {}))
},
[key]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as Yup from 'yup'
import { ButtonPrimary } from '@/common/components/buttons'
import { FileEntry, FileInput } from '@/common/components/forms/FileInput'
import { Modal, ModalBody, ModalHeader, ModalFooter } from '@/common/components/Modal'
import { useCustomEvent } from '@/common/hooks/useCustomEvent'
import { useLocalStorage } from '@/common/hooks/useLocalStorage'
import { useModal } from '@/common/hooks/useModal'
import { dedupeObjects } from '@/common/utils'
Expand Down Expand Up @@ -68,7 +67,6 @@ export const RestoreVotesModal = () => {
} = useModal<RestoreVotesModalCall>()
const [votingAttempts, setVotingAttempts] = useLocalStorage<VotingAttempt[]>(`votes:${cycleId}`)
const [value, dispatch] = useReducer(valueReducer(cycleId), undefined)
const { triggerEvent } = useCustomEvent()

const onUpload = useCallback(async ([file]: File[]) => {
if (!file) return
Expand All @@ -84,7 +82,6 @@ export const RestoreVotesModal = () => {
try {
VotingAttemptsSchema.validateSync(votingAttempts)
setVotingAttempts(dedupeObjects([...(votingAttempts ?? []), ...content.votingAttempts]))
triggerEvent('RefreshElectionPageEvent', {})
} catch (error) {
if (error instanceof Yup.ValidationError) {
setVotingAttempts(content.votingAttempts)
Expand Down

0 comments on commit d301b49

Please sign in to comment.