From 4dfe80213e4b84fca48713fe5681d2fd91c722d1 Mon Sep 17 00:00:00 2001
From: tobias
Date: Mon, 24 Jun 2024 09:55:03 +0200
Subject: [PATCH] Use collection config for slugs and correct locale for links
---
src/app/(app)/page.tsx | 4 ++--
src/app/(app)/pages/[[...path]]/page.tsx | 2 +-
src/app/(app)/posts/[[...path]]/page.tsx | 2 +-
src/app/(payload)/collections/Authors.ts | 3 ++-
src/app/(payload)/collections/Media.ts | 3 ++-
src/app/(payload)/collections/Posts.ts | 3 ++-
src/app/(payload)/collections/Users.ts | 3 ++-
src/app/(payload)/collections/config.ts | 12 +++---------
src/components/Blocks/{Posts.tsx => PostList.tsx} | 5 +++--
src/components/PostEntry.tsx | 6 +++++-
src/components/PostPage.tsx | 2 +-
11 files changed, 24 insertions(+), 21 deletions(-)
rename src/components/Blocks/{Posts.tsx => PostList.tsx} (84%)
diff --git a/src/app/(app)/page.tsx b/src/app/(app)/page.tsx
index f7c9c00..7ed35c6 100644
--- a/src/app/(app)/page.tsx
+++ b/src/app/(app)/page.tsx
@@ -5,7 +5,7 @@ import Footer from '@/components/Footer'
import { getPayloadHMR } from '@payloadcms/next/utilities'
import configPromise from '@payload-config'
-import Posts from '@/components/Blocks/Posts'
+import PostList from '@/components/Blocks/PostList'
interface Props {}
@@ -19,7 +19,7 @@ const Page = (props: Props) => {
{`When you're ready to deploy the website on your own server, Nextload comes with a production environment that requires the use of Traefik as a reverse proxy. This setup provides a secure and scalable production environment for your website.`}
>
)
diff --git a/src/app/(app)/pages/[[...path]]/page.tsx b/src/app/(app)/pages/[[...path]]/page.tsx
index dfb56e9..f251e5f 100644
--- a/src/app/(app)/pages/[[...path]]/page.tsx
+++ b/src/app/(app)/pages/[[...path]]/page.tsx
@@ -29,7 +29,7 @@ const Page = async ({ params }: PageArgs) => {
depth: 3,
})
if (!page) notFound()
- return
+ return
}
export default Page
diff --git a/src/app/(app)/posts/[[...path]]/page.tsx b/src/app/(app)/posts/[[...path]]/page.tsx
index d8a4cf3..e22cf9b 100644
--- a/src/app/(app)/posts/[[...path]]/page.tsx
+++ b/src/app/(app)/posts/[[...path]]/page.tsx
@@ -30,7 +30,7 @@ const Page = async ({ params }: PageArgs) => {
depth: 3,
})
if (!post) notFound()
- return
+ return
}
export default Page
diff --git a/src/app/(payload)/collections/Authors.ts b/src/app/(payload)/collections/Authors.ts
index a1f08c1..bb467c8 100644
--- a/src/app/(payload)/collections/Authors.ts
+++ b/src/app/(payload)/collections/Authors.ts
@@ -1,9 +1,10 @@
import { CollectionConfig } from 'payload/types'
import { isEditor } from '@payload/access/isEditor'
import { isUser } from '@payload/access/isUser'
+import { COLLECTION_SLUG_AUTHOR } from './config'
const Authors: CollectionConfig = {
- slug: 'authors',
+ slug: COLLECTION_SLUG_AUTHOR,
admin: {
defaultColumns: ['name'],
useAsTitle: 'name',
diff --git a/src/app/(payload)/collections/Media.ts b/src/app/(payload)/collections/Media.ts
index f775a7a..b20abe5 100644
--- a/src/app/(payload)/collections/Media.ts
+++ b/src/app/(payload)/collections/Media.ts
@@ -1,8 +1,9 @@
import { isUser } from '@payload/access/isUser'
import { CollectionConfig } from 'payload/types'
+import { COLLECTION_SLUG_MEDIA } from './config'
export const Media: CollectionConfig = {
- slug: 'media',
+ slug: COLLECTION_SLUG_MEDIA,
admin: {},
access: {
read: (): boolean => true,
diff --git a/src/app/(payload)/collections/Posts.ts b/src/app/(payload)/collections/Posts.ts
index bb921a6..4a1a0e1 100644
--- a/src/app/(payload)/collections/Posts.ts
+++ b/src/app/(payload)/collections/Posts.ts
@@ -5,9 +5,10 @@ import { revalidateTag } from 'next/cache'
import { generateDocumentCacheKey } from '@/utils/getDocument'
import { slugField, pathField } from '@payload/fields/'
import { blocksField } from '@payload/fields/blocks'
+import { COLLECTION_SLUG_POST } from './config'
const Posts: CollectionConfig = {
- slug: 'posts',
+ slug: COLLECTION_SLUG_POST,
versions: {
drafts: {
autosave: false,
diff --git a/src/app/(payload)/collections/Users.ts b/src/app/(payload)/collections/Users.ts
index d586be3..f6cc133 100644
--- a/src/app/(payload)/collections/Users.ts
+++ b/src/app/(payload)/collections/Users.ts
@@ -1,8 +1,9 @@
import { CollectionConfig } from 'payload/types'
import { isAdmin, isAdminOrSelf } from '@payload/access/isAdmin'
+import { COLLECTION_SLUG_USER } from './config'
const Users: CollectionConfig = {
- slug: 'users',
+ slug: COLLECTION_SLUG_USER,
auth: true,
admin: {
defaultColumns: ['roles', 'email'],
diff --git a/src/app/(payload)/collections/config.ts b/src/app/(payload)/collections/config.ts
index c16e632..592c961 100644
--- a/src/app/(payload)/collections/config.ts
+++ b/src/app/(payload)/collections/config.ts
@@ -1,11 +1,5 @@
-/* export const COLLECTION_SLUG_USER = 'users' as const
-export const COLLECTION_SLUG_SESSIONS = 'sessions' as const
-export const COLLECTION_SLUG_FORMS = 'forms' as const
-export const COLLECTION_SLUG_MEDIA = 'media' as const
- */
+export const COLLECTION_SLUG_USER = 'users' as const
export const COLLECTION_SLUG_PAGE = 'pages' as const
export const COLLECTION_SLUG_POST = 'posts' as const
-
-/* export const COLLECTION_SLUG_PRODUCTS = 'products' as const
-export const COLLECTION_SLUG_PRICES = 'prices' as const
-export const COLLECTION_SLUG_SUBSCRIPTIONS = 'subscriptions' as const */
+export const COLLECTION_SLUG_MEDIA = 'media' as const
+export const COLLECTION_SLUG_AUTHOR = 'authors' as const
diff --git a/src/components/Blocks/Posts.tsx b/src/components/Blocks/PostList.tsx
similarity index 84%
rename from src/components/Blocks/Posts.tsx
rename to src/components/Blocks/PostList.tsx
index a6fd33c..c29555d 100644
--- a/src/components/Blocks/Posts.tsx
+++ b/src/components/Blocks/PostList.tsx
@@ -3,6 +3,7 @@ import PostEntry from '@/components/PostEntry'
import { getPayloadHMR } from '@payloadcms/next/utilities'
import configPromise from '@payload-config'
import { PaginatedDocs } from 'payload/database'
+import { COLLECTION_SLUG_POST } from '@payload/collections/config'
type Props = {}
@@ -11,10 +12,10 @@ const payload = await getPayloadHMR({
})
const posts: PaginatedDocs = await payload.find({
- collection: 'posts',
+ collection: COLLECTION_SLUG_POST,
})
-export default function Posts(props: Props) {
+export default function PostList(props: Props) {
return (
Posts
diff --git a/src/components/PostEntry.tsx b/src/components/PostEntry.tsx
index 1d207d4..45f322b 100644
--- a/src/components/PostEntry.tsx
+++ b/src/components/PostEntry.tsx
@@ -1,5 +1,6 @@
import { Post } from 'types/payload-types'
import Image from 'next/image'
+import { COLLECTION_SLUG_POST } from '@/app/(payload)/collections/config'
interface Props {
post: Post
@@ -9,7 +10,10 @@ export default function PostEntry(props: Props) {
if (typeof props.post.thumbnail === 'string') return
return (
-
+
-
+
{props?.post.author && typeof props?.post.author !== 'string' && (
)}