Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pmelab committed Jun 14, 2024
1 parent bdb49b5 commit a41720d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
9 changes: 3 additions & 6 deletions packages/ui/src/components/Routes/NotFoundPage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
'use client';
import { NotFoundPageQuery, useLocalized } from '@custom/schema';
import { NotFoundPageQuery, useLocalized, withOperation } from '@custom/schema';
import React from 'react';

import { useOperation } from '../../utils/operation';
import { PageDisplay } from '../Organisms/PageDisplay';

export function NotFoundPage() {
const { data } = useOperation(NotFoundPageQuery);
const page = useLocalized(data?.websiteSettings?.notFoundPage?.translations);
export const NotFoundPage = withOperation(NotFoundPageQuery, ({operationResult}) => {
const page = useLocalized(operationResult.websiteSettings?.notFoundPage?.translations);
return page ? <PageDisplay {...page} /> : <div />;
}
39 changes: 24 additions & 15 deletions packages/ui/src/components/Routes/Page.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
'use client';
import { useLocation, ViewPageQuery } from '@custom/schema';
import { useLocation, ViewPageQuery, withOperation } from '@custom/schema';
import React from 'react';

import { isTruthy } from '../../utils/isTruthy';
import { useOperation } from '../../utils/operation';
import { Translations } from '../../utils/translations';
import { PageDisplay } from '../Organisms/PageDisplay';

export const PageWithData = withOperation(
ViewPageQuery,
({ operationResult }) => {
// Initialize the language switcher with the options this page has.
const translations = Object.fromEntries(
operationResult?.page?.translations
?.filter(isTruthy)
.map((translation) => [translation.locale, translation.path]) || [],
);
return operationResult?.page ? (
<Translations translations={translations}>
<PageDisplay {...operationResult.page} />
</Translations>
) : null;
},
);

export function Page() {
// Retrieve the current location and load the page
// behind it.
const [loc] = useLocation();
const { data } = useOperation(ViewPageQuery, { pathname: loc.pathname });

// Initialize the language switcher with the options this page has.
const translations = Object.fromEntries(
data?.page?.translations
?.filter(isTruthy)
.map((translation) => [translation.locale, translation.path]) || [],
return (
<PageWithData
operationVariables={{
pathname: loc.pathname,
}}
/>
);
return data?.page ? (
<Translations translations={translations}>
<PageDisplay {...data.page} />
</Translations>
) : null;
}

0 comments on commit a41720d

Please sign in to comment.