From d3a045399f8474823f15c9c210134d1bded9a289 Mon Sep 17 00:00:00 2001 From: Alexander Liu Date: Sat, 20 Jan 2024 19:13:07 -0800 Subject: [PATCH 1/8] feat: resources page --- apps/sanity/sanity.config.ts | 69 +++++++++++++++---- apps/sanity/schemas/index.ts | 10 ++- apps/sanity/schemas/resourceCategoryOrder.ts | 21 ++++++ .../src/app/(main)/resources/getResources.ts | 41 ++++++++--- apps/site/src/app/(main)/resources/page.tsx | 59 ++++++++++++++++ 5 files changed, 176 insertions(+), 24 deletions(-) create mode 100644 apps/sanity/schemas/resourceCategoryOrder.ts create mode 100644 apps/site/src/app/(main)/resources/page.tsx diff --git a/apps/sanity/sanity.config.ts b/apps/sanity/sanity.config.ts index 059dba80..6ad9ae4e 100644 --- a/apps/sanity/sanity.config.ts +++ b/apps/sanity/sanity.config.ts @@ -1,19 +1,60 @@ -import {defineConfig} from 'sanity' -import {deskTool} from 'sanity/desk' -import {visionTool} from '@sanity/vision' -import {colorInput} from '@sanity/color-input' -import {schemaTypes} from './schemas' +import { defineConfig } from "sanity"; +import { deskTool } from "sanity/desk"; +import { visionTool } from "@sanity/vision"; +import { colorInput } from "@sanity/color-input"; +import { schemaTypes } from "./schemas"; +import { ListOrdered, Folders, Globe } from "lucide-react"; export default defineConfig({ - name: 'default', - title: 'irvinehacks-site-2024', + name: "default", + title: "irvinehacks-site-2024", - projectId: 'fosuyru0', - dataset: 'production', + projectId: "fosuyru0", + dataset: "production", - plugins: [deskTool(), visionTool(), colorInput()], + plugins: [ + deskTool({ + structure: (S) => + S.list() + .title("Content") + .items([ + ...S.documentTypeListItems().filter( + (listItem) => + ![ + "resourceCategoryOrder", + "resourceCategory", + "resource", + ].includes(listItem.getId()!) + ), + S.divider(), + S.listItem() + .title("Resource Categories Order") + .icon(ListOrdered) + .child( + S.document() + .schemaType("resourceCategoryOrder") + .documentId("resourceCategoryOrder") + .title("Resource Categories Order") + ), + S.listItem() + .title("Resource Categories") + .icon(Folders) + .child( + S.documentTypeList("resourceCategory").title( + "Resource Categories" + ) + ), + S.listItem() + .title("Resources") + .icon(Globe) + .child(S.documentTypeList("resource").title("Resources")), + ]), + }), + visionTool(), + colorInput(), + ], - schema: { - types: schemaTypes, - }, -}) + schema: { + types: schemaTypes, + }, +}); diff --git a/apps/sanity/schemas/index.ts b/apps/sanity/schemas/index.ts index 30e40ab6..f36c2797 100644 --- a/apps/sanity/schemas/index.ts +++ b/apps/sanity/schemas/index.ts @@ -2,6 +2,14 @@ import faqs from "./faqs"; import event from "./event"; import resource from "./resource"; import resourceCategory from "./resourceCategory"; +import resourceCategoryOrder from "./resourceCategoryOrder"; import sponsors from "./sponsors"; -export const schemaTypes = [faqs, event, resource, resourceCategory, sponsors]; +export const schemaTypes = [ + faqs, + event, + resource, + resourceCategory, + resourceCategoryOrder, + sponsors, +]; diff --git a/apps/sanity/schemas/resourceCategoryOrder.ts b/apps/sanity/schemas/resourceCategoryOrder.ts new file mode 100644 index 00000000..38614b96 --- /dev/null +++ b/apps/sanity/schemas/resourceCategoryOrder.ts @@ -0,0 +1,21 @@ +import { defineArrayMember, defineField, defineType } from "sanity"; + +export default defineType({ + name: "resourceCategoryOrder", + title: "Resource Categories Order", + type: "document", + fields: [ + defineField({ + name: "order", + title: "Order", + type: "array", + of: [ + defineArrayMember({ + type: "reference", + to: { type: "resourceCategory" }, + }), + ], + validation: (Rule) => Rule.required(), + }), + ], +}); diff --git a/apps/site/src/app/(main)/resources/getResources.ts b/apps/site/src/app/(main)/resources/getResources.ts index ff8a61b5..92fd36c3 100644 --- a/apps/site/src/app/(main)/resources/getResources.ts +++ b/apps/site/src/app/(main)/resources/getResources.ts @@ -2,16 +2,39 @@ import { z } from "zod"; import { cache } from "react"; import { client } from "@/lib/sanity/client"; import { SanityDocument, SanityReference } from "@/lib/sanity/types"; +import { groq } from "next-sanity"; -const Resources = z.array( - SanityDocument.extend({ - _type: z.literal("resource"), - link: z.string(), - title: z.string(), - resourceType: SanityReference, - }), -); +const Resources = z.object({ + order: z.array( + z.object({ + _id: z.string(), + iconUrl: z.string(), + title: z.string(), + description: z.string(), + resources: z.array( + SanityDocument.extend({ + _type: z.literal("resource"), + link: z.string(), + title: z.string(), + resourceType: SanityReference, + }), + ), + }), + ), +}); export const getResources = cache(async () => { - return Resources.parse(await client.fetch("*[_type == 'resource']")); + return Resources.parse( + await client.fetch(groq` + *[_type == 'resourceCategoryOrder' && _id == "resourceCategoryOrder"][0] { + order[]->{ + _id, + 'iconUrl': icon.asset->url, + title, + description, + 'resources': *[_type == 'resource' && resourceType._ref == ^._id] | order(title asc) + } + } + `), + ); }); diff --git a/apps/site/src/app/(main)/resources/page.tsx b/apps/site/src/app/(main)/resources/page.tsx new file mode 100644 index 00000000..a89bc83a --- /dev/null +++ b/apps/site/src/app/(main)/resources/page.tsx @@ -0,0 +1,59 @@ +import Button from "@/lib/components/Button/Button"; +import { Metadata } from "next"; +import { redirect } from "next/navigation"; +import { getResources } from "./getResources"; + +export const revalidate = 60; + +export const metadata: Metadata = { + title: "Resources | IrvineHacks 2024", +}; + +export default async function Schedule() { + if (process.env.MAINTENANCE_MODE_SCHEDULE) { + redirect("/"); + } + + const resources = await getResources(); + + return ( + <> +
+
+

+ Resources +

+
+
+ {resources.order.map( + ({ _id, iconUrl, title, description, resources }) => ( +
+
+
+ {/* eslint-disable-next-line @next/next/no-img-element */} + +

{title}

+
+

{description}

+
+
+ {resources.map(({ _id, title, link }) => ( +
+
+ ), + )} +
+
+ + ); +} From 217a0eeee92150652ff9d0b6914f388abf7c7549 Mon Sep 17 00:00:00 2001 From: Alexander Liu Date: Sat, 20 Jan 2024 19:36:04 -0800 Subject: [PATCH 2/8] fix: resources page component and maintenace mode name --- apps/site/src/app/(main)/resources/page.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/site/src/app/(main)/resources/page.tsx b/apps/site/src/app/(main)/resources/page.tsx index a89bc83a..a21ee7ff 100644 --- a/apps/site/src/app/(main)/resources/page.tsx +++ b/apps/site/src/app/(main)/resources/page.tsx @@ -9,8 +9,8 @@ export const metadata: Metadata = { title: "Resources | IrvineHacks 2024", }; -export default async function Schedule() { - if (process.env.MAINTENANCE_MODE_SCHEDULE) { +export default async function Resources() { + if (process.env.MAINTENANCE_MODE_RESOURCES) { redirect("/"); } From 54e271503a9592faa096a0509e00565f4251697f Mon Sep 17 00:00:00 2001 From: Alexander Liu Date: Sat, 20 Jan 2024 19:37:41 -0800 Subject: [PATCH 3/8] fix: center resource button text --- apps/site/src/app/(main)/resources/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/site/src/app/(main)/resources/page.tsx b/apps/site/src/app/(main)/resources/page.tsx index a21ee7ff..5226e5fd 100644 --- a/apps/site/src/app/(main)/resources/page.tsx +++ b/apps/site/src/app/(main)/resources/page.tsx @@ -45,7 +45,7 @@ export default async function Resources() { key={_id} text={title} href={link} - className="w-[100%!important]" + className="w-[100%!important] text-center" /> ))} From e5ca030cf30c62ff77368a29f22e376edd2fabaa Mon Sep 17 00:00:00 2001 From: Alexander Liu Date: Sat, 20 Jan 2024 19:44:32 -0800 Subject: [PATCH 4/8] feat: setup for alternating button colors --- apps/site/src/app/(main)/resources/page.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/site/src/app/(main)/resources/page.tsx b/apps/site/src/app/(main)/resources/page.tsx index 5226e5fd..9335bbff 100644 --- a/apps/site/src/app/(main)/resources/page.tsx +++ b/apps/site/src/app/(main)/resources/page.tsx @@ -40,12 +40,13 @@ export default async function Resources() {

{description}

- {resources.map(({ _id, title, link }) => ( + {resources.map(({ _id, title, link }, i) => (
From 33040e0e6f6467e35a376b2085ecd0beb317a206 Mon Sep 17 00:00:00 2001 From: Alexander Liu Date: Sat, 20 Jan 2024 19:46:59 -0800 Subject: [PATCH 5/8] fix: alternate resource button between categories, not within --- apps/site/src/app/(main)/resources/page.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/site/src/app/(main)/resources/page.tsx b/apps/site/src/app/(main)/resources/page.tsx index 9335bbff..6b1099e6 100644 --- a/apps/site/src/app/(main)/resources/page.tsx +++ b/apps/site/src/app/(main)/resources/page.tsx @@ -26,7 +26,7 @@ export default async function Resources() {
{resources.order.map( - ({ _id, iconUrl, title, description, resources }) => ( + ({ _id, iconUrl, title, description, resources }, i) => (
{description}

- {resources.map(({ _id, title, link }, i) => ( + {resources.map(({ _id, title, link }) => (