File
Blob: src/client/components/page-mention/shared-surface.tsx
| 1 | import { useCallback, useMemo, type ReactNode } from "react"; |
| 2 | import { useNavigate } from "@tanstack/react-router"; |
| 3 | import { PageMentionProvider } from "./provider"; |
| 4 | import { useOnline } from "@/client/hooks/use-online"; |
| 5 | import { useReadyShareView } from "@/client/components/share/use-share-view"; |
| 6 | |
| 7 | /** |
| 8 | * Shared surface page-mention provider. `/s/:token` is always link-scoped — |
| 9 | * resolution uses the share token, and mention navigation stays inside the |
| 10 | * shared shell. If product ever wants "member opening a share link becomes |
| 11 | * canonical viewer," that is a redirect out of the shared shell, not a |
| 12 | * route-kind branch here. |
| 13 | */ |
| 14 | export function SharedPageMentionSurface({ children }: { children: ReactNode }) { |
| 15 | const navigate = useNavigate(); |
| 16 | const share = useReadyShareView(); |
| 17 | const online = useOnline(); |
| 18 | |
| 19 | const scopeKey = useMemo( |
| 20 | () => ["shared", share.workspaceId, share.token].join(":"), |
| 21 | [share.workspaceId, share.token], |
| 22 | ); |
| 23 | |
| 24 | const handleNavigate = useCallback( |
| 25 | (pageId: string) => { |
| 26 | navigate({ |
| 27 | to: "/s/$token", |
| 28 | params: { token: share.token }, |
| 29 | search: { page: pageId === share.rootPageId ? undefined : pageId }, |
| 30 | }); |
| 31 | }, |
| 32 | [navigate, share.rootPageId, share.token], |
| 33 | ); |
| 34 | |
| 35 | return ( |
| 36 | <PageMentionProvider |
| 37 | workspaceId={share.workspaceId} |
| 38 | scopeKey={scopeKey} |
| 39 | shareToken={share.token} |
| 40 | cacheMode="live" |
| 41 | networkEnabled={online} |
| 42 | navigate={handleNavigate} |
| 43 | > |
| 44 | {children} |
| 45 | </PageMentionProvider> |
| 46 | ); |
| 47 | } |