diff --git a/apps/app/src/app/routes/app/admin/AdminSheetDraftRoute.tsx b/apps/app/src/app/routes/app/admin/AdminSheetDraftRoute.tsx
index 6be2c76a..aeeef8eb 100644
--- a/apps/app/src/app/routes/app/admin/AdminSheetDraftRoute.tsx
+++ b/apps/app/src/app/routes/app/admin/AdminSheetDraftRoute.tsx
@@ -59,13 +59,14 @@ function useReadOnly(mode: EditorMode, canEdit: boolean): boolean {
*/
/**
* The drawing guard (R-12) as the shell's own question: a link of the shell and the
- * sign-out ask « Abandonner le déplacement ? » before the sheet-level question. A started
- * move also guards a reload or a tab close; one with nothing started arms nothing.
+ * sign-out ask « Abandonner le déplacement ? » (or « … la création ? ») before the
+ * sheet-level question, and a link is intercepted only while such work is at stake. A
+ * started move also guards a reload or a tab close; one with nothing started arms nothing.
*/
function useDrawingLeaveAsk() {
const setAsk = useLeaveGuardStore((s) => s.setAsk)
useEffect(() => {
- setAsk(guardDrawing)
+ setAsk(guardDrawing, () => guardWork(useAnnotationWork.getState()) !== null)
return () => setAsk(null)
}, [setAsk])
useBeforeUnload(useAnnotationWork((work) => guardWork(work) !== null))
diff --git a/apps/app/src/components/shell/AppLayout.tsx b/apps/app/src/components/shell/AppLayout.tsx
index 0a8ae188..f0208428 100644
--- a/apps/app/src/components/shell/AppLayout.tsx
+++ b/apps/app/src/components/shell/AppLayout.tsx
@@ -11,7 +11,10 @@ import { useT } from '@/i18n/useT'
/** The draft editor takes the whole width (board 04's three columns). */
const DRAFT_EDITOR_PATH = '/app/admin/sheets/:sheetId/draft'
-/** An in-app link a plain click would follow: same origin, same tab, no modifier key. */
+/**
+ * An in-app link a plain click would follow: same origin, same tab, no modifier key, not
+ * a download (it leaves no page).
+ */
function followedLink(event: MouseEvent): HTMLAnchorElement | null {
if (event.defaultPrevented || event.button !== 0) return null
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
@@ -22,6 +25,7 @@ function followedLink(event: MouseEvent): HTMLAnchorElement | null {
if (
!anchor ||
anchor.target === '_blank' ||
+ anchor.hasAttribute('download') ||
anchor.origin !== window.location.origin
)
return null
@@ -44,11 +48,12 @@ export default function AppLayout() {
const arm = useLeaveGuardStore((s) => s.arm)
const [leaveTo, setLeaveTo] = useState
draft page
+ + page link + + + download link +account page from {from}
} const account = () => screen.getAllByRole('link', { @@ -326,9 +360,9 @@ describe('AppLayout and a started move on the drawing (R-12)', () => { screen.getByRole('dialog', { name: 'Abandonner le déplacement ?' }), ).toBeInTheDocument() expect(screen.queryByText(fr['leave.title'])).toBeNull() - expect(screen.queryByText('account page')).toBeNull() + expect(screen.queryByText(/account page/)).toBeNull() await user.click(screen.getByRole('button', { name: 'Abandonner' })) - expect(await screen.findByText('account page')).toBeInTheDocument() + expect(await screen.findByText(/account page/)).toBeInTheDocument() }) it('with sheet changes too: the drawing question, then the leave question', async () => { @@ -340,7 +374,7 @@ describe('AppLayout and a started move on the drawing (R-12)', () => { expect(screen.queryByText(fr['leave.title'])).toBeNull() await user.click(screen.getByRole('button', { name: 'Abandonner' })) expect(await screen.findByText(fr['leave.title'])).toBeInTheDocument() - expect(screen.queryByText('account page')).toBeNull() + expect(screen.queryByText(/account page/)).toBeNull() }) it('a started redraw asks « Abandonner le nouveau tracé ? » before a link', async () => { @@ -352,19 +386,37 @@ describe('AppLayout and a started move on the drawing (R-12)', () => { expect( screen.getByRole('dialog', { name: 'Abandonner le nouveau tracé ?' }), ).toBeInTheDocument() - expect(screen.queryByText('account page')).toBeNull() + expect(screen.queryByText(/account page/)).toBeNull() await user.click(screen.getByRole('button', { name: 'Abandonner' })) - expect(await screen.findByText('account page')).toBeInTheDocument() + expect(await screen.findByText(/account page/)).toBeInTheDocument() expect(useAnnotationWork.getState().mode).toBeNull() }) - it('a move with nothing started leaves at once and ends', async () => { + it('a move with nothing started is not at stake: the link goes at once', async () => { const user = userEvent.setup() mountDraft() startMove('a', 'doc') await user.click(account()) - expect(await screen.findByText('account page')).toBeInTheDocument() - expect(useAnnotationWork.getState().mode).toBeNull() + expect(await screen.findByText(/account page/)).toBeInTheDocument() + }) + + it("with nothing at stake a page link is the router's own: its state reaches the page", async () => { + const user = userEvent.setup() + mountDraft() + await user.click(screen.getByRole('link', { name: 'page link' })) + expect( + await screen.findByText('account page from draft'), + ).toBeInTheDocument() + }) + + it('a download link is never taken, even with a started move', async () => { + const user = userEvent.setup() + mountDraft() + started() + downloads.length = 0 + await user.click(screen.getByRole('link', { name: 'download link' })) + expect(downloads).toEqual([false]) + expect(screen.queryByRole('dialog')).toBeNull() }) })