From d20d76a42db84ef2570fac239a5524545945500b Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Wed, 14 May 2025 19:54:18 -0400 Subject: [PATCH] make first block text in pub drafts --- actions/createNewLeaflet.ts | 48 ++++++++++++++++++++----------- actions/createPublicationDraft.ts | 6 +++- app/home/CreateNewButton.tsx | 10 +++++-- app/new/route.ts | 2 +- app/route.ts | 2 +- 5 files changed, 47 insertions(+), 21 deletions(-) diff --git a/actions/createNewLeaflet.ts b/actions/createNewLeaflet.ts index 934999df..ec825f78 100644 --- a/actions/createNewLeaflet.ts +++ b/actions/createNewLeaflet.ts @@ -17,10 +17,15 @@ import { v7 } from "uuid"; import { sql, eq, and } from "drizzle-orm"; import { cookies } from "next/headers"; -export async function createNewLeaflet( - pageType: "canvas" | "doc", - redirectUser: boolean, -) { +export async function createNewLeaflet({ + pageType, + redirectUser, + firstBlockType, +}: { + pageType: "canvas" | "doc"; + redirectUser: boolean; + firstBlockType?: "h1" | "text"; +}) { const client = postgres(process.env.DB_URL as string, { idle_timeout: 5 }); let auth_token = (await cookies()).get("auth_token")?.value; const db = drizzle(client); @@ -107,18 +112,29 @@ export async function createNewLeaflet( attribute: "card/block", data: sql`${{ type: "ordered-reference", value: blockEntity.id, position: "a0" }}::jsonb`, }, - { - id: v7(), - entity: blockEntity.id, - attribute: "block/type", - data: sql`${{ type: "block-type-union", value: "heading" }}::jsonb`, - }, - { - id: v7(), - entity: blockEntity.id, - attribute: "block/heading-level", - data: sql`${{ type: "number", value: 1 }}::jsonb`, - }, + ...(firstBlockType === "text" + ? [ + { + id: v7(), + entity: blockEntity.id, + attribute: "block/type", + data: sql`${{ type: "block-type-union", value: "text" }}::jsonb`, + }, + ] + : [ + { + id: v7(), + entity: blockEntity.id, + attribute: "block/type", + data: sql`${{ type: "block-type-union", value: "heading" }}::jsonb`, + }, + { + id: v7(), + entity: blockEntity.id, + attribute: "block/heading-level", + data: sql`${{ type: "number", value: 1 }}::jsonb`, + }, + ]), ]); } if (auth_token) { diff --git a/actions/createPublicationDraft.ts b/actions/createPublicationDraft.ts index bd640fcf..d8ffbfa2 100644 --- a/actions/createPublicationDraft.ts +++ b/actions/createPublicationDraft.ts @@ -6,7 +6,11 @@ import { supabaseServerClient } from "supabase/serverClient"; export async function createPublicationDraft(publication_uri: string) { let identity = await getIdentityData(); if (!identity || !identity.atp_did) return null; - let newLeaflet = await createNewLeaflet("doc", false); + let newLeaflet = await createNewLeaflet({ + pageType: "doc", + redirectUser: false, + firstBlockType: "text", + }); console.log( await supabaseServerClient .from("leaflets_in_publications") diff --git a/app/home/CreateNewButton.tsx b/app/home/CreateNewButton.tsx index f5f72bd9..58605c0e 100644 --- a/app/home/CreateNewButton.tsx +++ b/app/home/CreateNewButton.tsx @@ -62,7 +62,10 @@ export const CreateNewLeafletButton = (props: {}) => { > { - let id = await createNewLeaflet("doc", false); + let id = await createNewLeaflet({ + pageType: "doc", + redirectUser: false, + }); openNewLeaflet(id); }} > @@ -76,7 +79,10 @@ export const CreateNewLeafletButton = (props: {}) => { { - let id = await createNewLeaflet("canvas", false); + let id = await createNewLeaflet({ + pageType: "canvas", + redirectUser: false, + }); openNewLeaflet(id); }} > diff --git a/app/new/route.ts b/app/new/route.ts index 20b20387..1a917326 100644 --- a/app/new/route.ts +++ b/app/new/route.ts @@ -5,5 +5,5 @@ export const dynamic = "force-dynamic"; export const fetchCache = "force-no-store"; export async function GET() { - await createNewLeaflet("doc", true); + await createNewLeaflet({ pageType: "doc", redirectUser: true }); } diff --git a/app/route.ts b/app/route.ts index 47d9e594..10f939f3 100644 --- a/app/route.ts +++ b/app/route.ts @@ -9,5 +9,5 @@ export const fetchCache = "force-no-store"; export async function GET() { let auth_token = (await cookies()).get("auth_token")?.value; if (auth_token) redirect("/home"); - else await createNewLeaflet("doc", true); + else await createNewLeaflet({ pageType: "doc", redirectUser: true }); } -- 2.51.2