From 4b7b26fbb2b94194d520c59f2d0c5db0ccc7d18d Mon Sep 17 00:00:00 2001 From: Brian Nelson Date: Fri, 10 Oct 2025 14:37:11 -0400 Subject: [PATCH] added project collection --- src/collections/Page.ts | 1 - src/collections/Projects.ts | 52 +++++++++++++ src/payload-types.ts | 150 ++++++++++++++++++++++++------------ src/payload.config.ts | 3 +- 4 files changed, 156 insertions(+), 50 deletions(-) create mode 100644 src/collections/Projects.ts diff --git a/src/collections/Page.ts b/src/collections/Page.ts index d404dd0..c6bc8ad 100644 --- a/src/collections/Page.ts +++ b/src/collections/Page.ts @@ -1,4 +1,3 @@ -import { lexicalEditor } from '@payloadcms/richtext-lexical' import type { CollectionConfig } from 'payload' import { slugField } from 'payload' diff --git a/src/collections/Projects.ts b/src/collections/Projects.ts new file mode 100644 index 0000000..d89258e --- /dev/null +++ b/src/collections/Projects.ts @@ -0,0 +1,52 @@ +import type { CollectionConfig } from 'payload' +import { slugField } from 'payload' + +export const Projects: CollectionConfig = { + slug: 'projects', + defaultPopulate: { + title: true, + slug: true, + }, + admin: { + defaultColumns: ['title', 'slug', 'updatedAt',], + }, + fields: [ + { + name: 'title', + type: 'text', + required: true, + }, + { + type: 'tabs', + tabs: [ + { + label: 'Content', + fields: [ + { + name: 'description', + type: 'textarea', + }, + { + name: 'richText', + type: 'richText' + }, + ] + }, + { + label: 'Project Links', + fields: [ + { + name: 'link', + type: 'text' + }, + { + name: 'github', + type: 'text' + } + ] + } + ] + }, + slugField(), + ], +} \ No newline at end of file diff --git a/src/payload-types.ts b/src/payload-types.ts index 5e16c46..0469f18 100644 --- a/src/payload-types.ts +++ b/src/payload-types.ts @@ -67,18 +67,20 @@ export interface Config { }; blocks: {}; collections: { + pages: Page; + projects: Project; users: User; media: Media; - pages: Page; 'payload-locked-documents': PayloadLockedDocument; 'payload-preferences': PayloadPreference; 'payload-migrations': PayloadMigration; }; collectionsJoins: {}; collectionsSelect: { + pages: PagesSelect | PagesSelect; + projects: ProjectsSelect | ProjectsSelect; users: UsersSelect | UsersSelect; media: MediaSelect | MediaSelect; - pages: PagesSelect | PagesSelect; 'payload-locked-documents': PayloadLockedDocumentsSelect | PayloadLockedDocumentsSelect; 'payload-preferences': PayloadPreferencesSelect | PayloadPreferencesSelect; 'payload-migrations': PayloadMigrationsSelect | PayloadMigrationsSelect; @@ -115,6 +117,69 @@ export interface UserAuthOperations { password: string; }; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "pages". + */ +export interface Page { + id: number; + title: string; + richText?: { + root: { + type: string; + children: { + type: any; + version: number; + [k: string]: unknown; + }[]; + direction: ('ltr' | 'rtl') | null; + format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + indent: number; + version: number; + }; + [k: string]: unknown; + } | null; + /** + * 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". + */ +export interface Project { + id: number; + title: string; + description?: string | null; + richText?: { + root: { + type: string; + children: { + type: any; + version: number; + [k: string]: unknown; + }[]; + direction: ('ltr' | 'rtl') | null; + format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + indent: number; + version: number; + }; + [k: string]: unknown; + } | null; + link?: string | null; + github?: string | null; + /** + * 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". @@ -160,36 +225,6 @@ export interface Media { focalX?: number | null; focalY?: number | null; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "pages". - */ -export interface Page { - id: number; - title: string; - richText?: { - root: { - type: string; - children: { - type: any; - version: number; - [k: string]: unknown; - }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; - indent: number; - version: number; - }; - [k: string]: unknown; - } | null; - /** - * 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` "payload-locked-documents". @@ -197,6 +232,14 @@ export interface Page { export interface PayloadLockedDocument { id: number; document?: + | ({ + relationTo: 'pages'; + value: number | Page; + } | null) + | ({ + relationTo: 'projects'; + value: number | Project; + } | null) | ({ relationTo: 'users'; value: number | User; @@ -204,10 +247,6 @@ export interface PayloadLockedDocument { | ({ relationTo: 'media'; value: number | Media; - } | null) - | ({ - relationTo: 'pages'; - value: number | Page; } | null); globalSlug?: string | null; user: { @@ -251,6 +290,33 @@ export interface PayloadMigration { updatedAt: string; createdAt: string; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "pages_select". + */ +export interface PagesSelect { + title?: T; + richText?: T; + generateSlug?: T; + slug?: T; + updatedAt?: T; + createdAt?: T; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "projects_select". + */ +export interface ProjectsSelect { + title?: T; + description?: T; + richText?: T; + link?: T; + github?: T; + generateSlug?: T; + slug?: T; + updatedAt?: T; + createdAt?: T; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "users_select". @@ -293,18 +359,6 @@ export interface MediaSelect { focalX?: T; focalY?: T; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "pages_select". - */ -export interface PagesSelect { - title?: T; - richText?: T; - generateSlug?: T; - slug?: T; - updatedAt?: T; - createdAt?: T; -} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "payload-locked-documents_select". diff --git a/src/payload.config.ts b/src/payload.config.ts index 7769a01..6fbb4c2 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -10,6 +10,7 @@ import sharp from 'sharp' import { Users } from './collections/Users' import { Media } from './collections/Media' import { Page } from './collections/Page' +import { Projects } from './collections/Projects' const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) @@ -21,7 +22,7 @@ export default buildConfig({ baseDir: path.resolve(dirname), }, }, - collections: [Users, Media, Page], + collections: [Page, Projects, Users, Media], editor: lexicalEditor({ features: ({ defaultFeatures, rootFeatures }) => [ ...defaultFeatures,