feat(editor): drawing guard before navigations drop a started move (R-12)
The move mode lives in the work store with its document stamp. guardDrawing ends an unstarted mode at once and asks « Abandonner le déplacement ? » (DrawingGuardDialog, at workspace level) once work is started, before a tab, a section, « Aller à », Back and a history jump out of the editor; the leave guard and sign-out count started work. An undo from the header, Ctrl+Z or the message only cancels a pending mode or preview (R-13), and a document change drops a stale mode, keeping a started one to be said. ConfirmDialog takes an optional body. Strings for Task 4 added.
This commit is contained in:
1 parent
8cd1bda6c2
commit
2882821661
18 files changed
+465
-37
No files matched your search
@@ -4,7 +4,8 @@ import Dialog from '@/components/ui/Dialog'
|
||||
export interface ConfirmDialogProps {
|
||||
open: boolean
|
||||
title: string
|
||||
body: string
|
||||
/** Absent: the title is the whole question. */
|
||||
body?: string
|
||||
confirmLabel: string
|
||||
cancelLabel: string
|
||||
onConfirm: () => void
|
||||
@@ -29,7 +30,7 @@ export default function ConfirmDialog({
|
||||
onClose={onCancel}
|
||||
title={title}
|
||||
description={
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">{body}</p>
|
||||
body && <p className="text-sm text-[var(--color-ink-muted)]">{body}</p>
|
||||
}
|
||||
size="sm"
|
||||
>
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
import type { TabTier } from '@/editor/useViewport'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import DrawingGuardDialog from './annotations/DrawingGuardDialog'
|
||||
import ConflictDialog from './ConflictDialog'
|
||||
import CopyIssueNotice from './CopyIssueNotice'
|
||||
import DraftHeader from './DraftHeader'
|
||||
@@ -240,6 +241,7 @@ function Workspace(props: Props & Who) {
|
||||
{nav.live}
|
||||
</p>
|
||||
<ConflictDialog />
|
||||
<DrawingGuardDialog />
|
||||
</div>
|
||||
</EditingState>
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
import { useEditorReadOnly } from '@/editor/editingContext'
|
||||
import { commitFocusedField } from '@/editor/focusRequest'
|
||||
import { canRedo, canUndo, useEditorStore } from '@/editor/state/editorStore'
|
||||
import { cancelPending } from '@/editor/annotations/workStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import EditorGlyph from './EditorGlyph'
|
||||
|
||||
@@ -73,6 +74,8 @@ function usePress(
|
||||
return
|
||||
}
|
||||
const store = useEditorStore.getState()
|
||||
// R-13: a pending preview or mode is only cancelled; the next undo undoes.
|
||||
if (!readOnly && direction === 'undo' && cancelPending()) return
|
||||
const can = direction === 'undo' ? canUndo(store) : canRedo(store)
|
||||
if (readOnly || !can) return
|
||||
if (direction === 'undo') store.undoStep()
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useRef } from 'react'
|
||||
import { answerDrawing } from '@/editor/annotations/drawingGuard'
|
||||
import { useAnnotationWork } from '@/editor/annotations/workStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import ConfirmDialog from '../ConfirmDialog'
|
||||
|
||||
/**
|
||||
* The drawing guard's question (R-12), mounted with the workspace so it shows whatever
|
||||
* tab is in view: « Continuer » keeps the work, « Abandonner » drops it and makes the move
|
||||
* that was held.
|
||||
*/
|
||||
export default function DrawingGuardDialog() {
|
||||
const t = useT()
|
||||
const question = useAnnotationWork((s) => s.question)
|
||||
// The title stays while the dialog closes.
|
||||
const title = useRef('')
|
||||
if (question) title.current = t(`editor.annotations.guard.${question.work}`)
|
||||
return (
|
||||
<ConfirmDialog
|
||||
open={question !== null}
|
||||
title={title.current}
|
||||
confirmLabel={t('editor.annotations.guard.discard')}
|
||||
cancelLabel={t('editor.annotations.guard.continue')}
|
||||
onConfirm={() => answerDrawing(true)}
|
||||
onCancel={() => answerDrawing(false)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -2,15 +2,17 @@ import type { ReactNode } from 'react'
|
||||
import { useEditorReadOnly } from '@/editor/editingContext'
|
||||
import type { GestureMessages } from '@/editor/annotations/useGestureMessage'
|
||||
import { canUndo, useEditorStore } from '@/editor/state/editorStore'
|
||||
import { cancelPending } from '@/editor/annotations/workStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
const PILL =
|
||||
'inline-flex h-9 max-w-full items-center gap-2 rounded-md px-3 text-sm'
|
||||
|
||||
/** The header's undo (T15): the same store step, under the same conditions. */
|
||||
/** The header's undo (T15): the same store step, under the same conditions (R-13 first). */
|
||||
function undoLast(readOnly: boolean): void {
|
||||
const store = useEditorStore.getState()
|
||||
if (!readOnly && canUndo(store)) store.undoStep()
|
||||
if (readOnly || cancelPending()) return
|
||||
if (canUndo(store)) store.undoStep()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,7 @@ import Icon from '@/components/ui/Icon'
|
||||
import SignOutLossDialog from './SignOutLossDialog'
|
||||
import { hasUserCopies, removeUserCopies } from '@/editor/state/recovery'
|
||||
import { leaveGuardArmed, useEditorStore } from '@/editor/state/editorStore'
|
||||
import { guardWork, useAnnotationWork } from '@/editor/annotations/workStore'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
@@ -17,7 +18,10 @@ export default function SignOutButton({
|
||||
const navigate = useNavigate()
|
||||
const signOut = useAuthStore((s) => s.signOut)
|
||||
const userId = useAuthStore((s) => s.user?.id)
|
||||
const unsavedWork = useEditorStore(leaveGuardArmed)
|
||||
const sheetWork = useEditorStore(leaveGuardArmed)
|
||||
// A started move on the drawing is unsaved work too (R-12).
|
||||
const drawingWork = useAnnotationWork((work) => guardWork(work) !== null)
|
||||
const unsavedWork = sheetWork || drawingWork
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [confirming, setConfirming] = useState(false)
|
||||
|
||||
|
||||
Reference in new issue
Block a user