From 3cc0e9bc3237e678c202d4015ae958d087a734b7 Mon Sep 17 00:00:00 2001 From: Aleks-Daniel Jakimenko-Aleksejev Date: Sun, 15 Sep 2024 21:30:43 +0300 Subject: [PATCH] Fix loading of new and public calendars --- frontend/src/routes/+page.svelte | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte index 34756f4..e0c7244 100644 --- a/frontend/src/routes/+page.svelte +++ b/frontend/src/routes/+page.svelte @@ -5,7 +5,6 @@ import { page } from '$app/stores'; import { goto } from '$app/navigation'; import { browser } from '$app/environment'; - import { onMount } from 'svelte'; const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:3000'; @@ -48,8 +47,6 @@ } } - onMount(() => loadCalendars()); - function saveCalendars(calendarData: CalendarData) { const calendars = Object.fromEntries(availableCalendars.map((c) => [c.value, c])); Object.assign(calendars, JSON.parse(localStorage.getItem('calendars') || '{}')); @@ -60,8 +57,11 @@ function loadCalendars() { if (localStorage.getItem('calendars')) { availableCalendars = Object.values(JSON.parse(localStorage.getItem('calendars') || '{}')); - } else { - availableCalendars = defaultCalendars; + } + for (const calendar of defaultCalendars) { + if (!availableCalendars.find((c) => c.value === calendar.value)) { + availableCalendars.push(calendar); + } } } @@ -72,6 +72,7 @@ if (response.status === 200) { calendarData = await response.json(); saveCalendars(calendarData); + loadCalendars(); } loading = false; } catch (error) { @@ -146,7 +147,6 @@ if (createdCalendars.length === 1) { const { token } = createdCalendars[0]; await fetchData(token); - loadCalendars(); goto(`?id=${token}`); } } catch (error) {