From ed351011d56f5b7e69c27c05f98e666017b103c4 Mon Sep 17 00:00:00 2001 From: Samuel Andert Date: Tue, 1 Aug 2023 14:21:43 +0200 Subject: [PATCH] Cleaning Up xStateFlows and abstracting generic interfaces --- src/lib/components/Recipies/feedback.md | 0 .../Recipies/machines/authMachine.ts | 88 +++++++++ src/lib/components/Recipies/oForm.svelte | 168 ++++++++++++++++++ src/lib/components/Recipies/oRecipe.svelte | 45 +++++ src/lib/components/examples/Form.svelte | 22 +-- src/lib/components/examples/feedback.md | 1 - src/lib/components/maschines/SignIn.svelte | 50 ++++++ src/lib/components/maschines/signInMachine.ts | 35 ++++ src/lib/types/HelloUserSchema.ts | 7 + src/routes/dashboard/+page.svelte | 6 + 10 files changed, 403 insertions(+), 19 deletions(-) create mode 100644 src/lib/components/Recipies/feedback.md create mode 100644 src/lib/components/Recipies/machines/authMachine.ts create mode 100644 src/lib/components/Recipies/oForm.svelte create mode 100644 src/lib/components/Recipies/oRecipe.svelte delete mode 100644 src/lib/components/examples/feedback.md create mode 100644 src/lib/components/maschines/SignIn.svelte create mode 100644 src/lib/components/maschines/signInMachine.ts create mode 100644 src/lib/types/HelloUserSchema.ts create mode 100644 src/routes/dashboard/+page.svelte diff --git a/src/lib/components/Recipies/feedback.md b/src/lib/components/Recipies/feedback.md new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/components/Recipies/machines/authMachine.ts b/src/lib/components/Recipies/machines/authMachine.ts new file mode 100644 index 0000000..ab95a35 --- /dev/null +++ b/src/lib/components/Recipies/machines/authMachine.ts @@ -0,0 +1,88 @@ +// src/lib/components/Recipies/machines/authMachine.ts +import { createMachine } from 'xstate'; + +export const authMachine = createMachine( + { + id: 'auth', + initial: 'notAuthenticated', + states: { + notAuthenticated: { + meta: { + title: 'Welcome!', + buttons: [ + { + type: 'START', + label: 'Login', + disabled: false + } + ] + }, + on: { + START: { + target: 'signIn', + actions: 'startSignIn' + } + } + }, + signIn: { + meta: { + title: 'Sign In', + composite: { + id: 'signInForm', + component: 'oForm' + }, + buttons: [ + { + type: 'BACK', + label: 'Back', + disabled: true + }, + { + type: 'NEXT', + label: 'Authenticate', + disabled: false + } + ] + }, + on: { + BACK: 'notAuthenticated', + NEXT: { + target: 'authenticated', + actions: 'authenticate' + } + } + }, + authenticated: { + meta: { + title: 'Authenticated', + buttons: [ + { + type: 'LOGOUT', + label: 'Logout', + disabled: false + } + ] + }, + on: { + LOGOUT: { + target: 'notAuthenticated', + actions: 'logout' + } + } + } + } + }, + { + actions: { + startSignIn: (context, event) => { + console.log('Starting sign in process...'); + }, + authenticate: (context, event) => { + console.log('Authenticating...'); + }, + logout: (context, event) => { + console.log('Logging out...'); + } + } + } +) \ No newline at end of file diff --git a/src/lib/components/Recipies/oForm.svelte b/src/lib/components/Recipies/oForm.svelte new file mode 100644 index 0000000..0e14700 --- /dev/null +++ b/src/lib/components/Recipies/oForm.svelte @@ -0,0 +1,168 @@ + + +{#if isStoreLoaded} +
+ {#if $successMessage} + + {:else} +
+ {#each fields as field} +
+ {#if $errors[field]} + {$errors[field]} + {:else} + + {/if} + + {#if field === 'about'} +