diff --git a/src/lib/components/containers/Window.svelte b/src/lib/components/containers/Window.svelte index bfca808..f2a9c72 100644 --- a/src/lib/components/containers/Window.svelte +++ b/src/lib/components/containers/Window.svelte @@ -2,6 +2,6 @@ let { children } = $props(); -
+
{@render children()}
diff --git a/src/lib/components/forms/frequency/FrequencyForm.svelte b/src/lib/components/forms/frequency/FrequencyForm.svelte new file mode 100644 index 0000000..5ad0eb3 --- /dev/null +++ b/src/lib/components/forms/frequency/FrequencyForm.svelte @@ -0,0 +1,62 @@ + + +
+ {#if frequency.id || form?.id} + + {/if} + +
+ + +
+ +
+ + +
+ + +
diff --git a/src/lib/components/ui/AffirmationList/AffirmationList.svelte b/src/lib/components/ui/AffirmationList/AffirmationList.svelte index 098a0fa..dbe6e49 100644 --- a/src/lib/components/ui/AffirmationList/AffirmationList.svelte +++ b/src/lib/components/ui/AffirmationList/AffirmationList.svelte @@ -122,7 +122,7 @@ {#each frequencies as frequency} diff --git a/src/lib/components/ui/FrequencyList/FrequencyList.svelte b/src/lib/components/ui/FrequencyList/FrequencyList.svelte new file mode 100644 index 0000000..2aaac69 --- /dev/null +++ b/src/lib/components/ui/FrequencyList/FrequencyList.svelte @@ -0,0 +1,176 @@ + + +
+
+ + + {#if hasActiveFilters} + + {/if} + + + {filteredAndSorted().length} of {frequencies.length} + +
+ +
+ + + + + + + + + + + {#each filteredAndSorted() as frequency} + + + + + + + {:else} + + + + {/each} + +
+ + + + + +
{frequency.name}{frequency.value} Hz + {frequency._count?.affirmations ?? 0} + + + Edit + +
+ {#if hasActiveFilters} + No frequencies match your filters + {:else} + No frequencies yet + {/if} +
+
+
diff --git a/src/routes/(protected)/+layout.svelte b/src/routes/(protected)/+layout.svelte index cf0c5f7..c014ecd 100644 --- a/src/routes/(protected)/+layout.svelte +++ b/src/routes/(protected)/+layout.svelte @@ -5,8 +5,6 @@ This layout also acts as a sort of 'gatekeeper' in that it is also the authorization layer. --> -
-
+
+

Affirmations

+
+ + {#if data.frequencies.length > 0} + + {:else} +
+
+

No frequencies yet

+

Click "Create +" to add your first one

+
+
+ {/if} +
+ +{#if showModal} +
+
+
+
+

Create New Frequency

+ +
+ + {#if form?.error} +
+ {form.error} +
+ {/if} + + +
+
+
+{/if} diff --git a/src/routes/(protected)/frequencies/[id]/+page.server.ts b/src/routes/(protected)/frequencies/[id]/+page.server.ts new file mode 100644 index 0000000..9e1cebd --- /dev/null +++ b/src/routes/(protected)/frequencies/[id]/+page.server.ts @@ -0,0 +1,50 @@ +import type { PageServerLoad } from './$types'; +import { prisma } from '$lib/db'; +import { error, fail, type Actions, type RequestEvent, type ServerLoadEvent } from '@sveltejs/kit'; + +export const load: PageServerLoad = async ({ params }: ServerLoadEvent) => { + const frequency = await prisma.solfeggioFrequency.findUnique({ + where: { id: Number(params.id) } + }); + + if (!frequency) { + throw error(404, 'not found'); + } + + return { frequency }; +}; + +export const actions: Actions = { + update: async ({ request }: RequestEvent) => { + const form = await request.formData(); + const id = Number(form.get('id')); + const name = form.get('name') as string; + const value = Number(form.get('value')); + + if (!name) { + return fail(400, { error: 'Name is required!', ...Object.fromEntries(form) }); + } + + if (!value || value <= 0) { + return fail(400, { + error: 'A valid frequency value is required!', + ...Object.fromEntries(form) + }); + } + + try { + const updatedFrequency = await prisma.solfeggioFrequency.update({ + where: { id }, + data: { name, value } + }); + + return { success: true, updatedFrequency }; + } catch (err) { + console.log(err); + return fail(500, { + error: 'An unknown error has occurred. Please try again later. Your changes have not been saved.', + ...Object.fromEntries(form) + }); + } + } +}; diff --git a/src/routes/(protected)/frequencies/[id]/+page.svelte b/src/routes/(protected)/frequencies/[id]/+page.svelte new file mode 100644 index 0000000..40247fb --- /dev/null +++ b/src/routes/(protected)/frequencies/[id]/+page.svelte @@ -0,0 +1,47 @@ + + +
+ Back to Frequencies + + {#if form?.error} +
+ {form.error} +
+ {/if} + + {#if form?.success} +
+ Frequency updated successfully! You will be redirected in {remainder} seconds. +
+ {/if} + +
+ +
+