Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pmelab committed Dec 9, 2023
1 parent 9f881ba commit 9415570
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 38 deletions.
13 changes: 6 additions & 7 deletions apps/decap/src/collections/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ImageSource, PreviewPageQuery, Url } from '@custom/schema';
import { ImageSource, Url, ViewPageQuery } from '@custom/schema';
import {
BlockMarkupSource,
BlockMediaSource,
Expand Down Expand Up @@ -220,6 +220,7 @@ export function PagePreview({
const previewSourceData = parsed.success
? parsed.data
: ({
id: '',
__typename: 'Page',
title: '[Missing title]',
path: '/preview' as Url,
Expand All @@ -230,10 +231,10 @@ export function PagePreview({
// data into the exact shape of the query result expected by the
// route.
const data = useQuery(
PreviewPageQuery,
ViewPageQuery,
{
previewPage: previewSourceData,
} satisfies PreviewPageQuery,
page: previewSourceData,
} satisfies ViewPageQuery,
{
id: '',
rid: '',
Expand All @@ -243,8 +244,6 @@ export function PagePreview({
);

return (
<PreviewFrame>
{data?.previewPage ? <Page page={data.previewPage} /> : null}
</PreviewFrame>
<PreviewFrame>{data?.page ? <Page page={data.page} /> : null}</PreviewFrame>
);
}
20 changes: 13 additions & 7 deletions apps/decap/src/helpers/frame.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FrameQuery, registerOperator, Url } from '@custom/schema';
import { FrameQuery, Locale, registerOperator, Url } from '@custom/schema';
import { NavigationItemSource } from '@custom/schema/source';
import { IntlProvider } from '@custom/ui/intl';
import { Frame } from '@custom/ui/routes/Frame';
Expand All @@ -18,12 +18,18 @@ const menuItems = (amount: number) =>
export function PreviewFrame({ children }: PropsWithChildren) {
registerOperator(
() => ({
mainNavigation: {
items: menuItems(4),
},
footerNavigation: {
items: menuItems(4),
},
mainNavigation: [
{
locale: Locale.En,
items: menuItems(4),
},
],
footerNavigation: [
{
locale: Locale.En,
items: menuItems(4),
},
],
}),
FrameQuery,
);
Expand Down
34 changes: 17 additions & 17 deletions apps/website/src/preview/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@

import {
drupalOperator,
PreviewPageQuery,
registerOperator,
useOperation,
ViewPageQuery,
} from '@custom/schema';
import { Loading } from '@custom/ui/routes/Loading';
import { Page } from '@custom/ui/routes/Page';
// import { Page } from '@custom/ui/routes/Page';
import React from 'react';

import { usePreviewParameters } from '../utils/preview';
// import { usePreviewParameters } from '../utils/preview';

export default function PagePreview() {
const { nid, rid, lang } = usePreviewParameters();
// const { nid, rid, lang } = usePreviewParameters();
registerOperator(
drupalOperator(`${process.env.GATSBY_DRUPAL_URL}/graphql`),
PreviewPageQuery,
ViewPageQuery,
);
const data = useOperation(
PreviewPageQuery,
nid && rid && lang
? {
id: nid,
rid: rid,
locale: lang,
}
: undefined,
);
return data?.previewPage ? <Page page={data.previewPage} /> : <Loading />;
return <Loading />;
// const data = useOperation(
// PreviewPageQuery,
// nid && rid && lang
// ? {
// id: nid,
// rid: rid,
// locale: lang,
// }
// : undefined,
// );
// return data?.previewPage ? <Page page={data.previewPage} /> : <Loading />;
}
10 changes: 10 additions & 0 deletions packages/schema/src/operations/ListPages.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fragment PageListEntry on Page {
id
locale
}

query ListPages {
allPages {
...PageListEntry
}
}
3 changes: 3 additions & 0 deletions packages/schema/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ A generic page.
type Page implements ContentHubResultItem
@entity(type: "node", bundle: "page")
@type(id: "page") {
id: ID! @resolveEntityId
locale: Locale! @resolveEntityLanguage
path: Url! @resolveEntityPath @isPath
title: String! @resolveProperty(path: "title.value")
Expand Down Expand Up @@ -134,6 +135,8 @@ type Query {

footerNavigation: [FooterNavigation] @gatsbyNodes(type: "FooterNavigation")

allPages: [Page] @gatsbyNodes(type: "Page")

page(id: ID!, rid: ID, locale: String!): Page
@fetchEntity(type: "node", id: "$id", rid: "$rid", language: "$locale")

Expand Down
8 changes: 1 addition & 7 deletions packages/ui/src/components/Organisms/Header.stories.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
FrameQuery,
Locale,
Navigation,
NavigationItemFragment,
Url,
} from '@custom/schema';
import { FrameQuery, Locale, Navigation, Url } from '@custom/schema';
import { Meta, StoryObj } from '@storybook/react';
import { userEvent, within } from '@storybook/testing-library';

Expand Down

0 comments on commit 9415570

Please sign in to comment.