Skip to content

Commit

Permalink
Merge pull request #61 from wp-graphql/feat/multiple-queries-per-temp…
Browse files Browse the repository at this point in the history
…late

feat: multiple queries per template
  • Loading branch information
jasonbahl authored Jan 23, 2024
2 parents 4b52071 + 635b5e2 commit 0b5fadb
Show file tree
Hide file tree
Showing 14 changed files with 321 additions and 388 deletions.
3 changes: 2 additions & 1 deletion components/FieldTypesList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export function FieldTypesList({ data }) {
fieldType?.featuredImage?.node.altText ??
'screenshot of the field type'
}
className="m-auto shrink-0 text-center"
layout="responsive"
className="shrink-0"
/>
)}
<div className="mt-auto">
Expand Down
24 changes: 12 additions & 12 deletions components/Layout.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { gql } from '@apollo/client'
import { flatListToHierarchical } from '@faustwp/core'
import { flatListToHierarchical, useFaustQuery } from '@faustwp/core'
import clsx from 'clsx'
import Link from 'next/link'
import { useCallback, useEffect, useState } from 'react'
Expand All @@ -13,8 +13,8 @@ import { SiteHeader } from '@/components/SiteHeader'
import { SitewideNotice } from '@/components/SitewideNotice'
import { collectHeadings } from '@/lib/utils'

