From 154ff43dfd5108f6dbd10a5dfed93080f6880e4f Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Sun, 19 May 2024 20:40:49 -0400 Subject: [PATCH] add replicache and supabase backend --- app/[doc_id]/page.tsx | 45 +- backend/index.ts | 5 - components/TextEditor.tsx | 20 + drizzle.config.ts | 11 + drizzle/relations.ts | 13 + drizzle/schema.ts | 36 + package-lock.json | 6201 ++++++------------- package.json | 9 +- replicache/attributes.ts | 10 + replicache/index.tsx | 127 + replicache/mutations.ts | 35 + replicache/pull.ts | 64 + replicache/push.ts | 102 + replicache/utils.ts | 36 + supabase/database.types.ts | 523 ++ supabase/migrations/20240519231512_init.sql | 202 + wrangler.toml | 16 - 17 files changed, 3133 insertions(+), 4322 deletions(-) delete mode 100644 backend/index.ts create mode 100644 components/TextEditor.tsx create mode 100644 drizzle.config.ts create mode 100644 drizzle/relations.ts create mode 100644 drizzle/schema.ts create mode 100644 replicache/attributes.ts create mode 100644 replicache/index.tsx create mode 100644 replicache/mutations.ts create mode 100644 replicache/pull.ts create mode 100644 replicache/push.ts create mode 100644 replicache/utils.ts create mode 100644 supabase/database.types.ts create mode 100644 supabase/migrations/20240519231512_init.sql delete mode 100644 wrangler.toml diff --git a/app/[doc_id]/page.tsx b/app/[doc_id]/page.tsx index 809e6e6b..ec1b6795 100644 --- a/app/[doc_id]/page.tsx +++ b/app/[doc_id]/page.tsx @@ -1,3 +1,46 @@ +"use client"; +import { ReplicacheProvider, useEntity, useReplicache } from "../../replicache"; +import { TextEditor } from "../../components/TextEditor"; + export default function DocumentPage(props: { params: { doc_id: string } }) { - return
doc_id: {props.params.doc_id}
; + return ( + +
doc_id: {props.params.doc_id}
+ +
+ ); +} + +function AllFacts(props: { entityID: string }) { + let blocks = useEntity(props.entityID, "block/card"); + + return ( +
+ {blocks?.map((f) => { + let data = f.data as { type: "reference"; value: string }; + return ; + })} +
+ ); +} + +function Block(props: { entityID: string }) { + let content = useEntity(props.entityID, "card/content"); + let children = useEntity(props.entityID, "block/card"); + let rep = useReplicache(); + return ( +
+ { + await rep.rep?.mutate.assertFact({ + entity: props.entityID, + attribute: "card/content", + data: { type: "text", value }, + }); + }} + /> + {children?.map((c) => )} +
+ ); } diff --git a/backend/index.ts b/backend/index.ts deleted file mode 100644 index 310c2f10..00000000 --- a/backend/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default { - async fetch() { - return new Response("hello world"); - }, -}; diff --git a/components/TextEditor.tsx b/components/TextEditor.tsx new file mode 100644 index 00000000..fbd6756e --- /dev/null +++ b/components/TextEditor.tsx @@ -0,0 +1,20 @@ +import { useEffect, useState } from "react"; + +export function TextEditor(props: { + value?: string; + onChange: (value: string) => Promise; +}) { + let [intermediateState, setIntermediateState] = useState(props.value); + useEffect(() => { + setIntermediateState(props.value as string); + }, [props.value]); + return ( +