From 0239f869854ee85dbfab2342f1deb3acb8bdc264 Mon Sep 17 00:00:00 2001 From: Barf-Vader <47476490+Barf-Vader@users.noreply.github.com> Date: Mon, 16 Jun 2025 22:40:54 +0100 Subject: [PATCH 1/2] feat: delete --- src/lib/index.ts | 2 +- src/routes/space/[id]/+page.svelte | 16 +++++++++++++++- src/routes/space/[id]/edit/+page.svelte | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/lib/index.ts b/src/lib/index.ts index d8d8d52..af78d11 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -85,7 +85,7 @@ export function haversineDistance( return radius * 2 * Math.asin(Math.sqrt(e1)); } -export function collectTimings(study_space_hours: Table<"study_space_hours">[]) { +export function collectTimings(study_space_hours: Partial>[]) { // Collect all timing entries const timingsPerDay: Record[]> = { 0: [], diff --git a/src/routes/space/[id]/+page.svelte b/src/routes/space/[id]/+page.svelte index 0bf4b78..798979b 100644 --- a/src/routes/space/[id]/+page.svelte +++ b/src/routes/space/[id]/+page.svelte @@ -87,6 +87,12 @@ isFavourite = true; } } + + async function deleteSpace() { + if (!confirm("Are you sure you want to delete this study space?")) return; + await supabase.from("study_spaces").delete().eq("id", space.id); + window.location.href = "/"; + } @@ -192,7 +198,10 @@
{#if adminMode} - +
+ + +
{:else} {/if} @@ -355,4 +364,9 @@ width: 3.75rem; height: 3.75rem; } + .buttonContainer { + display: grid; + grid-template-columns: repeat(2, 1fr); + gap: 0.5rem; + } diff --git a/src/routes/space/[id]/edit/+page.svelte b/src/routes/space/[id]/edit/+page.svelte index a7832a7..f6008d8 100644 --- a/src/routes/space/[id]/edit/+page.svelte +++ b/src/routes/space/[id]/edit/+page.svelte @@ -14,7 +14,8 @@ volumeTags, gmapsLoader, daysOfWeek, - timeToMins + timeToMins, + collectTimings } from "$lib"; import { onMount } from "svelte"; import type { Json } from "$lib/database.js"; @@ -61,6 +62,19 @@ function checkTimings() { let cannotExist = [] as number[]; + let hasAllDays = Object.values(collectTimings(studySpaceData.opening_times)).every( + (item) => !(Array.isArray(item) && item.length === 0) + ); + + if ( + (allDays.closes_at === "" || allDays.opens_at === "") && + allDays.open_today_status === null && + !hasAllDays + ) { + alert(`No opening time provided for all other days.`); + return false; + } + const opensAtMinsAll = timeToMins(allDays.opens_at); const closesAtMinsAll = timeToMins(allDays.closes_at); if (opensAtMinsAll >= closesAtMinsAll) { @@ -200,6 +214,7 @@ // Nothing is provided if ( (allDays.closes_at != "" && allDays.opens_at != "") || + studySpaceData.opening_times.length === 7 || allDays.open_today_status != null ) { const { error: hoursErr } = await supabase -- 2.49.1 From 03bca1952792165e508ec46efeade552460b7eff Mon Sep 17 00:00:00 2001 From: Barf-Vader <47476490+Barf-Vader@users.noreply.github.com> Date: Mon, 16 Jun 2025 23:25:42 +0100 Subject: [PATCH 2/2] fix: Types --- src/lib/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/index.ts b/src/lib/index.ts index af78d11..93b15dc 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -85,9 +85,17 @@ export function haversineDistance( return radius * 2 * Math.asin(Math.sqrt(e1)); } -export function collectTimings(study_space_hours: Partial>[]) { +export function collectTimings( + study_space_hours: Omit< + Table<"study_space_hours">, + "id" | "created_at" | "updated_at" | "study_space_id" + >[] +) { // Collect all timing entries - const timingsPerDay: Record[]> = { + const timingsPerDay: Record< + number, + Omit, "id" | "created_at" | "updated_at" | "study_space_id">[] + > = { 0: [], 1: [], 2: [], -- 2.49.1