Skip to content

Commit

Permalink
Merge pull request #42 from Blazity/nav-query
Browse files Browse the repository at this point in the history
fix: query fix - nav
  • Loading branch information
Pierniki authored Sep 21, 2023
2 parents 55d5284 + 93a8dde commit 9b1afed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
20 changes: 5 additions & 15 deletions src/components/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,16 @@ type NavigationProps = {
lang: Locale
}

type Page = {
__typename?: "Page"
slug: string
title: string
}

type NavItem = {
pages: Page[]
}

export async function Navigation({ lang }: NavigationProps) {
const { getNav } = HygraphApi({ lang })
const { nav } = await getNav({})
const navElements = nav.reduce((acc: Page[], curr: NavItem) => acc.concat(curr.pages), [])
const { navigations } = await getNav({})
const navElements = navigations[0]?.pages

return (
<ul className="flex items-center justify-center gap-5 px-4">
{navElements.map((navElement) => (
<li key={navElement.slug}>
<Link href={`/${lang}/${navElement.slug}`}>{navElement.title}</Link>
{navElements?.map((navElement) => (
<li key={navElement?.slug}>
<Link href={`/${lang}/${navElement?.slug}`}>{navElement?.title}</Link>
</li>
))}
</ul>
Expand Down
4 changes: 2 additions & 2 deletions src/hygraphApi/hygraphApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const getHomepage = graphql(`

const getNav = graphql(`
query getNav($locales: [Locale!]!) {
nav {
pages(locales: $locales) {
navigations(locales: $locales, first: 1) {
pages {
slug
title
}
Expand Down

0 comments on commit 9b1afed

Please sign in to comment.