diff --git a/frontend/apps/web/app/document.tsx b/frontend/apps/web/app/document.tsx index f09b0c64..a59a9afd 100644 --- a/frontend/apps/web/app/document.tsx +++ b/frontend/apps/web/app/document.tsx @@ -10,6 +10,7 @@ import { NodeOutline, UnpackedHypermediaId, } from "@shm/shared"; +import {SiteRoutingProvider} from "@shm/shared/src/routing"; import {Container} from "@shm/ui/src/container"; import {DirectoryItem} from "@shm/ui/src/directory"; import {CommentGroup} from "@shm/ui/src/discussion"; @@ -93,10 +94,14 @@ export function DocumentPage(props: SiteDocumentPayload) { /> ); if (document.metadata.layout === "Seed/Experimental/Newspaper") { - return ; + return ( + + ; + + ); } return ( - <> + setOpen(false)}> setOpen(false)} /> - + ); } diff --git a/frontend/packages/shared/src/routing.ts b/frontend/packages/shared/src/routing.tsx similarity index 62% rename from frontend/packages/shared/src/routing.ts rename to frontend/packages/shared/src/routing.tsx index 4e379105..657cf60d 100644 --- a/frontend/packages/shared/src/routing.ts +++ b/frontend/packages/shared/src/routing.tsx @@ -1,10 +1,11 @@ -import {createContext, useContext} from 'react' +import {createContext, PropsWithChildren, useContext} from 'react' import {GestureResponderEvent} from 'react-native' import {NavRoute} from './routes' import {idToUrl, UnpackedHypermediaId} from './utils' type UniversalRoutingContextValue = { openRoute: (route: NavRoute) => void + siteHomeId?: UnpackedHypermediaId | null } const UniversalRoutingContext = @@ -21,13 +22,38 @@ export function useOpenRoute() { } } +export function SiteRoutingProvider({ + homeId, + children, +}: PropsWithChildren<{ + homeId?: UnpackedHypermediaId | null +}>) { + const context = useContext(UniversalRoutingContext) + console.log('== we out here', homeId) + return ( + {}, + }), + siteHomeId: homeId, + }} + > + {children} + + ) +} + export function useRouteLink( route: NavRoute, siteHomeId?: UnpackedHypermediaId, ) { const context = useContext(UniversalRoutingContext) + console.log('== lfg', context) const href = - route.key === 'document' ? idToUrl(route.id, {siteHomeId}) : undefined + route.key === 'document' + ? idToUrl(route.id, {siteHomeId: siteHomeId || context?.siteHomeId}) + : undefined if (!context) throw new Error('useRouteLink must be used in a UniversalRoutingProvider') return { diff --git a/frontend/packages/ui/src/newspaper.tsx b/frontend/packages/ui/src/newspaper.tsx index ca30f0cc..26a4432f 100644 --- a/frontend/packages/ui/src/newspaper.tsx +++ b/frontend/packages/ui/src/newspaper.tsx @@ -48,7 +48,6 @@ export function BannerNewspaperCard({ >