From 29ac52339a2cd64011e9da52cbe97d72c6e36c50 Mon Sep 17 00:00:00 2001 From: Daniel Fjeldstad <45217974+w3bdesign@users.noreply.github.com> Date: Fri, 6 Dec 2024 04:24:30 +0100 Subject: [PATCH] Refactor Groq queries Fixes #507 Refactor Groq queries to a separate file and update imports. * Add `pageContentQuery` and `navigationQuery` to `src/lib/sanity/queries.ts`. * Remove `pageContentQuery` from `src/app/page.tsx` and import it from `src/lib/sanity/queries.ts`. * Remove `projectsQuery` from `src/app/prosjekter/page.tsx` and import it from `src/lib/sanity/queries.ts`. * Remove `navigationQuery` from `src/app/RootLayout.tsx` and import it from `src/lib/sanity/queries.ts`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/w3bdesign/dfweb-v4/issues/507?shareId=XXXX-XXXX-XXXX-XXXX). --- src/app/RootLayout.tsx | 15 +-------------- src/app/page.tsx | 11 +---------- src/app/prosjekter/page.tsx | 13 +------------ src/lib/sanity/queries.ts | 22 ++++++++++++++++++++++ 4 files changed, 25 insertions(+), 36 deletions(-) diff --git a/src/app/RootLayout.tsx b/src/app/RootLayout.tsx index 6186edf0..0ba817f9 100644 --- a/src/app/RootLayout.tsx +++ b/src/app/RootLayout.tsx @@ -1,20 +1,7 @@ -import { groq } from "next-sanity"; import { client } from "@/lib/sanity/client"; import Header from "@/components/Layout/Header.component"; import ErrorBoundary from "@/components/ErrorBoundary/ErrorBoundary"; - -const navigationQuery = groq` - *[_type == "navigation"][0] { - title, - links[] { - title, - name, - hash, - href, - externalLink - } - } -`; +import { navigationQuery } from "@/lib/sanity/queries"; export default async function RootLayout({ children, diff --git a/src/app/page.tsx b/src/app/page.tsx index 781e8e03..a7c8b5de 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,7 +1,7 @@ -import { groq } from "next-sanity"; import dynamic from "next/dynamic"; import RootLayout from "@/app/RootLayout"; import { client } from "@/lib/sanity/client"; +import { pageContentQuery } from "@/lib/sanity/queries"; const DynamicHero = dynamic(() => import("@/components/Index/Hero.component"), { loading: () =>