feature: next/prev buttons

This commit is contained in:
Benno Tielen 2026-04-17 09:37:20 +02:00
parent 3fab363e1f
commit 130d5b89df
7 changed files with 24493 additions and 1 deletions

View file

@ -23,6 +23,7 @@ import { PublicationAndNewsletterBlock } from '@/collections/blocks/PublicationA
import { ContactPersonBlock } from '@/collections/blocks/ContactPersonBlock'
import { ImageCardsBlock } from '@/collections/blocks/ImageCards'
import { ClassifiedsBlock } from '@/collections/blocks/Classifieds'
import { NextPrevButtonsBlock } from '@/collections/blocks/NextPrevButtons'
import { isPublishedPublic } from '@/collections/access/public'
export const Pages: CollectionConfig = {
@ -106,6 +107,7 @@ export const Pages: CollectionConfig = {
ContactPersonBlock,
ImageCardsBlock,
ClassifiedsBlock,
NextPrevButtonsBlock,
],
},
],

View file

@ -0,0 +1,64 @@
import { Block } from 'payload'
import { validateHref } from '@/globals/ValidateHref'
export const NextPrevButtonsBlock: Block = {
slug: 'nextPrevButtons',
labels: {
singular: {
de: 'Zurück-/Weiter-Buttons',
},
plural: {
de: 'Zurück-/Weiter-Buttons',
},
},
fields: [
{
name: 'prev',
type: 'group',
label: {
de: 'Zurück',
},
fields: [
{
name: 'text',
type: 'text',
label: {
de: 'Text',
},
},
{
name: 'href',
type: 'text',
label: {
de: 'Zieladresse',
},
validate: validateHref,
},
],
},
{
name: 'next',
type: 'group',
label: {
de: 'Weiter',
},
fields: [
{
name: 'text',
type: 'text',
label: {
de: 'Text',
},
},
{
name: 'href',
type: 'text',
label: {
de: 'Zieladresse',
},
validate: validateHref,
},
],
},
],
}

View file

