From a8c88d130386ab9dd7be8e3068e80e0c5705ec12 Mon Sep 17 00:00:00 2001 From: evlist Date: Tue, 21 Feb 2023 21:11:03 +0100 Subject: [PATCH] Database structure update --- src/components/invitation/Invitation.tsx | 51 ++++++++++++++-------- src/components/invitations/Invitations.tsx | 20 ++++----- 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/components/invitation/Invitation.tsx b/src/components/invitation/Invitation.tsx index c7b0b73..39bb62d 100644 --- a/src/components/invitation/Invitation.tsx +++ b/src/components/invitation/Invitation.tsx @@ -1,29 +1,30 @@ -import { createForm } from "@felte/solid"; -import { Component, createUniqueId } from "solid-js"; -import { TextField, Button } from "@kobalte/core"; +import { createForm } from '@felte/solid'; +import { Component, createUniqueId } from 'solid-js'; +import { TextField, Button } from '@kobalte/core'; -import "./style.css"; -import { createServerAction$ } from "solid-start/server"; -import PouchDb from "pouchdb"; -import { v4 as uuid } from "uuid"; +import './style.css'; +import { createServerAction$ } from 'solid-start/server'; +import PouchDb from 'pouchdb'; +import { v4 as uuid } from 'uuid'; interface Props {} const Invitation: Component = (props) => { const [saving, save] = createServerAction$(async (values: any) => { - const db = new PouchDb(".db"); + const db = new PouchDb('.db'); const id = `invitation/${uuid()}`; await db.put({ _id: id, - type: "invitation", - doc: values, + type: 'invitation', + ...values, + date: new Date().toISOString(), }); return id; }); const submitHandler = (values: any, context: any) => { console.log({ - caller: "Invitation / submitHandler", + caller: 'Invitation / submitHandler', props, values, context, @@ -35,13 +36,25 @@ const Invitation: Component = (props) => { return (
+ + Mail address + + + Please provide a valid URL + + Database Please provide a valid URL @@ -50,17 +63,17 @@ const Invitation: Component = (props) => { Password Please provide a valid password - Create + Create ); }; diff --git a/src/components/invitations/Invitations.tsx b/src/components/invitations/Invitations.tsx index 4d09801..90a25ba 100644 --- a/src/components/invitations/Invitations.tsx +++ b/src/components/invitations/Invitations.tsx @@ -1,19 +1,19 @@ -import PouchDb from "pouchdb"; -import { Component, createEffect, For } from "solid-js"; -import { createServerAction$ } from "solid-start/server"; +import PouchDb from 'pouchdb'; +import { Component, createEffect, For } from 'solid-js'; +import { createServerAction$ } from 'solid-start/server'; interface Props {} const Invitations: Component = (props) => { const [invitations, getInvitations] = createServerAction$( async (values: any) => { - const db = new PouchDb(".db"); + const db = new PouchDb('.db'); const results = await db.allDocs({ include_docs: true, - startkey: "invitation/", - endkey: "invitation/\ufff0", + startkey: 'invitation/', + endkey: 'invitation/\ufff0', }); - console.log({ caller: "Invitations / serverAction", results }); + console.log({ caller: 'Invitations / serverAction', results }); return results.rows; } ); @@ -22,7 +22,7 @@ const Invitations: Component = (props) => { createEffect(() => { console.log({ - caller: "Invitations", + caller: 'Invitations', invitations: invitations.result, }); }); @@ -32,10 +32,10 @@ const Invitations: Component = (props) => { {(invitation: any) => { console.log({ - caller: "Invitations / loop", + caller: 'Invitations / loop', invitations: invitation, }); - return
  • {invitation.id}
  • ; + return
  • {invitation.doc.mail}
  • ; }}