= existingTokensString
- ? JSON.parse(existingTokensString)
- : {};
- existingTokens[eventID] = token;
- localStorage.setItem(this.localStorageKey, JSON.stringify(existingTokens));
- }
-
- getToken(eventID: number): string {
- const tokens = this.tokens();
- if (!tokens) return '';
- return tokens[eventID] || '';
- }
-}
-
-export const hostTokenStorage = new TokenStorage('host-tokens');
-export const voterTokenStorage = new TokenStorage('voter-tokens');
diff --git a/src/lib/voting-system/components/ranked-choice/RankedChoiceVoting.svelte b/src/lib/voting-system/components/ranked-choice/RankedChoiceVoting.svelte
index 686e9c7..eaa2d69 100644
--- a/src/lib/voting-system/components/ranked-choice/RankedChoiceVoting.svelte
+++ b/src/lib/voting-system/components/ranked-choice/RankedChoiceVoting.svelte
@@ -1,7 +1,7 @@
Drag your preferred options to the top.
diff --git a/src/lib/voting-system/components/star/StarVoting.svelte b/src/lib/voting-system/components/star/StarVoting.svelte
index df1cb1e..7fef5c8 100644
--- a/src/lib/voting-system/components/star/StarVoting.svelte
+++ b/src/lib/voting-system/components/star/StarVoting.svelte
@@ -4,15 +4,12 @@
import { RefreshOutline } from 'flowbite-svelte-icons';
import type { StarSubmission } from './types';
import type { VotingComponentProps } from '$lib/voting-system/types';
- import { getContext } from 'svelte';
+ import { getContext, onMount } from 'svelte';
let { event }: VotingComponentProps = $props();
let submissionContext: SubmissionContext = getContext('ballot-data');
- let ratings: StarSubmission = $state(event.choices.map((choice) => ({ choice, rating: 0 })));
-
- submissionContext.submission = ratings;
- submissionContext.submissionIsValid = true;
+ let ratings: StarSubmission = $state([]);
function onRatingClick(choice: string, rating: number) {
const selectedChoice = ratings.find((r) => r.choice === choice);
@@ -21,6 +18,12 @@
}
submissionContext.submission = ratings;
}
+
+ onMount(() => {
+ ratings = event.choices.map((choice) => ({ choice, rating: 0 }));
+ submissionContext.submission = ratings;
+ submissionContext.submissionIsValid = true;
+ });
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 8882385..84a3020 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -5,9 +5,12 @@
import { defaultTheme } from '$lib/themes';
import { InfoAPI } from '$lib/api/info';
import { onMount } from 'svelte';
+ import StorageProvider from '$lib/storage/StorageProvider.svelte';
let { children } = $props();
+ let loaded = $state(false);
+
onMount(async () => {
console.log(
`App Version: ${import.meta.env.VITE_APP_VERSION}`,
@@ -21,9 +24,17 @@
-
-
- {@render children?.()}
-
-
+ (loaded = true)}>
+ {#if !loaded}
+
+ {:else}
+
+
+ {@render children?.()}
+
+
+ {/if}
+
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 4d07e9e..257c2d9 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -3,8 +3,10 @@
import { EventsAPI } from '$lib/api/events';
import { Heading, Input, Label, Button, Select } from 'flowbite-svelte';
import { resolve } from '$app/paths';
- import { hostTokenStorage } from '$lib/token-util';
import votingSystems from '$lib/voting-system/config';
+ import { getStorageContext } from '$lib/storage/storage';
+
+ const storage = getStorageContext();
let eventName = $state('');
let dishes: string[] = $state([]);
@@ -41,7 +43,7 @@
electoral_system: votingSystem
});
- hostTokenStorage.saveToken(response.id, response.host_token);
+ storage.saveEvent(response.id, response.name, response.host_token);
await goto(resolve(`/event/${response.id}/host/invitation/`));
};
diff --git a/src/routes/event/[id=eventID]/ballot/[ballotID=eventID]/+layout.svelte b/src/routes/event/[id=eventID]/ballot/[ballotID=eventID]/+layout.svelte
index a38187a..8adfa00 100644
--- a/src/routes/event/[id=eventID]/ballot/[ballotID=eventID]/+layout.svelte
+++ b/src/routes/event/[id=eventID]/ballot/[ballotID=eventID]/+layout.svelte
@@ -1,9 +1,9 @@
Voting - {name}
@@ -26,7 +38,7 @@
Loading event data...
{:else if submitted}
{#if eventContext.event?.show_results === true}
-
+
{:else}
You have already submitted your vote. Thank you!
{/if}
@@ -34,7 +46,7 @@
{/if}
diff --git a/src/routes/event/[id=eventID]/host/+layout.svelte b/src/routes/event/[id=eventID]/host/+layout.svelte
index c00b660..3f3f78e 100644
--- a/src/routes/event/[id=eventID]/host/+layout.svelte
+++ b/src/routes/event/[id=eventID]/host/+layout.svelte
@@ -12,10 +12,12 @@
import { EventsAPI } from '$lib/api/events';
import { goto } from '$app/navigation';
import { resolve } from '$app/paths';
- import { hostTokenStorage } from '$lib/token-util';
+ import { getStorageContext } from '$lib/storage/storage';
let { children } = $props();
+ const storage = getStorageContext();
+
let activeUrl = $derived(page.url.pathname);
let eventID = $derived(Number(page.params.id));
let confirmationModalOpen = $state(false);
@@ -27,7 +29,8 @@
if (eventID === undefined) return;
const api = new EventsAPI();
- await api.closeEvent(eventID, hostTokenStorage.getToken(eventID));
+ const event = storage.getEvent(eventID);
+ await api.closeEvent(eventID, event.token);
goto(resolve(`/event/${eventID}/host/results/`));
};
@@ -35,9 +38,9 @@
onMount(async () => {
//Cannot use load function in layout, cannot access localStorage in load function
const api = new EventsAPI(fetch);
- const hostToken = hostTokenStorage.getToken(eventID);
- hostContext.event = await api.getEvent(eventID, hostToken);
- hostContext.ballots = await api.listBallots(eventID, hostToken);
+ const event = storage.getEvent(eventID);
+ hostContext.event = await api.getEvent(eventID, event.token);
+ hostContext.ballots = await api.listBallots(eventID, event.token);
});
diff --git a/src/routes/event/[id=eventID]/host/dashboard/+page.svelte b/src/routes/event/[id=eventID]/host/dashboard/+page.svelte
index 1e85eda..5d33474 100644
--- a/src/routes/event/[id=eventID]/host/dashboard/+page.svelte
+++ b/src/routes/event/[id=eventID]/host/dashboard/+page.svelte
@@ -1,13 +1,14 @@