@ -23,6 +23,7 @@ import { MassTimesBlock } from '@/compositions/Blocks/MassTimesBlock'
import { EventsBlock } from '@/compositions/Blocks/EventsBlock'
import { ImageCardsBlock } from '@/compositions/Blocks/ImageCardsBlock'
import { ClassifiedsFromApi } from '@/components/Classifieds/ClassifiedsFromApi'
import { NextPrevButtons } from '@/components/NextPrevButtons/NextPrevButtons'
type BlocksProps = {
content: Blog['content']['content'] | NonNullable<Page['content']>
@ -265,6 +266,20 @@ export function Blocks({ content }: BlocksProps) {
)
}
if (item.blockType === 'nextPrevButtons') {
const prev = item.prev?.href && item.prev?.text
? { href: item.prev.href, text: item.prev.text }
: undefined
const next = item.next?.href && item.next?.text
? { href: item.next.href, text: item.next.text }
: undefined
return (
<Section key={item.id} padding={'small'}>
<NextPrevButtons prev={prev} next={next} />
</Section>
)
}
if (item.blockType === 'contactPersonBlock') {
const contact = typeof item.contact === 'object'
? item.contact

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,52 @@
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
await db.execute(sql`
CREATE TABLE "pages_blocks_next_prev_buttons" (
"_order" integer NOT NULL,
"_parent_id" uuid NOT NULL,
"_path" text NOT NULL,
"id" varchar PRIMARY KEY NOT NULL,
"prev_text" varchar,
"prev_href" varchar,
"next_text" varchar,
"next_href" varchar,
"block_name" varchar
);
CREATE TABLE "_pages_v_blocks_next_prev_buttons" (
"_order" integer NOT NULL,
"_parent_id" uuid NOT NULL,
"_path" text NOT NULL,
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"prev_text" varchar,
"prev_href" varchar,
"next_text" varchar,
"next_href" varchar,
"_uuid" varchar,
"block_name" varchar
);
ALTER TABLE "announcement" ALTER COLUMN "date" SET DEFAULT '2026-04-19T07:28:46.077Z';
ALTER TABLE "calendar" ALTER COLUMN "date" SET DEFAULT '2026-04-19T07:28:46.368Z';
ALTER TABLE "classifieds" ALTER COLUMN "until" SET DEFAULT '2026-05-17T07:28:46.426Z';
ALTER TABLE "pages_blocks_next_prev_buttons" ADD CONSTRAINT "pages_blocks_next_prev_buttons_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."pages"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "_pages_v_blocks_next_prev_buttons" ADD CONSTRAINT "_pages_v_blocks_next_prev_buttons_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."_pages_v"("id") ON DELETE cascade ON UPDATE no action;
CREATE INDEX "pages_blocks_next_prev_buttons_order_idx" ON "pages_blocks_next_prev_buttons" USING btree ("_order");
CREATE INDEX "pages_blocks_next_prev_buttons_parent_id_idx" ON "pages_blocks_next_prev_buttons" USING btree ("_parent_id");
CREATE INDEX "pages_blocks_next_prev_buttons_path_idx" ON "pages_blocks_next_prev_buttons" USING btree ("_path");
CREATE INDEX "_pages_v_blocks_next_prev_buttons_order_idx" ON "_pages_v_blocks_next_prev_buttons" USING btree ("_order");
CREATE INDEX "_pages_v_blocks_next_prev_buttons_parent_id_idx" ON "_pages_v_blocks_next_prev_buttons" USING btree ("_parent_id");
CREATE INDEX "_pages_v_blocks_next_prev_buttons_path_idx" ON "_pages_v_blocks_next_prev_buttons" USING btree ("_path");`)
}
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
await db.execute(sql`
ALTER TABLE "pages_blocks_next_prev_buttons" DISABLE ROW LEVEL SECURITY;
ALTER TABLE "_pages_v_blocks_next_prev_buttons" DISABLE ROW LEVEL SECURITY;
DROP TABLE "pages_blocks_next_prev_buttons" CASCADE;
DROP TABLE "_pages_v_blocks_next_prev_buttons" CASCADE;
ALTER TABLE "announcement" ALTER COLUMN "date" SET DEFAULT '2026-04-19T12:14:50.471Z';
ALTER TABLE "calendar" ALTER COLUMN "date" SET DEFAULT '2026-04-19T12:14:50.803Z';
ALTER TABLE "classifieds" ALTER COLUMN "until" SET DEFAULT '2026-05-16T12:14:50.859Z';`)
}

View file

@ -36,6 +36,7 @@ import * as migration_20260413_122020 from './20260413_122020';
import * as migration_20260416_090954_group_image_cards from './20260416_090954_group_image_cards';
import * as migration_20260416_115446 from './20260416_115446';
import * as migration_20260416_121451 from './20260416_121451';
import * as migration_20260417_072846 from './20260417_072846';
export const migrations = [
{
@ -226,6 +227,11 @@ export const migrations = [
{
up: migration_20260416_121451.up,
down: migration_20260416_121451.down,
name: '20260416_121451'
name: '20260416_121451',
},
{
up: migration_20260417_072846.up,
down: migration_20260417_072846.down,
name: '20260417_072846'
},
];

View file

@ -666,6 +666,19 @@ export interface Page {
blockName?: string | null;
blockType: 'classifieds';
}
| {
prev?: {
text?: string | null;
href?: string | null;
};
next?: {
text?: string | null;
href?: string | null;
};
id?: string | null;
blockName?: string | null;
blockType: 'nextPrevButtons';
}
)[]
| null;
updatedAt: string;
@ -2146,6 +2159,24 @@ export interface PagesSelect<T extends boolean = true> {
id?: T;
blockName?: T;
};
nextPrevButtons?:
| T
| {
prev?:
| T
| {
text?: T;
href?: T;
};
next?:
| T
| {
text?: T;
href?: T;
};
id?: T;
blockName?: T;
};
};
updatedAt?: T;
createdAt?: T;