Skip to content

Commit

Permalink
Fix simple URLs for newspaper card links
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvicenti committed Oct 22, 2024
1 parent 7a7cd62 commit d5c046c
Show file tree
Hide file tree
Showing 4 changed files with 813 additions and 791 deletions.
11 changes: 8 additions & 3 deletions frontend/apps/web/app/document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -93,10 +94,14 @@ export function DocumentPage(props: SiteDocumentPayload) {
/>
);
if (document.metadata.layout === "Seed/Experimental/Newspaper") {
return <NewspaperPage {...props} />;
return (
<SiteRoutingProvider homeId={props.homeId}>
<NewspaperPage {...props} />;
</SiteRoutingProvider>
);
}
return (
<>
<SiteRoutingProvider homeId={props.homeId}>
<YStack marginBottom={300}>
<PageHeader
homeMetadata={homeMetadata}
Expand Down Expand Up @@ -152,7 +157,7 @@ export function DocumentPage(props: SiteDocumentPayload) {
<MobileOutline open={open} onClose={() => setOpen(false)}>
<DocumentOutline document={document} onClose={() => setOpen(false)} />
</MobileOutline>
</>
</SiteRoutingProvider>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -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 (
<UniversalRoutingProvider
value={{
...(context || {
openRoute: () => {},
}),
siteHomeId: homeId,
}}
>
{children}
</UniversalRoutingProvider>
)
}

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 {
Expand Down
1 change: 0 additions & 1 deletion frontend/packages/ui/src/newspaper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export function BannerNewspaperCard({
>
<NewspaperCardContent banner entity={entity} />
<NewspaperCardFooter
banner
entity={entity}
item={item}
accountsMetadata={accountsMetadata}
Expand Down
Loading

0 comments on commit d5c046c

Please sign in to comment.