From 55859cf02a283b8741ad16254ee61cf49856089b Mon Sep 17 00:00:00 2001 From: briannelson95 <71141646+briannelson95@users.noreply.github.com> Date: Sat, 11 Oct 2025 10:05:23 -0400 Subject: [PATCH] added categories to projects --- src/collections/Projects.ts | 7 ++++++- src/payload-types.ts | 34 ++++++++++++++++++++++++++++++++++ src/payload.config.ts | 3 ++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/collections/Projects.ts b/src/collections/Projects.ts index 2528a8a..81b2f96 100644 --- a/src/collections/Projects.ts +++ b/src/collections/Projects.ts @@ -49,7 +49,12 @@ export const Projects: CollectionConfig = { { label: 'Settings', fields: [ - + { + name: 'categories', + type: 'relationship', + hasMany: true, + relationTo: 'categories' + } ] } ] diff --git a/src/payload-types.ts b/src/payload-types.ts index d4e4472..7b1c3d5 100644 --- a/src/payload-types.ts +++ b/src/payload-types.ts @@ -69,6 +69,7 @@ export interface Config { collections: { pages: Page; projects: Project; + categories: Category; users: User; media: Media; 'payload-locked-documents': PayloadLockedDocument; @@ -79,6 +80,7 @@ export interface Config { collectionsSelect: { pages: PagesSelect | PagesSelect; projects: ProjectsSelect | ProjectsSelect; + categories: CategoriesSelect | CategoriesSelect; users: UsersSelect | UsersSelect; media: MediaSelect | MediaSelect; 'payload-locked-documents': PayloadLockedDocumentsSelect | PayloadLockedDocumentsSelect; @@ -172,6 +174,7 @@ export interface Project { } | null; link?: string | null; github?: string | null; + categories?: (number | Category)[] | null; /** * When enabled, the slug will auto-generate from the title field on save and autosave. */ @@ -182,6 +185,21 @@ 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". @@ -242,6 +260,10 @@ export interface PayloadLockedDocument { relationTo: 'projects'; value: number | Project; } | null) + | ({ + relationTo: 'categories'; + value: number | Category; + } | null) | ({ relationTo: 'users'; value: number | User; @@ -314,6 +336,7 @@ export interface ProjectsSelect { richText?: T; link?: T; github?: T; + categories?: T; generateSlug?: T; slug?: T; featuredProject?: T; @@ -321,6 +344,17 @@ export interface ProjectsSelect { updatedAt?: T; createdAt?: T; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "categories_select". + */ +export interface CategoriesSelect { + title?: T; + generateSlug?: T; + slug?: T; + updatedAt?: T; + createdAt?: T; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "users_select". diff --git a/src/payload.config.ts b/src/payload.config.ts index 6fbb4c2..e483fb0 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -11,6 +11,7 @@ import { Users } from './collections/Users' import { Media } from './collections/Media' import { Page } from './collections/Page' import { Projects } from './collections/Projects' +import { Categories } from './collections/Categories' const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) @@ -22,7 +23,7 @@ export default buildConfig({ baseDir: path.resolve(dirname), }, }, - collections: [Page, Projects, Users, Media], + collections: [Page, Projects, Categories, Users, Media], editor: lexicalEditor({ features: ({ defaultFeatures, rootFeatures }) => [ ...defaultFeatures,