From 2d25466f93316805060df304d1dd04d499480a3c Mon Sep 17 00:00:00 2001 From: Brian Ginsburg <7957636+bgins@users.noreply.github.com> Date: Tue, 2 Aug 2022 10:57:36 -0700 Subject: [PATCH] Add initialization error toasts (#24) * Add error, success, info, and warning styles * Add Toast component * Add initialization error toast * Add device store and toast placement * Set device on window resize events Co-authored-by: Brian Ginsburg Co-authored-by: Jess Martin --- package-lock.json | 14 ++++---- package.json | 2 +- src/components/auth/Register.svelte | 4 +-- src/components/icons/CheckThinIcon.svelte | 17 ++++++++++ src/components/icons/XThinIcon.svelte | 14 ++++++++ src/components/notifications/Toast.svelte | 36 ++++++++++++++++++++ src/lib/device.ts | 3 ++ src/lib/session.ts | 16 +++++++-- src/routes/__layout.svelte | 40 +++++++++++++++++++++-- src/stores.ts | 5 ++- tailwind.config.cjs | 8 +++++ 11 files changed, 143 insertions(+), 16 deletions(-) create mode 100644 src/components/icons/CheckThinIcon.svelte create mode 100644 src/components/icons/XThinIcon.svelte create mode 100644 src/components/notifications/Toast.svelte create mode 100644 src/lib/device.ts diff --git a/package-lock.json b/package-lock.json index 57cb645..9061dd8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "svelte-elemetary-template", "version": "0.1.0", "dependencies": { - "webnative": "0.33.0-alpha-3" + "webnative": "0.33.0-alpha-4" }, "devDependencies": { "@sveltejs/adapter-static": "1.0.0-next.36", @@ -4679,9 +4679,9 @@ } }, "node_modules/webnative": { - "version": "0.33.0-alpha-3", - "resolved": "https://registry.npmjs.org/webnative/-/webnative-0.33.0-alpha-3.tgz", - "integrity": "sha512-fx7ZNk1eKdt88RHG90fKg99xhBKsPIizOEgggr0HYrbM9G9O4vXGabt48QQF6K9pTuZmrrSW/RyqR/bxCHRc6A==", + "version": "0.33.0-alpha-4", + "resolved": "https://registry.npmjs.org/webnative/-/webnative-0.33.0-alpha-4.tgz", + "integrity": "sha512-P7TH9uwh31IS8PjHaRD74wQRjmVu1qiHnMwkjr2x0FiUixUwbrkvumL4qergeCIKQj//ZrrnkCZhebJ1efaylQ==", "dependencies": { "@ipld/dag-cbor": "^7.0.0", "@ipld/dag-pb": "^2.1.15", @@ -8069,9 +8069,9 @@ "peer": true }, "webnative": { - "version": "0.33.0-alpha-3", - "resolved": "https://registry.npmjs.org/webnative/-/webnative-0.33.0-alpha-3.tgz", - "integrity": "sha512-fx7ZNk1eKdt88RHG90fKg99xhBKsPIizOEgggr0HYrbM9G9O4vXGabt48QQF6K9pTuZmrrSW/RyqR/bxCHRc6A==", + "version": "0.33.0-alpha-4", + "resolved": "https://registry.npmjs.org/webnative/-/webnative-0.33.0-alpha-4.tgz", + "integrity": "sha512-P7TH9uwh31IS8PjHaRD74wQRjmVu1qiHnMwkjr2x0FiUixUwbrkvumL4qergeCIKQj//ZrrnkCZhebJ1efaylQ==", "requires": { "@ipld/dag-cbor": "^7.0.0", "@ipld/dag-pb": "^2.1.15", diff --git a/package.json b/package.json index c1dc764..01f722d 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,6 @@ ] }, "dependencies": { - "webnative": "0.33.0-alpha-3" + "webnative": "0.33.0-alpha-4" } } diff --git a/src/components/auth/Register.svelte b/src/components/auth/Register.svelte index 35f2fb2..78f98af 100644 --- a/src/components/auth/Register.svelte +++ b/src/components/auth/Register.svelte @@ -88,12 +88,12 @@ /> {/if} {#if !(username.length === 0) && usernameAvailable && usernameValid && !checkingUsername} - + {/if} {#if !(username.length === 0) && !checkingUsername && !(usernameAvailable && usernameValid)} - + {/if} diff --git a/src/components/icons/CheckThinIcon.svelte b/src/components/icons/CheckThinIcon.svelte new file mode 100644 index 0000000..192f11a --- /dev/null +++ b/src/components/icons/CheckThinIcon.svelte @@ -0,0 +1,17 @@ + + + + + + + diff --git a/src/components/icons/XThinIcon.svelte b/src/components/icons/XThinIcon.svelte new file mode 100644 index 0000000..aad0960 --- /dev/null +++ b/src/components/icons/XThinIcon.svelte @@ -0,0 +1,14 @@ + + + diff --git a/src/components/notifications/Toast.svelte b/src/components/notifications/Toast.svelte new file mode 100644 index 0000000..74160b1 --- /dev/null +++ b/src/components/notifications/Toast.svelte @@ -0,0 +1,36 @@ + + +
+
+
+ {#if kind === 'success'} + + {:else if kind === 'error'} + + {/if} + {message} +
+
+
diff --git a/src/lib/device.ts b/src/lib/device.ts new file mode 100644 index 0000000..9eb8590 --- /dev/null +++ b/src/lib/device.ts @@ -0,0 +1,3 @@ +export type Device = { + isMobile: boolean +} \ No newline at end of file diff --git a/src/lib/session.ts b/src/lib/session.ts index fccfd38..6ceacb3 100644 --- a/src/lib/session.ts +++ b/src/lib/session.ts @@ -2,5 +2,17 @@ export type Session = { username: string authed: boolean loading: boolean - error?: 'Insecure Context' | 'Unsupported Browser' -} \ No newline at end of file + error?: SessionError +} + +type SessionError = 'Insecure Context' | 'Unsupported Browser' + +export const errorToMessage = (error: SessionError): string => { + switch (error) { + case 'Insecure Context': + return 'This application requires a secure context (HTTPS)' + + case 'Unsupported Browser': + return 'Your browser does not support this application' + } +} diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index 7bba9ba..1e172d1 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -1,29 +1,63 @@ + +
+ {#if session.error} + + {/if} +
diff --git a/src/stores.ts b/src/stores.ts index 2a8a5d9..43af42f 100644 --- a/src/stores.ts +++ b/src/stores.ts @@ -3,6 +3,7 @@ import type { Writable } from 'svelte/store' import type FileSystem from 'webnative/fs/index' import { loadTheme } from '$lib/theme' +import type { Device } from '$lib/device' import type { Session } from '$lib/session' import type { Theme } from '$lib/theme' @@ -14,4 +15,6 @@ export const sessionStore: Writable = writable({ loading: true }) -export const filesystemStore: Writable = writable(null) \ No newline at end of file +export const filesystemStore: Writable = writable(null) + +export const deviceStore: Writable = writable({ isMobile: true }) \ No newline at end of file diff --git a/tailwind.config.cjs b/tailwind.config.cjs index daf39a1..90d1da2 100644 --- a/tailwind.config.cjs +++ b/tailwind.config.cjs @@ -11,6 +11,10 @@ module.exports = { secondary: "#30aadd", accent: "#00ffc6", neutral: "#282828", + info: "#bfdbfe", + success: "#bbf7d0", + warning: "#fdba74", + error: "#fecaca", "base-content": "#ffffff", "base-100": "#111111", "--rounded-box": "16px", @@ -24,6 +28,10 @@ module.exports = { secondary: "#30aadd", accent: "#00ffc6", neutral: "#e5e5e5", + info: "#bfdbfe", + success: "#bbf7d0", + warning: "#fdba74", + error: "#fecaca", "base-content": "#000000", "base-100": "#ffffff", "--rounded-box": "16px",