calendar and testimonials
This commit is contained in:
parent
ad34d78d40
commit
63bc055191
22 changed files with 1044 additions and 19 deletions
|
|
@ -17,7 +17,7 @@
|
|||
function startHold(id: string) {
|
||||
holdingId = id;
|
||||
holdTimer = setTimeout(() => {
|
||||
const idx = blocks.findIndex((b) => b.id === id);
|
||||
const idx = blocks.findIndex((b: ContentBlock) => b.id === id);
|
||||
onDelete(id);
|
||||
onSelect(blocks[idx + 1]?.id || blocks[idx - 1]?.id || '');
|
||||
holdingId = '';
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ export const blockLabels: Record<BlockType, string> = {
|
|||
timeline: 'Timeline',
|
||||
hero: 'Hero',
|
||||
button: 'Button',
|
||||
spacer: 'Spacer'
|
||||
spacer: 'Spacer',
|
||||
testimonials: 'Testimonials',
|
||||
upcoming_calendar: 'Upcoming Calendar'
|
||||
};
|
||||
|
||||
export const blockTypes = Object.keys(blockLabels) as BlockType[];
|
||||
|
|
@ -44,6 +46,23 @@ export function createBlock(type: BlockType): ContentBlock {
|
|||
case 'spacer':
|
||||
base.data = { height: 64 };
|
||||
break;
|
||||
case 'testimonials':
|
||||
base.data = {
|
||||
title: 'What They Say About Me',
|
||||
items: [
|
||||
{ text: 'Recently I started to experience incredible whole-body orgasms. And now I know how it works. My awareness around sexuality changed for good and I feel like a boss of my own life. What a joy to have this freedom of choice.', title: 'Anne' },
|
||||
{ text: 'I never thought it was possible to sense so much pleasure in my body without intense stimulations I got used to. After the series of sessions, I could feel something like a trance state by receiving only a gentle touch. That was a totally new experience for me.', title: 'Espen' },
|
||||
{ text: "Eva's sexual healing methods should be accessible to everyone. I am amazed by the depth and integrity of the message she conveys through her work. I was meeting Eva for healing my body and, as a result, I reconnected with my heart and soul too.", title: 'Marie' },
|
||||
{ text: "It is hard to surprise me with any sexual activity since I had many exciting experiments in my life. But I always suspected that there might be something more I have not yet felt and tried. Thanks to Eva I realised how much power I've got. Under her guidance, I have learnt to maximise my orgasmic potential and consciously play with arousal. By the way, my wife is also happy that I became enthusiastic about new sexual practices.", title: 'Jan' }
|
||||
]
|
||||
};
|
||||
break;
|
||||
case 'upcoming_calendar':
|
||||
base.data = {
|
||||
title: 'Upcoming Events',
|
||||
categories: []
|
||||
};
|
||||
break;
|
||||
}
|
||||
base.data._background = { type: 'none', color: '', attachment: 'scroll', overlay: false, overlayOpacity: 40 };
|
||||
return base;
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
import RichTextEditor from './RichTextEditor.svelte';
|
||||
import ImageUploader from './ImageUploader.svelte';
|
||||
import SegmentedControl from './SegmentedControl.svelte';
|
||||
import SpacerBlock from '../../blocks/SpacerBlock.svelte';
|
||||
|
||||
let { block, onChange = (block: ContentBlock) => {} } = $props<{
|
||||
let { block, eventCategories = [], onChange = (block: ContentBlock) => {} } = $props<{
|
||||
block: ContentBlock | null;
|
||||
eventCategories?: string[];
|
||||
onChange?: (block: ContentBlock) => void;
|
||||
}>();
|
||||
|
||||
|
|
@ -33,6 +33,21 @@
|
|||
if (!block) return;
|
||||
updateData({ [key]: (block.data[key] || []).filter((_: unknown, i: number) => i !== index) });
|
||||
}
|
||||
|
||||
function toggleCategory(category: string) {
|
||||
if (!block) return;
|
||||
const categories = block.data.categories || [];
|
||||
updateData({
|
||||
categories: categories.includes(category)
|
||||
? categories.filter((item: string) => item !== category)
|
||||
: [...categories, category]
|
||||
});
|
||||
}
|
||||
|
||||
function titleCase(value: string | number) {
|
||||
const text = String(value);
|
||||
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if !block}
|
||||
|
|
@ -103,7 +118,7 @@
|
|||
options={['left', 'center', 'right']}
|
||||
value={block.data.alignment || 'left'}
|
||||
onChange={(v) => updateData({ alignment: v })}
|
||||
formatLabel={(v) => v.charAt(0).toUpperCase() + v.slice(1)}
|
||||
formatLabel={titleCase}
|
||||
/>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
|
|
@ -112,7 +127,7 @@
|
|||
options={['xs', 'sm', 'md', 'lg']}
|
||||
value={block.data.size || 'md'}
|
||||
onChange={(v) => updateData({ size: v })}
|
||||
formatLabel={(v) => ({ xs: 'Extra Small', sm: 'Small', md: 'Medium', lg: 'Large' }[v] || v)}
|
||||
formatLabel={(v) => String({ xs: 'Extra Small', sm: 'Small', md: 'Medium', lg: 'Large' }[String(v)] || v)}
|
||||
/>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
|
|
@ -132,6 +147,59 @@
|
|||
<input type="number" class="input input-bordered w-full" value={block.data.height || 64} oninput={(e) => updateData({ height: parseInt(e.currentTarget.value) || 64 })} />
|
||||
</label>
|
||||
</div>
|
||||
{:else if block.type === 'testimonials'}
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Section Title</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
</label>
|
||||
|
||||
{#each block.data.items || [] as item, i}
|
||||
<div class="rounded-box mb-3 border border-base-300 p-4">
|
||||
<textarea
|
||||
class="textarea textarea-bordered w-full mb-2"
|
||||
placeholder="Testimonial text"
|
||||
rows="3"
|
||||
value={item.text}
|
||||
oninput={(e) => updateArray('items', i, { text: e.currentTarget.value })}
|
||||
></textarea>
|
||||
<input
|
||||
class="input input-bordered w-full"
|
||||
placeholder="Author name"
|
||||
value={item.title}
|
||||
oninput={(e) => updateArray('items', i, { title: e.currentTarget.value })}
|
||||
/>
|
||||
<button class="btn btn-error btn-sm mt-2" type="button" onclick={() => removeArrayItem('items', i)}>Remove</button>
|
||||
</div>
|
||||
{/each}
|
||||
<button class="btn" type="button" onclick={() => addArrayItem('items', { text: '', title: '' })}>Add testimonial</button>
|
||||
</div>
|
||||
{:else if block.type === 'upcoming_calendar'}
|
||||
<div class="space-y-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Section title</span></div>
|
||||
<input class="input input-bordered w-full" value={block.data.title || ''} oninput={(e) => updateData({ title: e.currentTarget.value })} />
|
||||
</label>
|
||||
|
||||
<div class="rounded-box border border-base-300 p-4">
|
||||
<div class="mb-3">
|
||||
<h3 class="font-semibold">Category filters</h3>
|
||||
<p class="text-sm text-base-content/60">Choose categories to show in this block. Leave all unchecked to show every published event.</p>
|
||||
</div>
|
||||
{#if eventCategories?.length}
|
||||
<div class="flex flex-wrap gap-2">
|
||||
{#each eventCategories as category}
|
||||
<label class="btn btn-sm" class:btn-primary={(block.data.categories || []).includes(category)}>
|
||||
<input class="hidden" type="checkbox" checked={(block.data.categories || []).includes(category)} onchange={() => toggleCategory(category)} />
|
||||
{category}
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="text-sm text-base-content/60">No event categories exist yet. Create events in the Calendar admin page first.</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="rounded-box border border-base-300 p-4 mt-4">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<script lang="ts">
|
||||
import type { ContentBlock, BlockBackground, BlockForeground } from '$lib/types';
|
||||
import type { CalendarEventRecord, ContentBlock, BlockBackground, BlockForeground } from '$lib/types';
|
||||
import BackgroundWrapper from './BackgroundWrapper.svelte';
|
||||
import TextBlock from './TextBlock.svelte';
|
||||
import ImageTextBlock from './ImageTextBlock.svelte';
|
||||
|
|
@ -7,8 +7,10 @@
|
|||
import HeroBlock from './HeroBlock.svelte';
|
||||
import ButtonBlock from './ButtonBlock.svelte';
|
||||
import SpacerBlock from './SpacerBlock.svelte';
|
||||
import TestimonialsBlock from './TestimonialsBlock.svelte';
|
||||
import UpcomingCalendarBlock from './UpcomingCalendarBlock.svelte';
|
||||
|
||||
let { blocks = [] } = $props<{ blocks: ContentBlock[] }>();
|
||||
let { blocks = [], calendarEvents = [] } = $props<{ blocks: ContentBlock[]; calendarEvents?: CalendarEventRecord[] }>();
|
||||
|
||||
function getBg(block: ContentBlock): BlockBackground {
|
||||
return (block.data._background as BlockBackground) || { type: 'none', color: '', imageUrl: '', attachment: 'scroll', overlay: false, overlayOpacity: 40 };
|
||||
|
|
@ -33,6 +35,10 @@
|
|||
<ButtonBlock data={block.data} />
|
||||
{:else if block.type === 'spacer'}
|
||||
<SpacerBlock data={block.data} />
|
||||
{:else if block.type === 'testimonials'}
|
||||
<TestimonialsBlock data={block.data} />
|
||||
{:else if block.type === 'upcoming_calendar'}
|
||||
<UpcomingCalendarBlock data={block.data} events={calendarEvents} />
|
||||
{/if}
|
||||
</BackgroundWrapper>
|
||||
{/each}
|
||||
|
|
|
|||
87
app/src/lib/blocks/TestimonialsBlock.svelte
Normal file
87
app/src/lib/blocks/TestimonialsBlock.svelte
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<script lang="ts">
|
||||
let { data } = $props<{ data: Record<string, any> }>();
|
||||
|
||||
const testimonials = data.items || [
|
||||
{ text: 'Recently I started to experience incredible whole-body orgasms. And now I know how it works. My awareness around sexuality changed for good and I feel like a boss of my own life. What a joy to have this freedom of choice.', title: 'Anne' },
|
||||
{ text: 'I never thought it was possible to sense so much pleasure in my body without intense stimulations I got used to. After the series of sessions, I could feel something like a trance state by receiving only a gentle touch. That was a totally new experience for me.', title: 'Espen' },
|
||||
{ text: "Eva's sexual healing methods should be accessible to everyone. I am amazed by the depth and integrity of the message she conveys through her work. I was meeting Eva for healing my body and, as a result, I reconnected with my heart and soul too.", title: 'Marie' },
|
||||
{ text: "It is hard to surprise me with any sexual activity since I had many exciting experiments in my life. But I always suspected that there might be something more I have not yet felt and tried. Thanks to Eva I realised how much power I've got. Under her guidance, I have learnt to maximise my orgasmic potential and consciously play with arousal. By the way, my wife is also happy that I became enthusiastic about new sexual practices.", title: 'Jan' }
|
||||
];
|
||||
|
||||
const title = data.title || 'What They Say About Me';
|
||||
|
||||
// Simple state for carousel
|
||||
let currentIndex = $state(0);
|
||||
const totalSlides = testimonials.length;
|
||||
|
||||
function next() {
|
||||
currentIndex = (currentIndex + 1) % totalSlides;
|
||||
}
|
||||
|
||||
function prev() {
|
||||
currentIndex = (currentIndex - 1 + totalSlides) % totalSlides;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="relative min-h-[400px]">
|
||||
<div class="flex flex-col items-center px-4 py-12 min-h-[400px]">
|
||||
<!-- Title -->
|
||||
<h2 class="text-fg-heading text-2xl md:text-3xl font-light tracking-wide">
|
||||
{title}
|
||||
</h2>
|
||||
|
||||
<!-- Testimonial carousel - fills remaining space and centers content vertically -->
|
||||
<div class="w-full max-w-3xl flex-1 flex items-center justify-center">
|
||||
<!-- Slides are stacked in a grid so the carousel keeps the height of the tallest testimonial. -->
|
||||
<div class="grid px-8 text-center w-full pt-4 md:pt-8">
|
||||
{#each testimonials as testimonial, i}
|
||||
<div class="col-start-1 row-start-1 transition-opacity duration-300 {i === currentIndex ? 'opacity-100' : 'pointer-events-none opacity-0'}" aria-hidden={i !== currentIndex}>
|
||||
<p class="text-fg-body/85 text-lg md:text-xl font-light leading-relaxed mb-8">
|
||||
"{testimonial.text}"
|
||||
</p>
|
||||
<p class="text-fg-subheading font-medium tracking-wider">
|
||||
— {testimonial.title}
|
||||
</p>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Navigation arrows -->
|
||||
<div class="flex justify-center items-center gap-8">
|
||||
<button
|
||||
type="button"
|
||||
onclick={prev}
|
||||
class="w-10 h-10 rounded-full flex items-center justify-center transition-colors hover:bg-[rgba(255,236,224,1)] hover:text-[#93384a] bg-[rgba(255,219,197,0.8)]"
|
||||
aria-label="Previous slide"
|
||||
>
|
||||
<svg viewBox="0 0 7.3 13" class="w-2 h-3" fill="none" stroke="currentColor" stroke-width="1.5">
|
||||
<polyline points="6.5,0.5 1.5,6.5 6.5,12.5" stroke-linecap="butt" stroke-linejoin="miter"/>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<!-- Dots/bullets -->
|
||||
<div class="flex gap-3">
|
||||
{#each testimonials as _, i}
|
||||
<button
|
||||
type="button"
|
||||
class="w-2.5 h-2.5 rounded-full border-2 transition-colors {i === currentIndex ? 'bg-current' : 'border-current'}"
|
||||
aria-label="Go to slide {i + 1}"
|
||||
onclick={() => (currentIndex = i)}
|
||||
></button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onclick={next}
|
||||
class="w-10 h-10 rounded-full flex items-center justify-center transition-colors hover:bg-[rgba(255,236,224,1)] hover:text-[#93384a] bg-[rgba(255,219,197,0.8)]"
|
||||
aria-label="Next slide"
|
||||
>
|
||||
<svg viewBox="0 0 7.3 13" class="w-2 h-3" fill="none" stroke="currentColor" stroke-width="1.5">
|
||||
<polyline points="0.5,0.5 5.5,6.5 0.5,12.5" stroke-linecap="butt" stroke-linejoin="miter"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
let items = $derived(data.items?.length ? data.items : [
|
||||
{ title: 'Your story here', description: 'Add milestones, training, or the journey behind the practice.' }
|
||||
]);
|
||||
let widths = $derived(items.map((_, i) => {
|
||||
let widths = $derived(items.map((_: TimelineItem, i: number) => {
|
||||
const opts = ['w-[78%]', 'w-[85%]', 'w-[90%]', 'w-[95%]', 'w-[98%]'];
|
||||
return opts[(i * 7 + 3) % opts.length];
|
||||
}));
|
||||
|
|
|
|||
126
app/src/lib/blocks/UpcomingCalendarBlock.svelte
Normal file
126
app/src/lib/blocks/UpcomingCalendarBlock.svelte
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
<script lang="ts">
|
||||
import type { CalendarEventRecord, UpcomingCalendarBlockData } from '$lib/types';
|
||||
import {
|
||||
dateKey,
|
||||
eventMatchesCategories,
|
||||
eventOverlapsDay,
|
||||
eventRange,
|
||||
formatEventDateRange,
|
||||
getCurrentAndNextMonths,
|
||||
isExternalLink,
|
||||
normalizeLink,
|
||||
sortEvents
|
||||
} from '$lib/calendar';
|
||||
|
||||
let { data = {}, events = [] } = $props<{
|
||||
data: UpcomingCalendarBlockData;
|
||||
events?: CalendarEventRecord[];
|
||||
}>();
|
||||
|
||||
const weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
let months = $derived(getCurrentAndNextMonths());
|
||||
let selectedCategories = $derived(data.categories || []);
|
||||
let visibleEvents = $derived(sortEvents(events.filter((event: CalendarEventRecord) => event.published && eventMatchesCategories(event, selectedCategories))));
|
||||
|
||||
function eventsForDay(date: Date) {
|
||||
return visibleEvents.filter((event) => eventOverlapsDay(event, date));
|
||||
}
|
||||
|
||||
function eventStyle(event: CalendarEventRecord) {
|
||||
return `--event-color: ${event.color || '#8a9a7b'};`;
|
||||
}
|
||||
|
||||
function segmentMeta(event: CalendarEventRecord, date: Date) {
|
||||
const { start, end } = eventRange(event);
|
||||
const isStart = dateKey(start) === dateKey(date);
|
||||
const isEnd = dateKey(end) === dateKey(date);
|
||||
const startsWeek = date.getDay() === 0;
|
||||
const endsWeek = date.getDay() === 6;
|
||||
const visualStart = isStart || startsWeek;
|
||||
const visualEnd = isEnd || endsWeek;
|
||||
|
||||
return {
|
||||
showLabel: visualStart,
|
||||
classes: [
|
||||
visualStart ? 'rounded-l-xl' : 'rounded-l-none -ml-3',
|
||||
visualEnd ? 'rounded-r-xl' : 'rounded-r-none -mr-3',
|
||||
visualStart && visualEnd ? 'mx-0' : '',
|
||||
!visualStart && !visualEnd ? '-mx-3' : ''
|
||||
].filter(Boolean).join(' ')
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<section class="mx-auto max-w-7xl px-6 py-16">
|
||||
<div class="mb-10 text-center">
|
||||
<p class="text-sm uppercase tracking-[0.3em] text-sage-dark/75">Calendar</p>
|
||||
<h2 class="font-display mt-2 text-4xl text-charcoal md:text-5xl">{data.title || 'Upcoming Events'}</h2>
|
||||
</div>
|
||||
|
||||
{#if visibleEvents.length === 0}
|
||||
<div class="mx-auto max-w-2xl rounded-[2rem] border border-sage/20 bg-white/70 p-8 text-center shadow-sm">
|
||||
<p class="text-charcoal/70">No upcoming events are available for the selected categories.</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="isolate grid gap-8 lg:grid-cols-2">
|
||||
{#each months as month}
|
||||
<div class="relative z-0 overflow-visible rounded-[2rem] border border-sage/15 bg-white/80 p-5 shadow-sm backdrop-blur hover:z-[9000] focus-within:z-[9000]">
|
||||
<h3 class="font-display mb-5 text-center text-3xl text-charcoal">{month.label}</h3>
|
||||
<div class="mb-2 grid grid-cols-7 gap-1 text-center text-xs font-semibold uppercase tracking-wide text-charcoal/45">
|
||||
{#each weekdays as weekday}<div>{weekday}</div>{/each}
|
||||
</div>
|
||||
<div class="grid grid-cols-7 gap-1 overflow-visible">
|
||||
{#each month.days as day}
|
||||
<div class="relative min-h-28 overflow-visible rounded-2xl border p-2 {day.inMonth ? 'border-sage/10 bg-warm/60' : 'border-sage/5 bg-warm/25'}" class:ring-2={day.isToday} class:ring-sage={day.isToday}>
|
||||
<div class="mb-1 flex items-center justify-between">
|
||||
<span class="text-sm font-semibold {day.inMonth ? 'text-charcoal/70' : 'text-charcoal/30'}">{day.dayNumber}</span>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
{#each eventsForDay(day.date) as event}
|
||||
{@const href = normalizeLink(event.link)}
|
||||
{@const label = `${event.name}${event.description ? `: ${event.description}` : ''}`}
|
||||
{@const segment = segmentMeta(event, day.date)}
|
||||
{#if href}
|
||||
<a
|
||||
class="group/event relative z-10 block px-2 py-1 text-left text-[0.7rem] font-semibold leading-tight text-white shadow-sm hover:z-[9999] hover:shadow-md focus:z-[9999] focus:outline-none focus:ring-2 focus:ring-charcoal/30 {segment.classes}"
|
||||
href={href}
|
||||
target={isExternalLink(href) ? '_blank' : undefined}
|
||||
rel={isExternalLink(href) ? 'noreferrer' : undefined}
|
||||
style={eventStyle(event)}
|
||||
aria-label={label}
|
||||
>
|
||||
<span class="absolute inset-0 bg-[var(--event-color)] {segment.classes}"></span>
|
||||
<span class="relative block truncate">{segment.showLabel ? event.name : '\u00a0'}</span>
|
||||
<span class="pointer-events-none absolute bottom-full left-0 z-[10000] mb-2 hidden w-64 rounded-xl bg-charcoal p-3 text-xs font-normal leading-relaxed text-white shadow-xl group-hover/event:block group-focus/event:block">
|
||||
<strong class="block">{event.name}</strong>
|
||||
<span class="block opacity-80">{formatEventDateRange(event)}</span>
|
||||
{#if event.description}<span class="mt-1 block">{event.description}</span>{/if}
|
||||
</span>
|
||||
</a>
|
||||
{:else}
|
||||
<span
|
||||
class="group/event relative z-10 block px-2 py-1 text-left text-[0.7rem] font-semibold leading-tight text-white shadow-sm hover:z-[9999] focus:z-[9999] focus:outline-none focus:ring-2 focus:ring-charcoal/30 {segment.classes}"
|
||||
style={eventStyle(event)}
|
||||
tabindex="0"
|
||||
role="button"
|
||||
aria-label={label}
|
||||
>
|
||||
<span class="absolute inset-0 bg-[var(--event-color)] {segment.classes}"></span>
|
||||
<span class="relative block truncate">{segment.showLabel ? event.name : '\u00a0'}</span>
|
||||
<span class="pointer-events-none absolute bottom-full left-0 z-[10000] mb-2 hidden w-64 rounded-xl bg-charcoal p-3 text-xs font-normal leading-relaxed text-white shadow-xl group-hover/event:block group-focus/event:block">
|
||||
<strong class="block">{event.name}</strong>
|
||||
<span class="block opacity-80">{formatEventDateRange(event)}</span>
|
||||
{#if event.description}<span class="mt-1 block">{event.description}</span>{/if}
|
||||
</span>
|
||||
</span>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
199
app/src/lib/calendar.ts
Normal file
199
app/src/lib/calendar.ts
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
import type { CalendarEventRecord, ContentBlock } from '$lib/types';
|
||||
|
||||
type UnknownRecord = Record<string, unknown>;
|
||||
|
||||
export type CalendarDay = {
|
||||
date: Date;
|
||||
dateKey: string;
|
||||
dayNumber: number;
|
||||
inMonth: boolean;
|
||||
isToday: boolean;
|
||||
};
|
||||
|
||||
export type CalendarMonth = {
|
||||
date: Date;
|
||||
label: string;
|
||||
days: CalendarDay[];
|
||||
};
|
||||
|
||||
export function hasUpcomingCalendarBlock(blocks: ContentBlock[] = []) {
|
||||
return blocks.some((block) => block.type === 'upcoming_calendar');
|
||||
}
|
||||
|
||||
export function toDateInput(value?: string | null) {
|
||||
if (!value) return '';
|
||||
return value.slice(0, 10);
|
||||
}
|
||||
|
||||
export function toDatetimeInput(value?: string | null) {
|
||||
if (!value) return '';
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return value.slice(0, 16);
|
||||
const offset = date.getTimezoneOffset();
|
||||
const local = new Date(date.getTime() - offset * 60_000);
|
||||
return local.toISOString().slice(0, 16);
|
||||
}
|
||||
|
||||
export function dateInputToPocketBase(value: string, allDay = true) {
|
||||
if (!value) return '';
|
||||
if (!allDay && value.includes('T')) {
|
||||
return new Date(value).toISOString();
|
||||
}
|
||||
return `${value.slice(0, 10)} 00:00:00.000Z`;
|
||||
}
|
||||
|
||||
export function parseEventDate(value?: string | null) {
|
||||
if (!value) return null;
|
||||
const datePart = value.slice(0, 10);
|
||||
const [year, month, day] = datePart.split('-').map(Number);
|
||||
if (!year || !month || !day) return null;
|
||||
return new Date(year, month - 1, day);
|
||||
}
|
||||
|
||||
export function dateKey(date: Date) {
|
||||
const year = date.getFullYear();
|
||||
const month = `${date.getMonth() + 1}`.padStart(2, '0');
|
||||
const day = `${date.getDate()}`.padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
|
||||
export function addDays(date: Date, days: number) {
|
||||
const copy = new Date(date);
|
||||
copy.setDate(copy.getDate() + days);
|
||||
return copy;
|
||||
}
|
||||
|
||||
export function addMonths(date: Date, months: number) {
|
||||
return new Date(date.getFullYear(), date.getMonth() + months, 1);
|
||||
}
|
||||
|
||||
export function startOfMonth(date = new Date()) {
|
||||
return new Date(date.getFullYear(), date.getMonth(), 1);
|
||||
}
|
||||
|
||||
export function endOfMonth(date = new Date()) {
|
||||
return new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
||||
}
|
||||
|
||||
export function getUpcomingCalendarRange(reference = new Date()) {
|
||||
const start = startOfMonth(reference);
|
||||
const end = endOfMonth(addMonths(reference, 1));
|
||||
return { start, end };
|
||||
}
|
||||
|
||||
export function createCalendarMonth(monthDate: Date, reference = new Date()): CalendarMonth {
|
||||
const first = startOfMonth(monthDate);
|
||||
const monthEnd = endOfMonth(monthDate);
|
||||
const gridStart = addDays(first, -first.getDay());
|
||||
const gridEnd = addDays(monthEnd, 6 - monthEnd.getDay());
|
||||
const todayKey = dateKey(reference);
|
||||
const days: CalendarDay[] = [];
|
||||
|
||||
for (let day = new Date(gridStart); day <= gridEnd; day = addDays(day, 1)) {
|
||||
days.push({
|
||||
date: new Date(day),
|
||||
dateKey: dateKey(day),
|
||||
dayNumber: day.getDate(),
|
||||
inMonth: day.getMonth() === first.getMonth(),
|
||||
isToday: dateKey(day) === todayKey
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
date: first,
|
||||
label: first.toLocaleDateString(undefined, { month: 'long', year: 'numeric' }),
|
||||
days
|
||||
};
|
||||
}
|
||||
|
||||
export function getCurrentAndNextMonths(reference = new Date()) {
|
||||
const current = startOfMonth(reference);
|
||||
return [createCalendarMonth(current, reference), createCalendarMonth(addMonths(current, 1), reference)];
|
||||
}
|
||||
|
||||
export function rangesOverlap(startA: Date, endA: Date, startB: Date, endB: Date) {
|
||||
return startA <= endB && endA >= startB;
|
||||
}
|
||||
|
||||
export function eventRange(event: Pick<CalendarEventRecord, 'start' | 'end'>) {
|
||||
const start = parseEventDate(event.start) || new Date();
|
||||
const end = parseEventDate(event.end) || start;
|
||||
return end < start ? { start: end, end: start } : { start, end };
|
||||
}
|
||||
|
||||
export function eventOverlapsDay(event: CalendarEventRecord, day: Date) {
|
||||
const { start, end } = eventRange(event);
|
||||
return rangesOverlap(start, end, day, day);
|
||||
}
|
||||
|
||||
export function eventOverlapsRange(event: CalendarEventRecord, start: Date, end: Date) {
|
||||
const range = eventRange(event);
|
||||
return rangesOverlap(range.start, range.end, start, end);
|
||||
}
|
||||
|
||||
export function normalizeEvent(record: UnknownRecord): CalendarEventRecord {
|
||||
return {
|
||||
id: String(record.id || ''),
|
||||
name: String(record.name || ''),
|
||||
start: String(record.start || ''),
|
||||
end: record.end ? String(record.end) : '',
|
||||
description: record.description ? String(record.description) : '',
|
||||
color: String(record.color || '#8a9a7b'),
|
||||
link: record.link ? String(record.link) : '',
|
||||
categories: normalizeCategories(record.categories),
|
||||
published: Boolean(record.published),
|
||||
allDay: record.allDay !== false
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeCategories(value: unknown): string[] {
|
||||
if (Array.isArray(value)) {
|
||||
return [...new Set(value.map((item) => String(item).trim()).filter(Boolean))];
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
return [...new Set(value.split(',').map((item) => item.trim()).filter(Boolean))];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
export function categoriesToText(categories: string[] = []) {
|
||||
return categories.join(', ');
|
||||
}
|
||||
|
||||
export function extractCategories(events: CalendarEventRecord[]) {
|
||||
return [...new Set(events.flatMap((event) => event.categories || []))].sort((a, b) => a.localeCompare(b));
|
||||
}
|
||||
|
||||
export function eventMatchesCategories(event: CalendarEventRecord, categories: string[] = []) {
|
||||
if (!categories.length) return true;
|
||||
return event.categories?.some((category) => categories.includes(category));
|
||||
}
|
||||
|
||||
export function sortEvents(events: CalendarEventRecord[]) {
|
||||
return [...events].sort((a, b) => {
|
||||
const startA = parseEventDate(a.start)?.getTime() ?? 0;
|
||||
const startB = parseEventDate(b.start)?.getTime() ?? 0;
|
||||
return startA - startB || a.name.localeCompare(b.name);
|
||||
});
|
||||
}
|
||||
|
||||
export function formatEventDateRange(event: CalendarEventRecord) {
|
||||
const start = parseEventDate(event.start);
|
||||
const end = parseEventDate(event.end);
|
||||
if (!start) return '';
|
||||
const formatter = new Intl.DateTimeFormat(undefined, { month: 'short', day: 'numeric' });
|
||||
if (!end || dateKey(start) === dateKey(end)) return formatter.format(start);
|
||||
return `${formatter.format(start)} – ${formatter.format(end)}`;
|
||||
}
|
||||
|
||||
export function normalizeLink(link?: string) {
|
||||
const value = String(link || '').trim();
|
||||
if (!value) return '';
|
||||
if (value.startsWith('/') || value.startsWith('#') || value.startsWith('mailto:') || value.startsWith('tel:')) return value;
|
||||
if (/^https?:\/\//i.test(value)) return value;
|
||||
return `/${value.replace(/^\/+/, '')}`;
|
||||
}
|
||||
|
||||
export function isExternalLink(link?: string) {
|
||||
return /^https?:\/\//i.test(String(link || ''));
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import type { ContentBlock, PageRecord } from '$lib/types';
|
||||
import type { CalendarEventRecord, ContentBlock } from '$lib/types';
|
||||
|
||||
/**
|
||||
* The portable export format.
|
||||
|
|
@ -17,6 +17,7 @@ export type SiteExport = {
|
|||
key: string;
|
||||
data: Record<string, unknown>;
|
||||
}[];
|
||||
events?: Omit<CalendarEventRecord, 'id'>[];
|
||||
/** Maps original PocketBase file URLs → base64 data-URI */
|
||||
images: Record<string, string>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ export type BlockType =
|
|||
| 'timeline'
|
||||
| 'hero'
|
||||
| 'button'
|
||||
| 'spacer';
|
||||
| 'spacer'
|
||||
| 'testimonials'
|
||||
| 'upcoming_calendar';
|
||||
|
||||
export type BlockBackground = {
|
||||
type: 'none' | 'color' | 'image';
|
||||
|
|
@ -36,6 +38,24 @@ export type PageRecord = {
|
|||
published: boolean;
|
||||
};
|
||||
|
||||
export type CalendarEventRecord = {
|
||||
id: string;
|
||||
name: string;
|
||||
start: string;
|
||||
end?: string;
|
||||
description?: string;
|
||||
color: string;
|
||||
link?: string;
|
||||
categories: string[];
|
||||
published: boolean;
|
||||
allDay: boolean;
|
||||
};
|
||||
|
||||
export type UpcomingCalendarBlockData = {
|
||||
title?: string;
|
||||
categories?: string[];
|
||||
};
|
||||
|
||||
export type HeaderGlobal = {
|
||||
logo: { url: string; alt: string };
|
||||
navLinks: { label: string; href: string }[];
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { error } from '@sveltejs/kit';
|
||||
import { defaultHeader } from '$lib/types';
|
||||
import { defaultHeader, type CalendarEventRecord } from '$lib/types';
|
||||
import { eventOverlapsRange, getUpcomingCalendarRange, hasUpcomingCalendarBlock, normalizeEvent } from '$lib/calendar';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ locals }) => {
|
||||
|
|
@ -16,7 +17,16 @@ export const load: PageServerLoad = async ({ locals }) => {
|
|||
const page = await locals.pb
|
||||
.collection('pages')
|
||||
.getFirstListItem(`slug = "${homeSlug}" && published = true`);
|
||||
return { page };
|
||||
let calendarEvents: CalendarEventRecord[] = [];
|
||||
if (hasUpcomingCalendarBlock(page.blocks || [])) {
|
||||
const range = getUpcomingCalendarRange();
|
||||
const events = await locals.pb.collection('events').getFullList({
|
||||
filter: `published = true && start <= "${range.end.toISOString()}"`,
|
||||
sort: 'start'
|
||||
});
|
||||
calendarEvents = events.map((event) => normalizeEvent(event)).filter((event) => eventOverlapsRange(event, range.start, range.end));
|
||||
}
|
||||
return { page, calendarEvents };
|
||||
} catch {
|
||||
throw error(404, 'Page not found');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,4 +8,4 @@
|
|||
<title>{data.page.title}</title>
|
||||
</svelte:head>
|
||||
|
||||
<BlockRenderer blocks={data.page.blocks || []} />
|
||||
<BlockRenderer blocks={data.page.blocks || []} calendarEvents={data.calendarEvents || []} />
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
import { error } from '@sveltejs/kit';
|
||||
import { eventOverlapsRange, getUpcomingCalendarRange, hasUpcomingCalendarBlock, normalizeEvent } from '$lib/calendar';
|
||||
import type { CalendarEventRecord } from '$lib/types';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, locals }) => {
|
||||
|
|
@ -6,7 +8,16 @@ export const load: PageServerLoad = async ({ params, locals }) => {
|
|||
const page = await locals.pb
|
||||
.collection('pages')
|
||||
.getFirstListItem(`slug = "${params.slug}" && published = true`);
|
||||
return { page };
|
||||
let calendarEvents: CalendarEventRecord[] = [];
|
||||
if (hasUpcomingCalendarBlock(page.blocks || [])) {
|
||||
const range = getUpcomingCalendarRange();
|
||||
const events = await locals.pb.collection('events').getFullList({
|
||||
filter: `published = true && start <= "${range.end.toISOString()}"`,
|
||||
sort: 'start'
|
||||
});
|
||||
calendarEvents = events.map((event) => normalizeEvent(event)).filter((event) => eventOverlapsRange(event, range.start, range.end));
|
||||
}
|
||||
return { page, calendarEvents };
|
||||
} catch {
|
||||
throw error(404, 'Page not found');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,4 +7,4 @@
|
|||
<title>{data.page.title}</title>
|
||||
</svelte:head>
|
||||
|
||||
<BlockRenderer blocks={data.page.blocks || []} />
|
||||
<BlockRenderer blocks={data.page.blocks || []} calendarEvents={data.calendarEvents || []} />
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
throw new Error(err?.message || `Import failed (${res.status})`);
|
||||
}
|
||||
const result = await res.json();
|
||||
const msg = `Imported ${result.pagesImported} page(s), ${result.globalsImported} global(s), ${result.imagesUploaded} image(s).`;
|
||||
const msg = `Imported ${result.pagesImported} page(s), ${result.globalsImported} global(s), ${result.eventsImported || 0} event(s), ${result.imagesUploaded} image(s).`;
|
||||
importStatus = { ok: true, message: result.errors?.length ? msg + ` ${result.errors.length} error(s).` : msg };
|
||||
setTimeout(() => location.reload(), 1500);
|
||||
} catch (e) {
|
||||
|
|
@ -58,6 +58,7 @@
|
|||
</div>
|
||||
<div class="flex-none gap-2">
|
||||
<a class="btn btn-ghost" href="/admin/pages">Pages</a>
|
||||
<a class="btn btn-ghost" href="/admin/calendar">Calendar</a>
|
||||
<a class="btn btn-ghost" href="/admin/globals">Globals</a>
|
||||
<div class="dropdown dropdown-end">
|
||||
<button class="btn btn-ghost btn-sm" type="button" tabindex="0">
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import {
|
|||
urlToKey,
|
||||
type SiteExport
|
||||
} from '$lib/exportImport';
|
||||
import { normalizeEvent } from '$lib/calendar';
|
||||
|
||||
export const GET: RequestHandler = async ({ locals }) => {
|
||||
// Fetch all pages
|
||||
|
|
@ -14,6 +15,7 @@ export const GET: RequestHandler = async ({ locals }) => {
|
|||
|
||||
// Fetch all globals
|
||||
const globals = await locals.pb.collection('globals').getFullList();
|
||||
const events = await locals.pb.collection('events').getFullList({ sort: 'start' }).catch(() => []);
|
||||
|
||||
// Collect all image URLs from pages and globals
|
||||
const allUrls = new Set<string>();
|
||||
|
|
@ -55,11 +57,27 @@ export const GET: RequestHandler = async ({ locals }) => {
|
|||
data: replaceUrlsWithKeys(g.data, urlToKeyMap) as Record<string, unknown>
|
||||
}));
|
||||
|
||||
const exportEvents = events.map((record) => {
|
||||
const event = normalizeEvent(record);
|
||||
return {
|
||||
name: event.name,
|
||||
start: event.start,
|
||||
end: event.end,
|
||||
description: event.description,
|
||||
color: event.color,
|
||||
link: event.link,
|
||||
categories: event.categories,
|
||||
published: event.published,
|
||||
allDay: event.allDay
|
||||
};
|
||||
});
|
||||
|
||||
const exportData: SiteExport = {
|
||||
version: 1,
|
||||
exportedAt: new Date().toISOString(),
|
||||
pages: exportPages,
|
||||
globals: exportGlobals,
|
||||
events: exportEvents,
|
||||
images
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
|||
imagesUploaded: 0,
|
||||
pagesImported: 0,
|
||||
globalsImported: 0,
|
||||
eventsImported: 0,
|
||||
errors: [] as string[]
|
||||
};
|
||||
|
||||
|
|
@ -102,5 +103,38 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
|||
}
|
||||
}
|
||||
|
||||
// 4. Import events
|
||||
for (const event of body.events || []) {
|
||||
try {
|
||||
let existing;
|
||||
try {
|
||||
existing = await locals.pb.collection('events').getFirstListItem(`name = "${event.name}" && start = "${event.start}"`);
|
||||
} catch {
|
||||
existing = null;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
name: event.name,
|
||||
start: event.start,
|
||||
end: event.end || null,
|
||||
description: event.description || '',
|
||||
color: event.color || '#8a9a7b',
|
||||
link: event.link || '',
|
||||
categories: event.categories || [],
|
||||
published: Boolean(event.published),
|
||||
allDay: event.allDay !== false
|
||||
};
|
||||
|
||||
if (existing) {
|
||||
await locals.pb.collection('events').update(existing.id, payload);
|
||||
} else {
|
||||
await locals.pb.collection('events').create(payload);
|
||||
}
|
||||
results.eventsImported++;
|
||||
} catch (e) {
|
||||
results.errors.push(`Failed to import event "${event.name}": ${e instanceof Error ? e.message : String(e)}`);
|
||||
}
|
||||
}
|
||||
|
||||
return json(results);
|
||||
};
|
||||
54
app/src/routes/admin/calendar/+page.server.ts
Normal file
54
app/src/routes/admin/calendar/+page.server.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { fail } from '@sveltejs/kit';
|
||||
import { dateInputToPocketBase, normalizeCategories, normalizeEvent } from '$lib/calendar';
|
||||
import type { Actions, PageServerLoad } from './$types';
|
||||
|
||||
function eventPayload(data: FormData) {
|
||||
const allDay = String(data.get('allDay')) === 'true';
|
||||
const start = String(data.get('start') || '').trim();
|
||||
const end = String(data.get('end') || '').trim();
|
||||
const name = String(data.get('name') || '').trim();
|
||||
|
||||
return {
|
||||
name,
|
||||
start: dateInputToPocketBase(start, allDay),
|
||||
end: end ? dateInputToPocketBase(end, allDay) : null,
|
||||
description: String(data.get('description') || '').trim(),
|
||||
color: String(data.get('color') || '#8a9a7b').trim(),
|
||||
link: String(data.get('link') || '').trim(),
|
||||
categories: normalizeCategories(String(data.get('categories') || '')),
|
||||
published: String(data.get('published')) === 'true',
|
||||
allDay
|
||||
};
|
||||
}
|
||||
|
||||
export const load: PageServerLoad = async ({ locals }) => {
|
||||
const records = await locals.pb.collection('events').getFullList({ sort: 'start' }).catch(() => []);
|
||||
const events = records.map((record) => normalizeEvent(record));
|
||||
return { events };
|
||||
};
|
||||
|
||||
export const actions: Actions = {
|
||||
create: async ({ request, locals }) => {
|
||||
const data = await request.formData();
|
||||
const payload = eventPayload(data);
|
||||
if (!payload.name || !payload.start) return fail(400, { message: 'Name and start are required.' });
|
||||
await locals.pb.collection('events').create(payload);
|
||||
return { ok: true };
|
||||
},
|
||||
update: async ({ request, locals }) => {
|
||||
const data = await request.formData();
|
||||
const id = String(data.get('id') || '');
|
||||
const payload = eventPayload(data);
|
||||
if (!id) return fail(400, { message: 'Event id is required.' });
|
||||
if (!payload.name || !payload.start) return fail(400, { message: 'Name and start are required.' });
|
||||
await locals.pb.collection('events').update(id, payload);
|
||||
return { ok: true };
|
||||
},
|
||||
delete: async ({ request, locals }) => {
|
||||
const data = await request.formData();
|
||||
const id = String(data.get('id') || '');
|
||||
if (!id) return fail(400, { message: 'Event id is required.' });
|
||||
await locals.pb.collection('events').delete(id);
|
||||
return { ok: true };
|
||||
}
|
||||
};
|
||||
236
app/src/routes/admin/calendar/+page.svelte
Normal file
236
app/src/routes/admin/calendar/+page.svelte
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
<script lang="ts">
|
||||
import { addMonths, createCalendarMonth, eventOverlapsDay, formatEventDateRange, sortEvents, toDateInput, toDatetimeInput } from '$lib/calendar';
|
||||
import type { CalendarEventRecord } from '$lib/types';
|
||||
|
||||
let { data, form } = $props();
|
||||
let events = $derived(sortEvents(data.events || []));
|
||||
let viewDate = $state(new Date(new Date().getFullYear(), new Date().getMonth(), 1));
|
||||
let showEditor = $state(false);
|
||||
let draft = $state<CalendarEventRecord>({
|
||||
id: '',
|
||||
name: '',
|
||||
start: toDateInput(new Date().toISOString()),
|
||||
end: '',
|
||||
description: '',
|
||||
color: '#8a9a7b',
|
||||
link: '',
|
||||
categories: [],
|
||||
published: false,
|
||||
allDay: true
|
||||
});
|
||||
let categoryText = $state('');
|
||||
|
||||
const weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
let month = $derived(createCalendarMonth(viewDate));
|
||||
let action = $derived(draft.id ? '?/update' : '?/create');
|
||||
let dateInputType = $derived(draft.allDay ? 'date' : 'datetime-local');
|
||||
let startValue = $derived(draft.allDay ? toDateInput(draft.start) : toDatetimeInput(draft.start));
|
||||
let endValue = $derived(draft.allDay ? toDateInput(draft.end) : toDatetimeInput(draft.end));
|
||||
let allCategories = $derived([...new Set(events.flatMap((event) => event.categories || []))].sort((a, b) => a.localeCompare(b)));
|
||||
|
||||
function eventsForDay(date: Date) {
|
||||
return events.filter((event) => eventOverlapsDay(event, date));
|
||||
}
|
||||
|
||||
function emptyDraft(start = toDateInput(new Date().toISOString())): CalendarEventRecord {
|
||||
return {
|
||||
id: '',
|
||||
name: '',
|
||||
start,
|
||||
end: '',
|
||||
description: '',
|
||||
color: '#8a9a7b',
|
||||
link: '',
|
||||
categories: [],
|
||||
published: false,
|
||||
allDay: true
|
||||
};
|
||||
}
|
||||
|
||||
function createEvent(start?: string) {
|
||||
draft = emptyDraft(start);
|
||||
categoryText = '';
|
||||
showEditor = true;
|
||||
}
|
||||
|
||||
function editEvent(event: CalendarEventRecord) {
|
||||
draft = structuredClone(event);
|
||||
categoryText = event.categories.join(', ');
|
||||
showEditor = true;
|
||||
}
|
||||
|
||||
function previousMonth() {
|
||||
viewDate = addMonths(viewDate, -1);
|
||||
}
|
||||
|
||||
function nextMonth() {
|
||||
viewDate = addMonths(viewDate, 1);
|
||||
}
|
||||
|
||||
function addCategory(category: string) {
|
||||
if (!category || draft.categories.includes(category)) return;
|
||||
draft = { ...draft, categories: [...draft.categories, category] };
|
||||
categoryText = draft.categories.join(', ');
|
||||
}
|
||||
|
||||
function removeCategory(category: string) {
|
||||
draft = { ...draft, categories: draft.categories.filter((item) => item !== category) };
|
||||
categoryText = draft.categories.join(', ');
|
||||
}
|
||||
|
||||
function syncCategoryText(value: string) {
|
||||
categoryText = value;
|
||||
draft = { ...draft, categories: value.split(',').map((item) => item.trim()).filter(Boolean) };
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head><title>Calendar | CMS</title></svelte:head>
|
||||
|
||||
<div class="space-y-6">
|
||||
<div class="flex flex-col justify-between gap-4 md:flex-row md:items-end">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold">Calendar</h1>
|
||||
<p class="text-base-content/60">Create and manage events used by Upcoming Calendar blocks.</p>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="button" onclick={() => createEvent()}>Create event</button>
|
||||
</div>
|
||||
|
||||
{#if form?.message}<div class="alert alert-error">{form.message}</div>{/if}
|
||||
|
||||
<div class="rounded-box bg-base-100 p-5 shadow">
|
||||
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
<button class="btn btn-outline btn-sm" type="button" onclick={previousMonth}>← Previous</button>
|
||||
<h2 class="text-2xl font-bold">{month.label}</h2>
|
||||
<button class="btn btn-outline btn-sm" type="button" onclick={nextMonth}>Next →</button>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-7 gap-2 text-center text-xs font-semibold uppercase text-base-content/50">
|
||||
{#each weekdays as weekday}<div>{weekday}</div>{/each}
|
||||
</div>
|
||||
<div class="mt-2 grid grid-cols-7 gap-2">
|
||||
{#each month.days as day}
|
||||
<div class="min-h-32 rounded-box border border-base-300 bg-base-200/60 p-2" class:opacity-40={!day.inMonth}>
|
||||
<button class="btn btn-ghost btn-xs mb-1" class:btn-primary={day.isToday} type="button" onclick={() => createEvent(day.dateKey)}>{day.dayNumber}</button>
|
||||
<div class="space-y-1">
|
||||
{#each eventsForDay(day.date) as event}
|
||||
<button class="w-full rounded-lg px-2 py-1 text-left text-xs font-semibold text-white shadow" style={`background:${event.color || '#8a9a7b'}`} type="button" onclick={() => editEvent(event)}>
|
||||
<span class="block truncate">{event.name}</span>
|
||||
<span class="block truncate text-[0.65rem] opacity-80">{formatEventDateRange(event)}</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-box bg-base-100 p-5 shadow">
|
||||
<h2 class="mb-4 text-xl font-bold">All events</h2>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table">
|
||||
<thead><tr><th>Name</th><th>Date</th><th>Categories</th><th>Status</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{#each events as event}
|
||||
<tr>
|
||||
<td><span class="mr-2 inline-block h-3 w-3 rounded-full" style={`background:${event.color}`}></span>{event.name}</td>
|
||||
<td>{formatEventDateRange(event)}</td>
|
||||
<td>{event.categories.join(', ')}</td>
|
||||
<td><span class="badge" class:badge-success={event.published}>{event.published ? 'Published' : 'Draft'}</span></td>
|
||||
<td class="text-right"><button class="btn btn-sm" type="button" onclick={() => editEvent(event)}>Edit</button></td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if showEditor}
|
||||
<div class="fixed inset-0 z-50 bg-black/50 p-4">
|
||||
<div class="mx-auto max-h-full max-w-2xl overflow-auto rounded-box bg-base-100 p-6 shadow-xl">
|
||||
<div class="mb-4 flex items-center justify-between gap-3">
|
||||
<h2 class="text-2xl font-bold">{draft.id ? 'Edit event' : 'Create event'}</h2>
|
||||
<button class="btn btn-ghost btn-sm" type="button" onclick={() => (showEditor = false)}>Close</button>
|
||||
</div>
|
||||
|
||||
<form method="POST" action={action} class="space-y-4">
|
||||
<input type="hidden" name="id" value={draft.id} />
|
||||
<input type="hidden" name="allDay" value={draft.allDay ? 'true' : 'false'} />
|
||||
<input type="hidden" name="published" value={draft.published ? 'true' : 'false'} />
|
||||
<input type="hidden" name="categories" value={categoryText} />
|
||||
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Name</span></div>
|
||||
<input class="input input-bordered w-full" name="name" required bind:value={draft.name} />
|
||||
</label>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Start</span></div>
|
||||
<input class="input input-bordered w-full" type={dateInputType} name="start" required value={startValue} oninput={(e) => (draft = { ...draft, start: e.currentTarget.value })} />
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">End optional</span></div>
|
||||
<input class="input input-bordered w-full" type={dateInputType} name="end" value={endValue} oninput={(e) => (draft = { ...draft, end: e.currentTarget.value })} />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<label class="label cursor-pointer justify-start gap-3">
|
||||
<input class="toggle toggle-primary" type="checkbox" bind:checked={draft.allDay} />
|
||||
<span class="label-text">All-day event</span>
|
||||
</label>
|
||||
<label class="label cursor-pointer justify-start gap-3">
|
||||
<input class="toggle toggle-success" type="checkbox" bind:checked={draft.published} />
|
||||
<span class="label-text">Published</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Description</span></div>
|
||||
<textarea class="textarea textarea-bordered min-h-28" name="description" bind:value={draft.description}></textarea>
|
||||
</label>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Color</span></div>
|
||||
<div class="flex gap-2">
|
||||
<input class="input input-bordered h-12 w-14 p-1" type="color" bind:value={draft.color} />
|
||||
<input class="input input-bordered flex-1" name="color" bind:value={draft.color} />
|
||||
</div>
|
||||
</label>
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Link optional</span></div>
|
||||
<input class="input input-bordered w-full" name="link" placeholder="/page or https://..." bind:value={draft.link} />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="rounded-box border border-base-300 p-4">
|
||||
<label class="form-control w-full">
|
||||
<div class="label"><span class="label-text">Categories comma-separated</span></div>
|
||||
<input class="input input-bordered w-full" value={categoryText} oninput={(e) => syncCategoryText(e.currentTarget.value)} />
|
||||
</label>
|
||||
{#if allCategories.length}
|
||||
<div class="mt-3 flex flex-wrap gap-2">
|
||||
{#each allCategories as category}
|
||||
<button class="btn btn-xs" class:btn-primary={draft.categories.includes(category)} type="button" onclick={() => draft.categories.includes(category) ? removeCategory(category) : addCategory(category)}>{category}</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="flex justify-between gap-2 pt-2">
|
||||
{#if draft.id}
|
||||
<button class="btn btn-error" type="submit" formaction="?/delete">Delete</button>
|
||||
{:else}
|
||||
<span></span>
|
||||
{/if}
|
||||
<div class="flex gap-2">
|
||||
<button class="btn" type="button" onclick={() => (showEditor = false)}>Cancel</button>
|
||||
<button class="btn btn-primary" type="submit">Save event</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
import { fail, redirect } from '@sveltejs/kit';
|
||||
import { extractCategories, normalizeEvent } from '$lib/calendar';
|
||||
import type { Actions, PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, locals }) => {
|
||||
const page = await locals.pb.collection('pages').getFirstListItem(`slug = "${params.slug}"`);
|
||||
return { page };
|
||||
const events = await locals.pb.collection('events').getFullList({ sort: 'start' }).catch(() => []);
|
||||
const eventCategories = extractCategories(events.map((event) => normalizeEvent(event)));
|
||||
return { page, eventCategories };
|
||||
};
|
||||
|
||||
export const actions: Actions = {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@
|
|||
</div>
|
||||
<BlockList {blocks} {selectedId} onSelect={(id) => (selectedId = id)} onDelete={deleteBlock} onMove={moveBlock} />
|
||||
</aside>
|
||||
<BlockEditor block={selectedBlock} onChange={updateBlock} />
|
||||
<BlockEditor block={selectedBlock} eventCategories={data.eventCategories || []} onChange={updateBlock} />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
|
|
|||
132
pb_schema.json
132
pb_schema.json
|
|
@ -158,5 +158,137 @@
|
|||
],
|
||||
"indexes": [],
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"id": "pbc_events0001",
|
||||
"name": "events",
|
||||
"type": "base",
|
||||
"system": false,
|
||||
"listRule": "published = true || @request.auth.id != ''",
|
||||
"viewRule": "published = true || @request.auth.id != ''",
|
||||
"createRule": "@request.auth.id != ''",
|
||||
"updateRule": "@request.auth.id != ''",
|
||||
"deleteRule": "@request.auth.id != ''",
|
||||
"fields": [
|
||||
{
|
||||
"id": "text_eventname",
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"system": false,
|
||||
"required": true,
|
||||
"presentable": true,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"min": null,
|
||||
"max": 180,
|
||||
"pattern": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "date_eventstart",
|
||||
"name": "start",
|
||||
"type": "date",
|
||||
"system": false,
|
||||
"required": true,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"min": "",
|
||||
"max": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "date_eventend",
|
||||
"name": "end",
|
||||
"type": "date",
|
||||
"system": false,
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"min": "",
|
||||
"max": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "text_eventdesc",
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"system": false,
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"min": null,
|
||||
"max": 2000,
|
||||
"pattern": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "text_eventcolor",
|
||||
"name": "color",
|
||||
"type": "text",
|
||||
"system": false,
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"min": null,
|
||||
"max": 32,
|
||||
"pattern": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "url_eventlink",
|
||||
"name": "link",
|
||||
"type": "text",
|
||||
"system": false,
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"min": null,
|
||||
"max": 500,
|
||||
"pattern": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "json_eventcats",
|
||||
"name": "categories",
|
||||
"type": "json",
|
||||
"system": false,
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {
|
||||
"maxSize": 200000
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "bool_eventpub",
|
||||
"name": "published",
|
||||
"type": "bool",
|
||||
"system": false,
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"id": "bool_eventallday",
|
||||
"name": "allDay",
|
||||
"type": "bool",
|
||||
"system": false,
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {}
|
||||
}
|
||||
],
|
||||
"indexes": [
|
||||
"CREATE INDEX `idx_events_start` ON `events` (`start`)",
|
||||
"CREATE INDEX `idx_events_published` ON `events` (`published`)"
|
||||
],
|
||||
"options": {}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue