-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: header alignment and request pw
- Loading branch information
1 parent
88fc50c
commit b9552b9
Showing
8 changed files
with
112 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useEffect, useRef } from 'react'; | ||
|
||
import { noop } from '@shared/utils'; | ||
|
||
export function useInterval(callback: () => void, delay: number | null) { | ||
const savedCallback = useRef(noop); | ||
|
||
// Remember the latest callback. | ||
useEffect(() => { | ||
if (savedCallback) { | ||
savedCallback.current = callback; | ||
} | ||
}, [callback]); | ||
|
||
// Set up the interval. | ||
useEffect(() => { | ||
function tick() { | ||
savedCallback.current(); | ||
} | ||
if (delay !== null) { | ||
const id = setInterval(tick, delay); | ||
return () => clearInterval(id); | ||
} | ||
return; | ||
}, [delay]); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useMemo, useRef, useState } from 'react'; | ||
|
||
import { useInterval } from './use-interval'; | ||
|
||
// Keys are the seconds to wait before showing the message | ||
export type WaitingMessages = Record<number, string>; | ||
|
||
function messageForSecondsPassed(waitingMessages: WaitingMessages, seconds: number) { | ||
return waitingMessages[seconds as keyof typeof waitingMessages]; | ||
} | ||
|
||
export const useWaitingMessage = ( | ||
waitingMessages: WaitingMessages, | ||
{ waitingMessageInterval } = { | ||
waitingMessageInterval: 1000, | ||
} | ||
): [boolean, string, () => void, () => void] => { | ||
const [isRunning, setIsRunning] = useState(false); | ||
const [waitingMessage, setWaitingMessage] = useState(messageForSecondsPassed(waitingMessages, 0)); | ||
const handlers = useMemo( | ||
() => ({ | ||
startWaitingMessage: () => setIsRunning(true), | ||
stopWaitingMessage: () => setIsRunning(false), | ||
}), | ||
[] | ||
); | ||
const secondsPassed = useRef(0); | ||
|
||
useInterval( | ||
() => { | ||
secondsPassed.current += waitingMessageInterval / 1000; | ||
const newMessage = messageForSecondsPassed(waitingMessages, secondsPassed.current); | ||
if (newMessage) setWaitingMessage(newMessage); | ||
}, | ||
isRunning ? waitingMessageInterval : null | ||
); | ||
|
||
return [isRunning, waitingMessage, handlers.startWaitingMessage, handlers.stopWaitingMessage]; | ||
}; |
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
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