Retro Bulletin Board Systems on atproto. Web app and TUI. lazy mirror of alyraffauf/atbbs atbbs.xyz
forums python tui atproto bbs
3
fork

Configure Feed

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

web/writes: handle cache on record creation/deletion

+34 -3
+34 -3
web/src/lib/writes.ts
··· 4 4 import { SITE, BOARD, POST, BAN, HIDE, PIN, PROFILE } from "./lexicon"; 5 5 import { invalidateAllBBSCaches } from "./bbs"; 6 6 import { queryClient } from "./queryClient"; 7 - import { nowIso } from "./util"; 7 + import type { ATRecord } from "./atproto"; 8 + import { nowIso, parseAtUri } from "./util"; 8 9 import { getCurrentUser } from "./auth"; 9 10 import type { 10 11 XyzAtbbsPost, ··· 62 63 } 63 64 } 64 65 66 + // Seed the per-record cache used by getRecord so immediate re-reads (e.g. a 67 + // refetch of profileQuery after putProfile) see the new value instead of the 68 + // pre-write cached entry. 69 + function syncRecordCache<V extends object>( 70 + did: string, 71 + collection: string, 72 + rkey: string, 73 + value: V, 74 + uri: string, 75 + cid: string, 76 + ) { 77 + queryClient.setQueryData<ATRecord>(["record", did, collection, rkey], { 78 + uri, 79 + cid, 80 + value: { $type: collection, ...value }, 81 + }); 82 + } 83 + 65 84 async function createRecord<V extends object>( 66 85 rpc: Client, 67 86 collection: string, 68 87 value: V, 69 88 rkey?: string, 70 89 ) { 90 + const did = currentDid(); 71 91 const resp = await rpc.post("com.atproto.repo.createRecord", { 72 92 input: { 73 - repo: currentDid(), 93 + repo: did, 74 94 collection: asNsid(collection), 75 95 ...(rkey ? { rkey } : {}), 76 96 record: { $type: collection, ...value }, 77 97 }, 78 98 }); 79 99 assertOk(resp, "createRecord"); 100 + const createdRkey = parseAtUri(resp.data.uri).rkey; 101 + syncRecordCache( 102 + did, 103 + collection, 104 + createdRkey, 105 + value, 106 + resp.data.uri, 107 + resp.data.cid, 108 + ); 80 109 return resp; 81 110 } 82 111 ··· 86 115 rkey: string, 87 116 value: V, 88 117 ) { 118 + const did = currentDid(); 89 119 const resp = await rpc.post("com.atproto.repo.putRecord", { 90 120 input: { 91 - repo: currentDid(), 121 + repo: did, 92 122 collection: asNsid(collection), 93 123 rkey, 94 124 record: { $type: collection, ...value }, 95 125 }, 96 126 }); 97 127 assertOk(resp, "putRecord"); 128 + syncRecordCache(did, collection, rkey, value, resp.data.uri, resp.data.cid); 98 129 return resp; 99 130 } 100 131