From 762393974ce749b6916b1df8f62366ccdc370db0 Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Mon, 26 Aug 2024 16:29:34 +0200 Subject: [PATCH] add some prototype data for the stores --- src/lib/stores/childrenData.js | 3 +++ src/lib/stores/contentStore.js | 26 ++++++++++++++++++++++++++ src/lib/stores/userData.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/lib/stores/childrenData.js create mode 100644 src/lib/stores/contentStore.js create mode 100644 src/lib/stores/userData.js diff --git a/src/lib/stores/childrenData.js b/src/lib/stores/childrenData.js new file mode 100644 index 00000000..74867cce --- /dev/null +++ b/src/lib/stores/childrenData.js @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/src/lib/stores/contentStore.js b/src/lib/stores/contentStore.js new file mode 100644 index 00000000..c38455c4 --- /dev/null +++ b/src/lib/stores/contentStore.js @@ -0,0 +1,26 @@ +import { writable } from 'svelte/store'; + +let contentlist = { + childrenSurveys: {}, + registrationForms: {} +}; + +const content = writable(contentlist); + +function addContent(type, key, content) { + content.update((contentlist) => { + contentlist[type][key] = content; + }); +} + +function removeContent(type, key) { + content.update((contentlist) => { + delete contentlist[type][key]; + }); +} + +function getContent(type, key) { + return content.value[type][key]; +} + +export { addContent, content, getContent, removeContent }; diff --git a/src/lib/stores/userData.js b/src/lib/stores/userData.js new file mode 100644 index 00000000..74818ea8 --- /dev/null +++ b/src/lib/stores/userData.js @@ -0,0 +1,34 @@ +// @ts-nocheck +import { writable } from 'svelte/store'; + +// FIXME: there must be something that is used to validate input - prototype for user data or so. +// this will eventually go into the backend, but for now it must reside here. + +let userlist = {}; + +const users = writable(userlist); + +async function addUser(userToken, userData) { + users.update((userlist) => { + if (userToken in userlist) { + // raise some error + } else { + userData['token'] = userToken; + userlist[userToken] = userData; + } + }); +} + +async function removeUser(userToken) { + users.update((userlist) => { + if (userToken in userlist) { + delete userlist[userToken]; + } + }); +} + +async function getUser(userToken) { + return users.value[userToken]; +} + +export { addUser, getUser, removeUser, users };