aboutsummaryrefslogtreecommitdiffstats
path: root/web/stores/favourites.ts
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2025-08-14 18:07:12 +0100
committerLeonardo Bishop <me@leonardobishop.com>2025-08-14 18:07:12 +0100
commit4697556cac819c47d068819b9fc9c3b4ea84e279 (patch)
treeb832d8fc6b643a8b9d0eeca35c1268e1649da731 /web/stores/favourites.ts
parentdd49c9205bb04844b686b9c3396c40eb49d25826 (diff)
Merge confplanner-web and replace fiber with native net/http
Diffstat (limited to 'web/stores/favourites.ts')
-rw-r--r--web/stores/favourites.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/web/stores/favourites.ts b/web/stores/favourites.ts
new file mode 100644
index 0000000..2bf7257
--- /dev/null
+++ b/web/stores/favourites.ts
@@ -0,0 +1,43 @@
+import { defineStore } from "pinia";
+import { type Event } from "./schedule";
+
+interface Favourite {
+ id: number;
+ eventGuid?: string;
+ eventId?: number;
+}
+
+export const useFavouritesStore = defineStore('favourites', () => {
+ const favourites = ref([] as Favourite[])
+ const status = ref('idle' as 'idle' | 'pending')
+
+ const setFavourites = (newFavourites: Favourite[]) => {
+ favourites.value = newFavourites
+ }
+ const addFavourite = (favourite: Favourite) => {
+ favourites.value.push(favourite)
+ }
+ const removeFavourite = (favourite: { eventGuid?: string, eventId?: number }) => {
+ if (favourite.eventGuid) {
+ favourites.value = favourites.value.filter(f => f.eventGuid !== favourite.eventGuid)
+ }
+ if (favourite.eventId) {
+ favourites.value = favourites.value.filter(f => f.eventId !== favourite.eventId)
+ }
+ }
+ const isFavourite = (event: Event) => {
+ return favourites.value.some(f => {
+ if (f.eventGuid) {
+ return f.eventGuid === event.guid
+ } else if (f.eventId) {
+ return f.eventId === event.id
+ }
+ })
+ }
+
+ const setStatus = (newStatus: 'idle' | 'pending') => {
+ status.value = newStatus
+ }
+
+ return {favourites, status, setFavourites, addFavourite, removeFavourite, isFavourite, setStatus}
+})