-
Notifications
You must be signed in to change notification settings - Fork 204
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
1 parent
da2a462
commit eef4326
Showing
18 changed files
with
301 additions
and
113 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
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
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
File renamed without changes.
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
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
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,88 @@ | ||
import { removeEdgesAndNodes } from '@bigcommerce/catalyst-client'; | ||
import { cache } from 'react'; | ||
|
||
import { SidebarMenu } from '@/vibes/soul/sections/sidebar-menu'; | ||
import { StickySidebarLayout } from '@/vibes/soul/sections/sticky-sidebar-layout'; | ||
import { client } from '~/client'; | ||
import { graphql } from '~/client/graphql'; | ||
import { revalidate } from '~/client/revalidate-target'; | ||
|
||
interface Props extends React.PropsWithChildren { | ||
params: Promise<{ id: string }>; | ||
} | ||
|
||
const WebPageChildrenQuery = graphql(` | ||
query WebPageChildren($id: ID!) { | ||
node(id: $id) { | ||
... on WebPage { | ||
children(first: 20) { | ||
edges { | ||
node { | ||
name | ||
... on NormalPage { | ||
path | ||
} | ||
... on ContactPage { | ||
path | ||
} | ||
... on RawHtmlPage { | ||
path | ||
} | ||
... on ExternalLinkPage { | ||
link | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
interface PageLink { | ||
label: string; | ||
href: string; | ||
} | ||
|
||
const getWebPageChildren = cache(async (id: string): Promise<PageLink[]> => { | ||
const { data } = await client.fetch({ | ||
document: WebPageChildrenQuery, | ||
variables: { id: decodeURIComponent(id) }, | ||
fetchOptions: { next: { revalidate } }, | ||
}); | ||
|
||
if (!data.node) { | ||
return []; | ||
} | ||
|
||
if (!('children' in data.node)) { | ||
return []; | ||
} | ||
|
||
const { children } = data.node; | ||
|
||
return removeEdgesAndNodes(children).reduce((acc: PageLink[], child) => { | ||
if ('path' in child) { | ||
return [...acc, { label: child.name, href: child.path }]; | ||
} | ||
|
||
if ('link' in child) { | ||
return [...acc, { label: child.name, href: child.link }]; | ||
} | ||
|
||
return acc; | ||
}, []); | ||
}); | ||
|
||
export default async function WebPageLayout({ params, children }: Props) { | ||
const { id } = await params; | ||
|
||
return ( | ||
<StickySidebarLayout | ||
sidebar={<SidebarMenu links={getWebPageChildren(id)} />} | ||
sidebarSize="small" | ||
> | ||
{children} | ||
</StickySidebarLayout> | ||
); | ||
} |
38 changes: 38 additions & 0 deletions
38
core/app/[locale]/(default)/webpages/[id]/normal/page-data.ts
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,38 @@ | ||
import { cache } from 'react'; | ||
|
||
import { client } from '~/client'; | ||
import { graphql } from '~/client/graphql'; | ||
import { revalidate } from '~/client/revalidate-target'; | ||
import { BreadcrumbsWebPageFragment } from '~/components/breadcrumbs/fragment'; | ||
|
||
const NormalPageQuery = graphql( | ||
` | ||
query NormalPageQuery($id: ID!) { | ||
node(id: $id) { | ||
... on NormalPage { | ||
__typename | ||
name | ||
...BreadcrumbsFragment | ||
htmlBody | ||
entityId | ||
seo { | ||
pageTitle | ||
metaDescription | ||
metaKeywords | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
[BreadcrumbsWebPageFragment], | ||
); | ||
|
||
export const getWebpageData = cache(async (variables: { id: string }) => { | ||
const { data } = await client.fetch({ | ||
document: NormalPageQuery, | ||
variables, | ||
fetchOptions: { next: { revalidate } }, | ||
}); | ||
|
||
return data; | ||
}); |
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
33 changes: 0 additions & 33 deletions
33
core/app/[locale]/(default)/webpages/normal/[id]/page-data.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.