-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #517 from social-tw/fix/hide-notification-after-ch…
…ecking-in-successfully [Fix] [Frontend] [Relay] Improve check in flow
- Loading branch information
Showing
12 changed files
with
113 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export const SERVER = process.env.REACT_APP_SERVER ?? 'http://localhost:8000' | ||
export const KEY_SERVER = `${SERVER}/build/` | ||
export const NUM_EPOCH_KEY_NONCE_PER_EPOCH = 3 | ||
export const CHECKED_IN_AT = 'checked-in-at' | ||
export const DISCARDED_CHECK_IN_AT = 'discarded-check-in-at' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 33 additions & 13 deletions
46
packages/frontend/src/features/reporting/hooks/useNotifyCheckIn/useNotifyCheckIn.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,57 @@ | ||
import { CHECKED_IN_AT, DISCARDED_CHECK_IN_AT } from '@/constants/config' | ||
import { useReputationScore } from '@/features/reporting' | ||
import { useLocalStorage } from '@uidotdev/usehooks' | ||
import dayjs from 'dayjs' | ||
import { useEffect, useMemo } from 'react' | ||
|
||
const DISCARDED_AT = 'discarded-checkin-at' | ||
import { useEffect } from 'react' | ||
|
||
export function useNotifyCheckIn() { | ||
const { reputationScore } = useReputationScore() | ||
|
||
const [discardedAt, saveDiscardedAt] = useLocalStorage<string | null>( | ||
DISCARDED_AT, | ||
const [checkedInAt, setCheckedInAt] = useLocalStorage<string | null>( | ||
CHECKED_IN_AT, | ||
null, | ||
) | ||
|
||
const isOpen = useMemo( | ||
() => !!reputationScore && reputationScore < 0 && !discardedAt, | ||
[reputationScore, discardedAt], | ||
const [discardedAt, setDiscardedAt] = useLocalStorage<string | null>( | ||
DISCARDED_CHECK_IN_AT, | ||
null, | ||
) | ||
|
||
const discard = () => { | ||
saveDiscardedAt(new Date().toISOString()) | ||
const isOpen = | ||
!!reputationScore && reputationScore < 0 && !checkedInAt && !discardedAt | ||
|
||
const startCheckIn = () => { | ||
setCheckedInAt(new Date().toISOString()) | ||
} | ||
|
||
const failCheckIn = () => { | ||
setCheckedInAt(null) | ||
} | ||
|
||
const discardCheckIn = () => { | ||
setDiscardedAt(new Date().toISOString()) | ||
} | ||
|
||
useEffect(() => { | ||
if (!checkedInAt || dayjs().isSame(dayjs(checkedInAt), 'day')) { | ||
return | ||
} | ||
|
||
setCheckedInAt(null) | ||
}, [checkedInAt, setCheckedInAt]) | ||
|
||
useEffect(() => { | ||
if (!discardedAt || dayjs().isSame(dayjs(discardedAt), 'day')) { | ||
return | ||
} | ||
|
||
saveDiscardedAt(null) | ||
}, [discardedAt, saveDiscardedAt]) | ||
setDiscardedAt(null) | ||
}, [discardedAt, setDiscardedAt]) | ||
|
||
return { | ||
isOpen, | ||
discard, | ||
startCheckIn, | ||
failCheckIn, | ||
discardCheckIn, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters