From e2795ff257d901131f35877ae68c91947b2c6c64 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Wed, 11 Jun 2025 17:53:55 +0100 Subject: [PATCH] feat: edit page --- src/lib/components/Carousel.svelte | 19 ++- src/lib/components/inputs/Images.svelte | 11 +- src/routes/+page.svelte | 2 +- src/routes/space/[id]/edit/+page.server.ts | 46 ++++++ src/routes/space/{ => [id]/edit}/+page.svelte | 137 ++++++++++++++---- 5 files changed, 182 insertions(+), 33 deletions(-) create mode 100644 src/routes/space/[id]/edit/+page.server.ts rename src/routes/space/{ => [id]/edit}/+page.svelte (74%) diff --git a/src/lib/components/Carousel.svelte b/src/lib/components/Carousel.svelte index 4eb0777..be70eeb 100644 --- a/src/lib/components/Carousel.svelte +++ b/src/lib/components/Carousel.svelte @@ -4,20 +4,27 @@ import { onMount } from "svelte"; interface Props { + scrollPosition?: number; urls?: string[]; ondelete?: (idx: number) => void; } - const { urls = [], ondelete }: Props = $props(); + let { scrollPosition = $bindable(0), urls = [], ondelete }: Props = $props(); let carousel = $state(); - let scrollPosition = $state(0); + let currentPosition = $state(0); let scrollWidth = $state(0); let clientWidth = $state(1); function updateScroll() { - scrollPosition = carousel?.scrollLeft || 0; + currentPosition = carousel?.scrollLeft || 0; scrollWidth = carousel?.scrollWidth || 0; clientWidth = carousel?.clientWidth || 1; } + $effect(() => { + carousel?.scrollTo({ + left: scrollPosition * clientWidth, + behavior: "smooth" + }); + }); onMount(() => { const id = setInterval(() => { if (carousel) { @@ -41,7 +48,7 @@ {/each} - {#if scrollPosition > clientWidth / 2} + {#if currentPosition > clientWidth / 2} {/if} - {#if scrollPosition < scrollWidth - clientWidth * 1.5} + {#if currentPosition < scrollWidth - clientWidth * 1.5} {/if} - {Math.round(scrollPosition / clientWidth) + 1} / {urls.length} + {Math.round(currentPosition / clientWidth) + 1} / {urls.length} diff --git a/src/lib/components/inputs/Images.svelte b/src/lib/components/inputs/Images.svelte index 123cdf3..6940dd0 100644 --- a/src/lib/components/inputs/Images.svelte +++ b/src/lib/components/inputs/Images.svelte @@ -8,9 +8,17 @@ minHeight?: string; files?: FileList; required?: boolean; + scrollPosition?: number; } - let { name, height, minHeight, files = $bindable(), ...rest }: Props = $props(); + let { + name, + height, + minHeight, + files = $bindable(), + scrollPosition = $bindable(), + ...rest + }: Props = $props();