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