a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add optimistic writes to db

+31 -12
+12 -4
actions/createPublication.ts
··· 3 3 import { AtpBaseClient } from "lexicons/src"; 4 4 import { createOauthClient } from "src/atproto-oauth"; 5 5 import { getIdentityData } from "actions/getIdentityData"; 6 + import { supabaseServerClient } from "supabase/serverClient"; 6 7 7 8 export async function createPublication(name: string) { 8 9 const oauthClient = await createOauthClient(); ··· 12 13 let agent = new AtpBaseClient( 13 14 credentialSession.fetchHandler.bind(credentialSession), 14 15 ); 16 + let record = { 17 + name, 18 + }; 15 19 let result = await agent.pub.leaflet.publication.create( 16 20 { repo: credentialSession.did!, rkey: TID.nextStr(), validate: false }, 17 - { 18 - name, 19 - }, 21 + record, 20 22 ); 21 - console.log(result); 23 + 24 + //optimistically write to our db! 25 + await supabaseServerClient.from("publications").upsert({ 26 + uri: result.uri, 27 + identity_did: credentialSession.did!, 28 + name: record.name, 29 + }); 22 30 }
+18 -2
actions/publishToPublication.ts
··· 23 23 import { BlobRef } from "@atproto/lexicon"; 24 24 import { IdResolver } from "@atproto/identity"; 25 25 import { AtUri } from "@atproto/syntax"; 26 + import { Json } from "supabase/database.types"; 26 27 27 28 const idResolver = new IdResolver(); 28 29 export async function publishToPublication( ··· 97 98 { repo: credentialSession.did!, rkey, validate: false }, 98 99 record, 99 100 ); 100 - let html = blocksToHtml(blocks, imageMap, scan, publication_uri); 101 - await sendPostToEmailSubscribers(publication_uri, { title, content: html }); 101 + 102 + await Promise.all([ 103 + //Optimistically put these in! 104 + supabaseServerClient.from("documents").upsert({ 105 + uri: result.uri, 106 + data: record as Json, 107 + }), 108 + supabaseServerClient.from("documents_in_publications").insert({ 109 + publication: record.publication, 110 + document: result.uri, 111 + }), 112 + sendPostToEmailSubscribers(publication_uri, { 113 + title, 114 + content: blocksToHtml(blocks, imageMap, scan, publication_uri), 115 + }), 116 + ]); 117 + 102 118 let handle = await idResolver.did.resolve(credentialSession.did!); 103 119 return { handle, rkey }; 104 120 }
+1 -6
app/lish/PostList.tsx
··· 27 27 </div> 28 28 ); 29 29 } 30 - return ( 31 - <div className="italic text-tertiary flex flex-col gap-2 justify-center place-items-center"> 32 - <div>Welcome to your new Publication</div> 33 - <ButtonPrimary>Start Drafting!</ButtonPrimary> 34 - </div> 35 - ); 30 + return null; 36 31 } 37 32 38 33 return (