Layout.fragment = gql`
fragment LayoutFragment on RootQuery {
export const LAYOUT_QUERY = gql`
query LayoutFragment {
...SitewideNoticeFragment
...PrimaryNavigationFragment
...DocsSidebarNavigationFragment
Expand Down Expand Up @@ -75,26 +75,24 @@ function useTableOfContents(tableOfContents) {
return currentSection
}

export function Layout({ data, children, toc, title }) {
export function Layout({ node, children, toc, title }) {
const { sitewideNotice, primaryMenuItems, footerMenuItems, docsSidebarMenuItems } = useFaustQuery(LAYOUT_QUERY);
let tableOfContents = toc && toc.length ? collectHeadings(toc) : []

const primaryMenuItems = data?.primaryMenuItems ?? []
const primaryNavigation = primaryMenuItems?.nodes
? flatListToHierarchical(primaryMenuItems.nodes, {
idKey: 'id',
childrenKey: 'links',
parentKey: 'parentId',
})
: []
const footerMenuItems = data?.footerMenuItems ?? []
const footerNavigation = footerMenuItems?.nodes
? flatListToHierarchical(footerMenuItems.nodes, {
idKey: 'id',
childrenKey: 'links',
parentKey: 'parentId',
})
: []
const docsSidebarMenuItems = data?.docsSidebarMenuItems ?? []
const docsSidebarNavigation = docsSidebarMenuItems?.nodes
? flatListToHierarchical(docsSidebarMenuItems.nodes, {
idKey: 'id',
Expand All @@ -105,13 +103,13 @@ export function Layout({ data, children, toc, title }) {
let docsSidebarAllLinks =
docsSidebarNavigation?.flatMap((section) => section.links) ?? []
let linkIndex = docsSidebarAllLinks.findIndex((link) => {
return link.href === data?.node?.uri
return link.href === node?.uri
})
let previousPage = docsSidebarAllLinks[linkIndex - 1]

let nextPage = docsSidebarAllLinks[linkIndex + 1]
let section = docsSidebarAllLinks.find((section) =>
section.links.find((link) => link.href === data?.node?.uri),
section.links.find((link) => link.href === node?.uri),
)
let currentSection = useTableOfContents(tableOfContents)

Expand All @@ -127,8 +125,8 @@ export function Layout({ data, children, toc, title }) {

return (
<>
<SitewideNotice displayNotice={data.sitewideNotice.sitewideNoticeFields.displayNotice} message={data.sitewideNotice.sitewideNoticeFields.message} />
<SiteHeader navigation={primaryNavigation} isNoticeVisible={data.sitewideNotice.sitewideNoticeFields.displayNotice} />
<SitewideNotice displayNotice={sitewideNotice.sitewideNoticeFields.displayNotice} message={sitewideNotice.sitewideNoticeFields.message} />
<SiteHeader navigation={primaryNavigation} isNoticeVisible={sitewideNotice.sitewideNoticeFields.displayNotice} />

<main className='content'>
<div className="relative mx-auto flex max-w-8xl justify-center sm:px-2 lg:px-8 xl:px-12">
Expand All @@ -138,7 +136,9 @@ export function Layout({ data, children, toc, title }) {
<div className="absolute bottom-0 right-0 top-28 hidden w-px bg-slate-800 dark:block" />
<div className="sticky top-[4.5rem] -ml-0.5 h-[calc(100vh-4.5rem)] w-64 overflow-y-auto overflow-x-hidden py-16 pl-0.5 pr-8 xl:w-72 xl:pr-16">
<DocsSidebarNavigation
data={data}
data={{
node
}}
navigation={docsSidebarNavigation}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/LayoutArchive.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { SiteFooter } from '@/components/SiteFooter'
import { SiteHeader } from '@/components/SiteHeader'
import { SitewideNotice } from '@/components/SitewideNotice'

LayoutArchive.fragment = gql`
fragment LayoutArchiveFragment on RootQuery {
export const LAYOUT_ARCHIVE_QUERY = gql`
query LayoutArchive {
...SitewideNoticeFragment
...PrimaryNavigationFragment
...DocsSidebarNavigationFragment
Expand Down
17 changes: 9 additions & 8 deletions components/LayoutFrontPage.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { gql } from '@apollo/client'
import { flatListToHierarchical } from '@faustwp/core'
import { flatListToHierarchical, useFaustQuery } from '@faustwp/core'

import { FooterNavigation } from './FooterNavigation'
import { SiteFooter } from './SiteFooter'
Expand All @@ -9,8 +9,8 @@ import { SiteHeader } from '@/components/SiteHeader'
import { SitewideNotice } from '@/components/SitewideNotice'


LayoutFrontPage.fragment = gql`
fragment LayoutFrontPageFragment on RootQuery {
export const LAYOUT_FRONT_PAGE_QUERY = gql`
query LayoutFrontPageFragment {
...SitewideNoticeFragment
...PrimaryNavigationFragment
...FooterNavigationFragment
Expand All @@ -20,16 +20,17 @@ LayoutFrontPage.fragment = gql`
${FooterNavigation.fragment}
`

export function LayoutFrontPage({ data, children }) {
const primaryMenuItems = data?.primaryMenuItems ?? []
export function LayoutFrontPage({ children }) {

const { sitewideNotice, primaryMenuItems, footerMenuItems } = useFaustQuery(LAYOUT_FRONT_PAGE_QUERY);

const primaryNavigation = primaryMenuItems?.nodes
? flatListToHierarchical(primaryMenuItems.nodes, {
idKey: 'id',
childrenKey: 'links',
parentKey: 'parentId',
})
: []
const footerMenuItems = data?.footerMenuItems ?? []
const footerNavigation = footerMenuItems?.nodes
? flatListToHierarchical(footerMenuItems.nodes, {
idKey: 'id',
Expand All @@ -39,8 +40,8 @@ export function LayoutFrontPage({ data, children }) {
: []
return (
<>
<SitewideNotice displayNotice={data.sitewideNotice.sitewideNoticeFields.displayNotice} message={data.sitewideNotice.sitewideNoticeFields.message} />
<SiteHeader navigation={primaryNavigation} data={data} isNoticeVisible={data.sitewideNotice.sitewideNoticeFields.displayNotice} />
<SitewideNotice displayNotice={sitewideNotice?.sitewideNoticeFields?.displayNotice} message={sitewideNotice?.sitewideNoticeFields?.message} />
<SiteHeader navigation={primaryNavigation} isNoticeVisible={sitewideNotice?.sitewideNoticeFields?.displayNotice} />
<main className='content'>
{children}
</main>
Expand Down
Loading

2 comments on commit 0b5fadb

@headless-platform-by-wp-engine

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out the recent updates to your Atlas environment:

App Environment URL Build
acf.wpgraphql.com main https://hb…wered.com ✅ (logs)

Learn more about building on Atlas in our documentation.

@headless-platform-by-wp-engine

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out the recent updates to your Atlas environment:

App Environment URL Build
acf.wpgraphql.com main https://hb…wered.com ✅ (logs)

Learn more about building on Atlas in our documentation.

Please sign in to comment.