このコミットが含まれているのは:
@@ -35,7 +35,7 @@ const UnsavedChangesGuardContext =
|
||||
export const UnsavedChangesGuardProvider: FC<PropsWithChildren> = ({ children }) => {
|
||||
const dialogue = useDialogue ()
|
||||
const sourcesRef = useRef (new Map<symbol, UnsavedChangesSource> ())
|
||||
const bypassNextNavigationRef = useRef (false)
|
||||
const bypassNextNavigationRef = useRef<symbol | null> (null)
|
||||
const [revision, setRevision] = useState (0)
|
||||
const dialogueOpenRef = useRef (false)
|
||||
|
||||
@@ -55,7 +55,13 @@ export const UnsavedChangesGuardProvider: FC<PropsWithChildren> = ({ children })
|
||||
}, [])
|
||||
|
||||
const allowNextNavigation = useCallback (() => {
|
||||
bypassNextNavigationRef.current = true
|
||||
const token = Symbol ('allowed-navigation')
|
||||
bypassNextNavigationRef.current = token
|
||||
|
||||
queueMicrotask (() => {
|
||||
if (bypassNextNavigationRef.current === token)
|
||||
bypassNextNavigationRef.current = null
|
||||
})
|
||||
}, [])
|
||||
|
||||
const sources = useMemo (
|
||||
@@ -68,16 +74,13 @@ export const UnsavedChangesGuardProvider: FC<PropsWithChildren> = ({ children })
|
||||
)
|
||||
const hasUnsavedChanges = dirtySources.length > 0
|
||||
const shouldBlock = useCallback (() => {
|
||||
if (!(hasUnsavedChanges))
|
||||
return false
|
||||
|
||||
if (bypassNextNavigationRef.current)
|
||||
if (bypassNextNavigationRef.current != null)
|
||||
{
|
||||
bypassNextNavigationRef.current = false
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
return hasUnsavedChanges
|
||||
}, [hasUnsavedChanges])
|
||||
const blocker = useBlocker (shouldBlock)
|
||||
|
||||
|
||||
新しい課題から参照
ユーザをブロックする