From e6480a6945134e81a54cd23b71a9876850e76b8f Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Tue, 21 May 2024 15:28:29 -0400 Subject: [PATCH] add ordered references for blocks --- app/[doc_id]/page.tsx | 37 +++++-- components/TextBlock.tsx | 89 +++++++++++---- drizzle/schema.ts | 114 +++++++++++++++----- package-lock.json | 35 ++++++ package.json | 3 + replicache/attributes.ts | 2 +- replicache/clientMutationContext.ts | 53 +++++++++ replicache/index.tsx | 77 +++++-------- replicache/mutations.ts | 23 ++-- replicache/pull.ts | 20 +--- replicache/push.ts | 67 +----------- replicache/serverMutationContext.ts | 87 +++++++++++++++ replicache/utils.ts | 5 +- supabase/migrations/20240519231512_init.sql | 10 +- utils/elementId.ts | 5 + 15 files changed, 425 insertions(+), 202 deletions(-) create mode 100644 replicache/clientMutationContext.ts create mode 100644 replicache/serverMutationContext.ts create mode 100644 utils/elementId.ts diff --git a/app/[doc_id]/page.tsx b/app/[doc_id]/page.tsx index ba25b24b..1cab3b1f 100644 --- a/app/[doc_id]/page.tsx +++ b/app/[doc_id]/page.tsx @@ -1,6 +1,7 @@ "use client"; import { ReplicacheProvider, useEntity, useReplicache } from "../../replicache"; import { TextBlock } from "../../components/TextBlock"; +import { generateKeyBetween } from "fractional-indexing"; export default function DocumentPage(props: { params: { doc_id: string } }) { return ( @@ -14,11 +15,15 @@ export default function DocumentPage(props: { params: { doc_id: string } }) { function AddBlock(props: { entityID: string }) { let rep = useReplicache(); + let blocks = useEntity(props.entityID, "card/block")?.sort((a, b) => { + return a.data.position > b.data.position ? 1 : -1; + }); return (