-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |