Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pmelab committed Dec 8, 2023
1 parent 5c9b493 commit 423703d
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 46 deletions.
70 changes: 34 additions & 36 deletions apps/website/src/layouts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,55 @@
import { SilverbackPageContext } from '@amazeelabs/gatsby-source-silverback';
import { NavigationFragment } from '@custom/schema';
import {
FooterQuery,
FrameQuery,
HeaderQuery,
registerOperator,
} from '@custom/schema';
import { IntlProvider } from '@custom/ui/intl';
import { Frame } from '@custom/ui/routes/Frame';
import { graphql, useStaticQuery, WrapPageElementNodeArgs } from 'gatsby';
import React, { PropsWithChildren } from 'react';

function useFrameQuery() {
return useStaticQuery<{
main_de: NavigationFragment;
main_en: NavigationFragment;
footer_de: NavigationFragment;
footer_en: NavigationFragment;
}>(graphql`
export default function Layout({
children,
pageContext: { locale },
}: PropsWithChildren<
WrapPageElementNodeArgs<any, SilverbackPageContext>['props']
>) {
// TODO: Remove duplication of queries here.
const data = useStaticQuery<FrameQuery>(graphql`
query Frame {
main_de: mainNavigation(_langcode: { eq: "de" }) {
main_en: mainNavigation(locale: "en") {
...Navigation
}
main_en: mainNavigation(_langcode: { eq: "en" }) {
items {
...NavigationItem
}
main_de: mainNavigation(locale: "de") {
...Navigation
}
footer_de: footerNavigation(_langcode: { eq: "de" }) {
items {
...NavigationItem
}
footer_de: footerNavigation(locale: "de") {
...Navigation
}
footer_en: footerNavigation(_langcode: { eq: "en" }) {
items {
...NavigationItem
}
footer_en: footerNavigation(locale: "en") {
...Navigation
}
}
`);
}

export default function Layout({
children,
pageContext: { locale },
}: PropsWithChildren<
WrapPageElementNodeArgs<any, SilverbackPageContext>['props']
>) {
const data = useFrameQuery();
const main = locale === 'de' ? data.main_de : data.main_en;
const footer = locale === 'de' ? data.footer_de : data.footer_en;
registerOperator(
() => ({
mainNavigation: main,
}),
HeaderQuery,
);
registerOperator(
() => ({
footerNavigation: footer,
}),
FooterQuery,
);
return (
<IntlProvider locale={locale || 'en'}>
<Frame
header={{ mainNavigation: main }}
footer={{ footerNavigation: footer }}
>
{children}
</Frame>
<Frame>{children}</Frame>
</IntlProvider>
);
}
4 changes: 2 additions & 2 deletions packages/schema/src/operations/Footer.gql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query Footer {
footerNavigation {
query Footer($locale: String!) {
footerNavigation(locale: $locale) {
...Navigation
}
}
14 changes: 14 additions & 0 deletions packages/schema/src/operations/Frame.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
query Frame {
main_en: mainNavigation(locale: "en") {
...Navigation
}
main_de: mainNavigation(locale: "de") {
...Navigation
}
footer_en: footerNavigation(locale: "en") {
...Navigation
}
footer_de: footerNavigation(locale: "de") {
...Navigation
}
}
4 changes: 2 additions & 2 deletions packages/schema/src/operations/Header.gql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query Header {
mainNavigation {
query Header($locale: String!) {
mainNavigation(locale: $locale) {
...Navigation
}
}
5 changes: 0 additions & 5 deletions packages/schema/src/operations/PreviewPage.gql

This file was deleted.

5 changes: 5 additions & 0 deletions packages/schema/src/operations/ViewPage.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query ViewPage($id: ID!, $rid: ID!, $locale: String!) {
page(id: $id, rid: $rid, locale: $locale) {
...Page
}
}
14 changes: 13 additions & 1 deletion packages/schema/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ scalar Url @default @value(json: "\"\"")
scalar Markup @default @value(json: "\"\"")
scalar ImageSource @default @value(json: "\"\"")

"""
implementation(gatsby): @custom/schema#fetchNavigation
"""
directive @fetchNavigation(type: String!, locale: String!) on FIELD_DEFINITION

enum Locale @default @value(json: "\"en\"") {
en
de
Expand Down Expand Up @@ -127,8 +132,15 @@ input PaginationInput {
}

type Query {
previewPage(id: ID!, rid: ID, locale: String!): Page
mainNavigation(locale: String!): MainNavigation
@fetchNavigation(type: "MainNavigation", locale: "$locale")

footerNavigation(locale: String!): FooterNavigation
@fetchNavigation(type: "FooterNavigation", locale: "$locale")

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

contentHub(query: String, pagination: PaginationInput!): ContentHubResult!
@contentHub(query: "$query", pagination: "$pagination")
}
Expand Down

0 comments on commit 423703d

Please sign in to comment.