-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Eric Oliver <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ryan Koch <[email protected]>
- Loading branch information
1 parent
d60d3c1
commit c670c93
Showing
15 changed files
with
100 additions
and
110 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
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
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,45 +1,31 @@ | ||
import { formatter } from '@/data/queries/banners' | ||
import { drupalClient } from '@/lib/drupal/drupalClient' | ||
import { LayoutProps } from '@/templates/globals/wrapper' | ||
import { NodeBanner } from '@/types/drupal/node' | ||
import { queries } from '@/data/queries' | ||
|
||
const nonSlugRoute = `${process.env.NEXT_PUBLIC_DRUPAL_BASE_URL}/jsonapi/banner-alerts?item-path=/` | ||
|
||
// Helper function to fetch global elements for layout. | ||
// It is called once for every page on build. | ||
// TODO: add cache layer to drupalClient query results | ||
|
||
// Helper function to fetch global elements for layout. This is called once for every page during a build, | ||
// because banners are associated with individual pages via slug lookup (itemPath). | ||
export async function getGlobalElements( | ||
jsonApiEntryPoint?: string, | ||
itemPath?: string, | ||
headerOnly: boolean = false | ||
): Promise<LayoutProps> { | ||
let banners = [] | ||
// This query is cached so header and footer menu data is only directly requested once per build. | ||
const headerFooterData = await queries.getData('header-footer-data') | ||
|
||
// If we are not in headerOnly mode and the necessary parameters are provided, fetch banners | ||
// move all of this into @/data/queries/banners.ts | ||
if (!headerOnly && jsonApiEntryPoint && itemPath) { | ||
let bannerPath = `${jsonApiEntryPoint}/banner-alerts?item-path=${itemPath}` | ||
// Banners can be fetched as long as we have context and a path (slug). | ||
if (!headerOnly && itemPath) { | ||
// Gather data for banners currently visible on this page. | ||
const bannerData = await queries.getData('banner-data', { | ||
itemPath, | ||
}) | ||
|
||
if (itemPath.includes('home')) { | ||
bannerPath = nonSlugRoute | ||
return { | ||
bannerData, | ||
headerFooterData, | ||
} | ||
|
||
const requestBanner = await drupalClient.fetch(`${bannerPath}`) | ||
const bannerData: [] | unknown = drupalClient.deserialize( | ||
await requestBanner.json() | ||
) | ||
banners = formatter(bannerData as NodeBanner[]) | ||
|
||
// gather data for banners currently visible on this page | ||
// const bannerData = await queries.getData('banner--alerts_lookup') | ||
} | ||
|
||
const headerFooterData = await queries.getData('header-footer-data') | ||
|
||
// Otherwise return header data without banners. | ||
return { | ||
bannerData: banners, | ||
bannerData: [], | ||
headerFooterData, | ||
} | ||
} |
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
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
Oops, something went wrong.