From 894358df20ad083d9830d5940d9d642a60794089 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Tue, 1 Mar 2022 13:16:20 +0100 Subject: [PATCH] Add toaster --- atsebayt/src/components/SurveyAdmin.svelte | 13 ++++-- .../src/components/SurveyQuestions.svelte | 11 ++++- atsebayt/src/components/Toaster.svelte | 18 ++++++++ atsebayt/src/routes/__layout.svelte | 4 ++ atsebayt/src/routes/surveys/[sid]/live.svelte | 5 ++- atsebayt/src/stores/toasts.js | 41 +++++++++++++++++++ 6 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 atsebayt/src/components/Toaster.svelte create mode 100644 atsebayt/src/stores/toasts.js diff --git a/atsebayt/src/components/SurveyAdmin.svelte b/atsebayt/src/components/SurveyAdmin.svelte index 0ab89cc..c0148e5 100644 --- a/atsebayt/src/components/SurveyAdmin.svelte +++ b/atsebayt/src/components/SurveyAdmin.svelte @@ -3,6 +3,7 @@ import { goto } from '$app/navigation'; import { getQuestions } from '../lib/questions'; + import { ToastsStore } from '../stores/toasts'; const dispatch = createEventDispatcher(); export let survey = null; @@ -11,7 +12,9 @@ survey.save().then((response) => { dispatch('saved'); }, (error) => { - console.log(error) + ToastsStore.addErrorToast({ + msg: error.errmsg, + }); }) } @@ -19,7 +22,9 @@ survey.delete().then((response) => { goto(`surveys`); }, (error) => { - console.log(error) + ToastsStore.addErrorToast({ + msg: error.errmsg, + }); }) } @@ -27,7 +32,9 @@ survey.duplicate().then((response) => { goto(`surveys/${response.id}`); }).catch((error) => { - console.log(error) + ToastsStore.addErrorToast({ + msg: error.errmsg, + }); }) } diff --git a/atsebayt/src/components/SurveyQuestions.svelte b/atsebayt/src/components/SurveyQuestions.svelte index a906418..1051e60 100644 --- a/atsebayt/src/components/SurveyQuestions.svelte +++ b/atsebayt/src/components/SurveyQuestions.svelte @@ -1,5 +1,6 @@ + +
+ {#each $ToastsStore.toasts as toast} + + {/each} +
diff --git a/atsebayt/src/routes/__layout.svelte b/atsebayt/src/routes/__layout.svelte index db852dc..df45380 100644 --- a/atsebayt/src/routes/__layout.svelte +++ b/atsebayt/src/routes/__layout.svelte @@ -42,6 +42,8 @@