tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
291
fork
atom
a tool for shared writing and social publishing
291
fork
atom
overview
issues
28
pulls
pipelines
fix update pub function and icon in edit form
awarm.space
10 months ago
5c1cb3d8
4f084078
+7
-4
2 changed files
expand all
collapse all
unified
split
app
lish
createPub
UpdatePubForm.tsx
updatePublication.ts
+1
-1
app/lish/createPub/UpdatePubForm.tsx
···
31
31
setDescriptionValue(record.description || "");
32
32
if (record.icon)
33
33
setIconPreview(
34
34
-
`url(/api/atproto_images?did=${pubData.identity_did}&cid=${(record.icon.ref as unknown as { $link: string })["$link"]})`,
34
34
+
`/api/atproto_images?did=${pubData.identity_did}&cid=${(record.icon.ref as unknown as { $link: string })["$link"]}`,
35
35
);
36
36
}, [pubData]);
37
37
let toast = useToaster();
+6
-3
app/lish/createPub/updatePublication.ts
···
6
6
import { supabaseServerClient } from "supabase/serverClient";
7
7
import { Json } from "supabase/database.types";
8
8
import { AtUri } from "@atproto/syntax";
9
9
+
import { redirect } from "next/navigation";
9
10
10
11
export async function updatePublication({
11
12
uri,
···
31
32
.select("*")
32
33
.eq("uri", uri)
33
34
.single();
34
34
-
if (!existingPub || existingPub.identity_did! === identity.atp_did) return;
35
35
+
if (!existingPub || existingPub.identity_did !== identity.atp_did) return;
35
36
let aturi = new AtUri(existingPub.uri);
36
37
37
38
let record: PubLeafletPublication.Record = {
38
39
$type: "pub.leaflet.publication",
39
39
-
name,
40
40
...(existingPub.record as object),
41
41
+
name,
41
42
};
42
43
43
44
if (description) {
···
66
67
});
67
68
68
69
//optimistically write to our db!
69
69
-
let { data: publication } = await supabaseServerClient
70
70
+
let { data: publication, error } = await supabaseServerClient
70
71
.from("publications")
71
72
.update({
72
73
name: record.name,
···
75
76
.eq("uri", uri)
76
77
.select()
77
78
.single();
79
79
+
if (name !== existingPub.name)
80
80
+
return redirect(`/lish/${aturi.host}/${name}/dashboard`);
78
81
79
82
return { success: true, publication };
80
83
}