From 9c1f42234755bc33b961fa0bfb6fc7553dfddd95 Mon Sep 17 00:00:00 2001 From: nichenqin Date: Tue, 19 Nov 2024 21:11:42 +0800 Subject: [PATCH] fix: fix calendar virtual list --- .../calendar-view-month-records.svelte | 44 ++++++++++------ .../select-calendar-field-form.svelte | 52 +++++++++++++------ 2 files changed, 65 insertions(+), 31 deletions(-) diff --git a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month-records.svelte b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month-records.svelte index 32bc2bb04..5f7bc5d66 100644 --- a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month-records.svelte +++ b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-month-records.svelte @@ -118,6 +118,7 @@ $: records = Records.fromJSON($t, rs) let virtualListEl: HTMLDivElement + let virtualItemEls: HTMLDivElement[] = [] $: color = $viewId ? $t.views.getViewById($viewId)?.color.into(undefined) : undefined @@ -127,6 +128,14 @@ estimateSize: () => 60, overscan: 5, }) + + $: items = $virtualizer.getVirtualItems() + + $: { + if (virtualItemEls.length) { + virtualItemEls.forEach((el) => $virtualizer.measureElement(el)) + } + }
@@ -146,21 +155,26 @@
{#if !records.isEmpty}
- {#each $virtualizer.getVirtualItems() as row (row.key)} -
- -
- {/each} +
+ {#each items as row, idx (row.key)} +
+ +
+ {/each} +
{#if $getRecords.hasNextPage} diff --git a/apps/frontend/src/lib/components/blocks/calendar-view/select-calendar-field-form.svelte b/apps/frontend/src/lib/components/blocks/calendar-view/select-calendar-field-form.svelte index 1ecd24ae1..56bb178bb 100644 --- a/apps/frontend/src/lib/components/blocks/calendar-view/select-calendar-field-form.svelte +++ b/apps/frontend/src/lib/components/blocks/calendar-view/select-calendar-field-form.svelte @@ -12,6 +12,7 @@ import { invalidate } from "$app/navigation" import { hasPermission } from "$lib/store/space-member.store" import { CircleCheckBigIcon } from "lucide-svelte" + import * as Form from "$lib/components/ui/form" export let readonly = false @@ -21,6 +22,8 @@ export let view: CalendarView + let calendar = view.calendar.unwrapOrElse(() => ({ field: undefined, timeScale: "month" })) + const form = superForm( defaults( { @@ -28,7 +31,10 @@ viewId: view.id.value, type: "calendar", name: view.name.value, - calendar: view.calendar.unwrapOrElse(() => ({ field: undefined })), + calendar: { + ...calendar, + timeScale: calendar.timeScale ?? "month", + }, }, zodClient(updateCalendarViewDTO), ), @@ -38,15 +44,21 @@ validators: zodClient(updateCalendarViewDTO), resetForm: false, invalidateAll: false, + onSubmit(event) { + validateForm({ update: true }) + }, onUpdate(event) { - if (!event.form.valid) return + if (!event.form.valid) { + console.log(event.form.errors, event.form.data) + return + } $updateViewMutation.mutate(event.form.data) }, }, ) - const { enhance, form: formData } = form + const { enhance, form: formData, validateForm } = form const updateViewMutation = createMutation({ mutationFn: trpc.table.view.update.mutate, @@ -62,19 +74,27 @@
- { - if ($formData.calendar) { - $formData.calendar.field = field - } else { - $formData.calendar = { field } - } - }} - filter={(f) => fields.map((f) => f.id.value).includes(f.id)} - /> + + + Calendar field + { + if ($formData.calendar) { + $formData.calendar.field = field + } else { + $formData.calendar = { field } + } + }} + filter={(f) => fields.map((f) => f.id.value).includes(f.id)} + /> + + + +