From 23055629c96fb7bbbb0bd17fd67f2a3dc63cfc24 Mon Sep 17 00:00:00 2001 From: Brian Nelson Date: Wed, 22 Oct 2025 08:54:15 -0400 Subject: [PATCH] addded categories to pages and alert text to settings --- next.config.mjs | 11 +++++ src/app/(frontend)/globals.css | 2 +- src/app/(frontend)/page.tsx | 5 +- src/app/(frontend)/projects/[slug]/page.tsx | 53 ++++++++++++++++----- src/collections/Page.ts | 11 ++++- src/collections/Settings/index.ts | 10 +++- src/payload-types.ts | 37 ++++++++------ utilities/queries.ts | 3 +- 8 files changed, 96 insertions(+), 36 deletions(-) diff --git a/next.config.mjs b/next.config.mjs index 8e22d20..6d2cd27 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -12,6 +12,17 @@ const nextConfig = { return webpackConfig }, + + images: { + remotePatterns: [ + { + protocol: 'http', + hostname: 'localhost', + port: '3000', + pathname: '/api/media/**', + }, + ], + }, } export default withPayload(nextConfig, { devBundleServerPackages: false }) diff --git a/src/app/(frontend)/globals.css b/src/app/(frontend)/globals.css index 385ed45..680e422 100644 --- a/src/app/(frontend)/globals.css +++ b/src/app/(frontend)/globals.css @@ -100,7 +100,7 @@ svg { padding: 45px; max-width: 1024px; margin: 0 auto; - overflow: hidden; + /* overflow: hidden; */ @media (max-width: 400px) { padding: 24px; diff --git a/src/app/(frontend)/page.tsx b/src/app/(frontend)/page.tsx index e709f85..dccea9e 100644 --- a/src/app/(frontend)/page.tsx +++ b/src/app/(frontend)/page.tsx @@ -26,7 +26,6 @@ export default async function HomePage() {
{page && (
-

{page.title}

{page.richText && ( @@ -68,7 +67,7 @@ export default async function HomePage() {

Update this page by editing

app/(frontend)/page.tsx
-
+
{projects.docs.length > 0 && (
{projects.docs @@ -78,7 +77,7 @@ export default async function HomePage() { key={item.id} className="border-2 border-white rounded col-span-full" // full width styling > - +

{item.title}

{item.description}

diff --git a/src/app/(frontend)/projects/[slug]/page.tsx b/src/app/(frontend)/projects/[slug]/page.tsx index de883dc..aba32ef 100644 --- a/src/app/(frontend)/projects/[slug]/page.tsx +++ b/src/app/(frontend)/projects/[slug]/page.tsx @@ -1,29 +1,56 @@ import { SINGLE_PROJECT_QUERY } from '@/utilities/queries' import React from 'react' -import { PortableText } from "@portabletext/react" -import { RichTextComponent } from '@/src/components/RichTextComponents' import Image from 'next/image' import { RichText } from '@payloadcms/richtext-lexical/react' -export default async function SingleProjectPage({ params }: { params: { slug: string } }) { - const fetchData = await SINGLE_PROJECT_QUERY(params.slug) - const pageData = fetchData.docs[0]; - // console.log(pageData) +type Media = { + id: string | number; + url: string; + alt?: string; +}; + +type Project = { + id: string | number; + title: string; + featuredImage?: number | Media; + description?: string; + richText?: any; + link?: any; + github?: any; + slug: string; + categories?: any[] + createdAt: string; +}; + +export default async function SingleProjectPage({ + params +}: { + params: Promise<{ slug: string }> +}) { + // await the slug from the page + const { slug } = await params; + + // use the awaited slug for the query + const { docs } = await SINGLE_PROJECT_QUERY(slug) + const project = docs[0] as Project + + const img = project.featuredImage as Media | undefined; + const src = img?.url ?? ''; return (
-

{pageData.title}

- {pageData.featuredImage && ( +

{project.title}

+ {project.featuredImage && ( {pageData.featuredImage.alt} )} -
- {pageData.richText && ( - +
+ {project.richText && ( + )}
diff --git a/src/collections/Page.ts b/src/collections/Page.ts index 2ae9e7d..acff5c5 100644 --- a/src/collections/Page.ts +++ b/src/collections/Page.ts @@ -58,8 +58,15 @@ export const Page: CollectionConfig = { }, ] }, - slugField(), - + { + name: 'categories', + type: 'relationship', + hasMany: true, + relationTo: 'categories', + admin: { + position: 'sidebar' + } + }, ], } diff --git a/src/collections/Settings/index.ts b/src/collections/Settings/index.ts index 69ab35f..027d0b7 100644 --- a/src/collections/Settings/index.ts +++ b/src/collections/Settings/index.ts @@ -7,12 +7,20 @@ export const Settings: GlobalConfig = { type: 'tabs', tabs: [ { - label: 'Contact', + label: 'All Settings', fields: [ { name: 'email', label: 'Contact Email', type: 'email' + }, + { + name: 'alertBanner', + label: 'Alert Banner', + type: 'text', + admin: { + description: 'If there is text here an alert will show' + } } ] }, diff --git a/src/payload-types.ts b/src/payload-types.ts index 7e56ecf..bcf0102 100644 --- a/src/payload-types.ts +++ b/src/payload-types.ts @@ -160,6 +160,7 @@ export interface Page { */ generateSlug?: boolean | null; slug: string; + categories?: (number | Category)[] | null; updatedAt: string; createdAt: string; } @@ -182,6 +183,21 @@ export interface Media { focalX?: number | null; focalY?: number | null; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "categories". + */ +export interface Category { + id: number; + title: string; + /** + * When enabled, the slug will auto-generate from the title field on save and autosave. + */ + generateSlug?: boolean | null; + slug: string; + updatedAt: string; + createdAt: string; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "projects". @@ -219,21 +235,6 @@ export interface Project { updatedAt: string; createdAt: string; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "categories". - */ -export interface Category { - id: number; - title: string; - /** - * When enabled, the slug will auto-generate from the title field on save and autosave. - */ - generateSlug?: boolean | null; - slug: string; - updatedAt: string; - createdAt: string; -} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "users". @@ -345,6 +346,7 @@ export interface PagesSelect { }; generateSlug?: T; slug?: T; + categories?: T; updatedAt?: T; createdAt?: T; } @@ -459,6 +461,10 @@ export interface PayloadMigrationsSelect { export interface Setting { id: number; email?: string | null; + /** + * If there is text here an alert will show + */ + alertBanner?: string | null; updatedAt?: string | null; createdAt?: string | null; } @@ -492,6 +498,7 @@ export interface Header { */ export interface SettingsSelect { email?: T; + alertBanner?: T; updatedAt?: T; createdAt?: T; globalType?: T; diff --git a/utilities/queries.ts b/utilities/queries.ts index d478aa6..6525416 100644 --- a/utilities/queries.ts +++ b/utilities/queries.ts @@ -36,6 +36,7 @@ export const SINGLE_PROJECT_QUERY = async (slug: string) => { equals: slug } }, - limit: 1 + limit: 1, + depth: 1, } )} \ No newline at end of file