Skip to content

Commit 3cc0e9b

Browse files
committed
Fix loading of new and public calendars
1 parent 6e0930d commit 3cc0e9b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

frontend/src/routes/+page.svelte

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import { page } from '$app/stores';
66
import { goto } from '$app/navigation';
77
import { browser } from '$app/environment';
8-
import { onMount } from 'svelte';
98
109
const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:3000';
1110
@@ -48,8 +47,6 @@
4847
}
4948
}
5049
51-
onMount(() => loadCalendars());
52-
5350
function saveCalendars(calendarData: CalendarData) {
5451
const calendars = Object.fromEntries(availableCalendars.map((c) => [c.value, c]));
5552
Object.assign(calendars, JSON.parse(localStorage.getItem('calendars') || '{}'));
@@ -60,8 +57,11 @@
6057
function loadCalendars() {
6158
if (localStorage.getItem('calendars')) {
6259
availableCalendars = Object.values(JSON.parse(localStorage.getItem('calendars') || '{}'));
63-
} else {
64-
availableCalendars = defaultCalendars;
60+
}
61+
for (const calendar of defaultCalendars) {
62+
if (!availableCalendars.find((c) => c.value === calendar.value)) {
63+
availableCalendars.push(calendar);
64+
}
6565
}
6666
}
6767
@@ -72,6 +72,7 @@
7272
if (response.status === 200) {
7373
calendarData = await response.json();
7474
saveCalendars(calendarData);
75+
loadCalendars();
7576
}
7677
loading = false;
7778
} catch (error) {
@@ -146,7 +147,6 @@
146147
if (createdCalendars.length === 1) {
147148
const { token } = createdCalendars[0];
148149
await fetchData(token);
149-
loadCalendars();
150150
goto(`?id=${token}`);
151151
}
152152
} catch (error) {

0 commit comments

Comments
 (0)