From 4c24f2d4503d25203561a85de6b1a97aa4a1c3ef Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Sun, 8 Dec 2024 04:44:01 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20update=20p?= =?UTF-8?q?roject=20sorting=20based=20on=20featureOrder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement custom sorting logic for projects using a new featureOrder field instead of the previous featured-based filtering system. This provides more fine-grained control over project display order. --- src/app/prosjekter/page.tsx | 19 +++++++------------ src/lib/sanity/queries.ts | 4 +++- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/app/prosjekter/page.tsx b/src/app/prosjekter/page.tsx index c9bb5b93..0e946017 100644 --- a/src/app/prosjekter/page.tsx +++ b/src/app/prosjekter/page.tsx @@ -16,8 +16,12 @@ export const metadata: Metadata = { export default async function Prosjekter() { const posts: Project[] = await client.fetch(projectsQuery); - const featuredProjects = posts.filter((project) => project.featured); - const nonFeaturedProjects = posts.filter((project) => !project.featured); + // Sort by featureOrder, putting null/undefined values last + const sortedProjects = [...posts].sort((a, b) => { + if (a.featureOrder === null || a.featureOrder === undefined) return 1; + if (b.featureOrder === null || b.featureOrder === undefined) return -1; + return a.featureOrder - b.featureOrder; + }); return ( @@ -28,17 +32,8 @@ export default async function Prosjekter() { > Prosjekter
- {featuredProjects.length > 0 && ( -
-
- {featuredProjects.map((project) => ( - - ))} -
-
- )}
- {nonFeaturedProjects.map((project) => ( + {sortedProjects.map((project) => ( ))}
diff --git a/src/lib/sanity/queries.ts b/src/lib/sanity/queries.ts index 4ef648a4..9e5024e8 100644 --- a/src/lib/sanity/queries.ts +++ b/src/lib/sanity/queries.ts @@ -18,7 +18,9 @@ export const projectsQuery = groq` ..., _key, }, - "projectimage": projectimage.asset->url + "projectimage": projectimage.asset->url, + featured, + featureOrder } `; From 9d022fdff3dd4544a3dd78bf3d4f3463f064f366 Mon Sep 17 00:00:00 2001 From: w3bdesign <45217974+w3bdesign@users.noreply.github.com> Date: Sun, 8 Dec 2024 04:44:57 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20move=20pro?= =?UTF-8?q?ject=20sorting=20to=20sanity=20query?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sorting of projects by featureOrder has been moved from client-side JavaScript to the Sanity GROQ query, improving code maintainability and performance --- src/app/prosjekter/page.tsx | 9 +-------- src/lib/sanity/queries.ts | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/app/prosjekter/page.tsx b/src/app/prosjekter/page.tsx index 0e946017..791c4871 100644 --- a/src/app/prosjekter/page.tsx +++ b/src/app/prosjekter/page.tsx @@ -16,13 +16,6 @@ export const metadata: Metadata = { export default async function Prosjekter() { const posts: Project[] = await client.fetch(projectsQuery); - // Sort by featureOrder, putting null/undefined values last - const sortedProjects = [...posts].sort((a, b) => { - if (a.featureOrder === null || a.featureOrder === undefined) return 1; - if (b.featureOrder === null || b.featureOrder === undefined) return -1; - return a.featureOrder - b.featureOrder; - }); - return (
Prosjekter
- {sortedProjects.map((project) => ( + {posts.map((project) => ( ))}
diff --git a/src/lib/sanity/queries.ts b/src/lib/sanity/queries.ts index 9e5024e8..c3cf0969 100644 --- a/src/lib/sanity/queries.ts +++ b/src/lib/sanity/queries.ts @@ -1,7 +1,7 @@ import { groq } from "next-sanity"; export const projectsQuery = groq` - *[_type == "project"]{ + *[_type == "project"] | order(featureOrder asc) { id, name, description,