Skip to content

Commit

Permalink
Merge pull request #508 from w3bdesign/refactor-groq-queries
Browse files Browse the repository at this point in the history
Refactor Groq queries
  • Loading branch information
w3bdesign authored Dec 6, 2024
2 parents 67b7f2f + 29ac523 commit a3b86a1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 36 deletions.
15 changes: 1 addition & 14 deletions src/app/RootLayout.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
11 changes: 1 addition & 10 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -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: () => <div>Loading hero...</div>,
Expand All @@ -15,15 +15,6 @@ const DynamicIndexContent = dynamic(
);

export default async function HomePage() {
const pageContentQuery = groq`
*[_type == 'page' && title match 'Hjem'][0]{
"id": _id,
title,
hero,
content
}
`;

const pageContent = await client.fetch(pageContentQuery);

return (
Expand Down
13 changes: 1 addition & 12 deletions src/app/prosjekter/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PageHeader from "@/components/UI/PageHeader.component";
import ProsjektCard from "@/components/Prosjekter/ProsjektCard.component";

import { client } from "@/lib/sanity/client";
import { projectsQuery } from "@/lib/sanity/queries";

import type { Project } from "@/types/sanity.types";
import type { Metadata } from "next/types";
Expand All @@ -12,18 +13,6 @@ export const metadata: Metadata = {
description: "Daniel Fjeldstad | Frontend Web Utvikler | Portefølje",
};

const projectsQuery = `*[_type == "project"] | order(featured desc, featureOrder asc, _createdAt desc) {
id,
name,
description,
subdescription,
projectimage,
urlwww,
urlgithub,
featured,
featureOrder
}`;

export default async function Prosjekter() {
const posts: Project[] = await client.fetch(projectsQuery);

Expand Down
22 changes: 22 additions & 0 deletions src/lib/sanity/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,25 @@ export const cvQuery = groq`
}
}
`;

export const pageContentQuery = groq`
*[_type == 'page' && title match 'Hjem'][0]{
"id": _id,
title,
hero,
content
}
`;

export const navigationQuery = groq`
*[_type == "navigation"][0] {
title,
links[] {
title,
name,
hash,
href,
externalLink
}
}
`;

0 comments on commit a3b86a1

Please sign in to comment.