Database structure update

This commit is contained in:
Eric van der Vlist 2023-02-21 21:11:03 +01:00
parent fdb1da322c
commit a8c88d1303
2 changed files with 42 additions and 29 deletions

View File

@ -1,29 +1,30 @@
import { createForm } from "@felte/solid"; import { createForm } from '@felte/solid';
import { Component, createUniqueId } from "solid-js"; import { Component, createUniqueId } from 'solid-js';
import { TextField, Button } from "@kobalte/core"; import { TextField, Button } from '@kobalte/core';
import "./style.css"; import './style.css';
import { createServerAction$ } from "solid-start/server"; import { createServerAction$ } from 'solid-start/server';
import PouchDb from "pouchdb"; import PouchDb from 'pouchdb';
import { v4 as uuid } from "uuid"; import { v4 as uuid } from 'uuid';
interface Props {} interface Props {}
const Invitation: Component<Props> = (props) => { const Invitation: Component<Props> = (props) => {
const [saving, save] = createServerAction$(async (values: any) => { const [saving, save] = createServerAction$(async (values: any) => {
const db = new PouchDb(".db"); const db = new PouchDb('.db');
const id = `invitation/${uuid()}`; const id = `invitation/${uuid()}`;
await db.put({ await db.put({
_id: id, _id: id,
type: "invitation", type: 'invitation',
doc: values, ...values,
date: new Date().toISOString(),
}); });
return id; return id;
}); });
const submitHandler = (values: any, context: any) => { const submitHandler = (values: any, context: any) => {
console.log({ console.log({
caller: "Invitation / submitHandler", caller: 'Invitation / submitHandler',
props, props,
values, values,
context, context,
@ -35,13 +36,25 @@ const Invitation: Component<Props> = (props) => {
return ( return (
<form use:form> <form use:form>
<TextField.Root>
<TextField.Label>Mail address</TextField.Label>
<TextField.Input
type='mail'
name='mail'
required={true}
placeholder='Email address'
/>
<TextField.ErrorMessage>
Please provide a valid URL
</TextField.ErrorMessage>
</TextField.Root>
<TextField.Root> <TextField.Root>
<TextField.Label>Database</TextField.Label> <TextField.Label>Database</TextField.Label>
<TextField.Input <TextField.Input
type="url" type='url'
name="database" name='database'
required={true} required={true}
placeholder="Database URL" placeholder='Database URL'
/> />
<TextField.ErrorMessage> <TextField.ErrorMessage>
Please provide a valid URL Please provide a valid URL
@ -50,17 +63,17 @@ const Invitation: Component<Props> = (props) => {
<TextField.Root> <TextField.Root>
<TextField.Label>Password</TextField.Label> <TextField.Label>Password</TextField.Label>
<TextField.Input <TextField.Input
type="text" type='text'
name="password" name='password'
required={true} required={true}
placeholder="Password" placeholder='Password'
autocomplete="off" autocomplete='off'
/> />
<TextField.ErrorMessage> <TextField.ErrorMessage>
Please provide a valid password Please provide a valid password
</TextField.ErrorMessage> </TextField.ErrorMessage>
</TextField.Root> </TextField.Root>
<Button.Root type="submit">Create</Button.Root> <Button.Root type='submit'>Create</Button.Root>
</form> </form>
); );
}; };

View File

@ -1,19 +1,19 @@
import PouchDb from "pouchdb"; import PouchDb from 'pouchdb';
import { Component, createEffect, For } from "solid-js"; import { Component, createEffect, For } from 'solid-js';
import { createServerAction$ } from "solid-start/server"; import { createServerAction$ } from 'solid-start/server';
interface Props {} interface Props {}
const Invitations: Component<Props> = (props) => { const Invitations: Component<Props> = (props) => {
const [invitations, getInvitations] = createServerAction$( const [invitations, getInvitations] = createServerAction$(
async (values: any) => { async (values: any) => {
const db = new PouchDb(".db"); const db = new PouchDb('.db');
const results = await db.allDocs({ const results = await db.allDocs({
include_docs: true, include_docs: true,
startkey: "invitation/", startkey: 'invitation/',
endkey: "invitation/\ufff0", endkey: 'invitation/\ufff0',
}); });
console.log({ caller: "Invitations / serverAction", results }); console.log({ caller: 'Invitations / serverAction', results });
return results.rows; return results.rows;
} }
); );
@ -22,7 +22,7 @@ const Invitations: Component<Props> = (props) => {
createEffect(() => { createEffect(() => {
console.log({ console.log({
caller: "Invitations", caller: 'Invitations',
invitations: invitations.result, invitations: invitations.result,
}); });
}); });
@ -32,10 +32,10 @@ const Invitations: Component<Props> = (props) => {
<For each={invitations.result}> <For each={invitations.result}>
{(invitation: any) => { {(invitation: any) => {
console.log({ console.log({
caller: "Invitations / loop", caller: 'Invitations / loop',
invitations: invitation, invitations: invitation,
}); });
return <li>{invitation.id}</li>; return <li>{invitation.doc.mail}</li>;
}} }}
</For> </For>
</ul> </ul>