Skip to content

Commit

Permalink
Fix loading of new and public calendars
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDaniel committed Sep 15, 2024
1 parent 6e0930d commit 3cc0e9b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions frontend/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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') || '{}'));
Expand All @@ -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);
}
}
}
Expand All @@ -72,6 +72,7 @@
if (response.status === 200) {
calendarData = await response.json();
saveCalendars(calendarData);
loadCalendars();
}
loading = false;
} catch (error) {
Expand Down Expand Up @@ -146,7 +147,6 @@
if (createdCalendars.length === 1) {
const { token } = createdCalendars[0];
await fetchData(token);
loadCalendars();
goto(`?id=${token}`);
}
} catch (error) {
Expand Down

0 comments on commit 3cc0e9b

Please sign in to comment.