-
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
7 changed files
with
70 additions
and
46 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,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> | ||
); | ||
} |
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,5 +1,5 @@ | ||
query Footer { | ||
footerNavigation { | ||
query Footer($locale: String!) { | ||
footerNavigation(locale: $locale) { | ||
...Navigation | ||
} | ||
} |
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 |
---|---|---|
@@ -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 | ||
} | ||
} |
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,5 +1,5 @@ | ||
query Header { | ||
mainNavigation { | ||
query Header($locale: String!) { | ||
mainNavigation(locale: $locale) { | ||
...Navigation | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
query ViewPage($id: ID!, $rid: ID!, $locale: String!) { | ||
page(id: $id, rid: $rid, locale: $locale) { | ||
...Page | ||
} | ||
} |
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