a tool for shared writing and social publishing

added buttons to archive and unarchive in leaflet options

+78 -15
+26
actions/deleteLeaflet.ts
··· 9 9 import { eq } from "drizzle-orm"; 10 10 import { PermissionToken } from "src/replicache"; 11 11 import { pool } from "supabase/pool"; 12 + import { getIdentityData } from "./getIdentityData"; 13 + import { supabaseServerClient } from "supabase/serverClient"; 12 14 13 15 export async function deleteLeaflet(permission_token: PermissionToken) { 14 16 const client = await pool.connect(); ··· 34 36 client.release(); 35 37 return; 36 38 } 39 + 40 + export async function archivePost(token: string) { 41 + let identity = await getIdentityData(); 42 + if (!identity) throw new Error("No Identity"); 43 + 44 + await supabaseServerClient 45 + .from("permission_token_on_homepage") 46 + .update({ archived: true }) 47 + .eq("token", token) 48 + .eq("identity", identity.id); 49 + return; 50 + } 51 + 52 + export async function unarchivePost(token: string) { 53 + let identity = await getIdentityData(); 54 + if (!identity) throw new Error("No Identity"); 55 + 56 + await supabaseServerClient 57 + .from("permission_token_on_homepage") 58 + .update({ archived: false }) 59 + .eq("token", token) 60 + .eq("identity", identity.id); 61 + return; 62 + }
+3 -1
app/(home-pages)/home/LeafletList/LeafletInfo.tsx
··· 25 25 }) => { 26 26 let [prefetch, setPrefetch] = useState(false); 27 27 let prettyCreatedAt = props.added_at ? timeAgo(props.added_at) : ""; 28 - 29 28 let prettyPublishedAt = props.publishedAt ? timeAgo(props.publishedAt) : ""; 30 29 31 30 return ( ··· 78 77 </div> 79 78 ) : ( 80 79 <div className="text-xs text-tertiary">{prettyCreatedAt}</div> 80 + )} 81 + {props.archived && ( 82 + <div className="text-xs text-tertiary">archived</div> 81 83 )} 82 84 </Link> 83 85 {props.isTemplate && props.display === "grid" ? (
+48 -13
app/(home-pages)/home/LeafletList/LeafletOptions.tsx
··· 1 1 "use client"; 2 2 3 3 import { Menu, MenuItem } from "components/Layout"; 4 - import { useReplicache, type PermissionToken } from "src/replicache"; 5 - import { hideDoc } from "../storage"; 6 4 import { useState } from "react"; 7 5 import { ButtonPrimary, ButtonTertiary } from "components/Buttons"; 8 6 import { useTemplateState } from "../Actions/CreateNewButton"; 9 7 import { useSmoker, useToaster } from "components/Toast"; 10 - import { removeLeafletFromHome } from "actions/removeLeafletFromHome"; 11 - import { useIdentityData } from "components/IdentityProvider"; 12 - import { HideSmall } from "components/Icons/HideSmall"; 13 - import { MoreOptionsTiny } from "components/Icons/MoreOptionsTiny"; 14 8 import { TemplateRemoveSmall } from "components/Icons/TemplateRemoveSmall"; 15 9 import { TemplateSmall } from "components/Icons/TemplateSmall"; 16 10 import { MoreOptionsVerticalTiny } from "components/Icons/MoreOptionsVerticalTiny"; 17 11 import { DeleteSmall } from "components/Icons/DeleteSmall"; 18 - import { deleteLeaflet } from "actions/deleteLeaflet"; 12 + import { 13 + archivePost, 14 + deleteLeaflet, 15 + unarchivePost, 16 + } from "actions/deleteLeaflet"; 19 17 import { ArchiveSmall } from "components/Icons/ArchiveSmall"; 20 18 import { UnpublishSmall } from "components/Icons/UnpublishSmall"; 21 19 import { 22 20 deletePost, 23 21 unpublishPost, 24 22 } from "app/lish/[did]/[publication]/dashboard/deletePost"; 25 - import { usePublicationData } from "app/lish/[did]/[publication]/dashboard/PublicationSWRProvider"; 26 23 import { ShareButton } from "components/ShareOptions"; 27 24 import { ShareSmall } from "components/Icons/ShareSmall"; 25 + 26 + import { PermissionToken } from "src/replicache"; 28 27 29 28 export const LeafletOptions = (props: { 30 29 leaflet: PermissionToken; ··· 97 96 leaflet: PermissionToken; 98 97 isTemplate: boolean | undefined; 99 98 shareLink: string; 99 + archived?: boolean | null; 100 100 }) => { 101 + let toaster = useToaster(); 101 102 return ( 102 103 <> 103 104 <ShareButton ··· 118 119 /> 119 120 120 121 <hr className="border-border-light" /> 121 - <MenuItem onSelect={() => {}}> 122 + <MenuItem 123 + onSelect={() => { 124 + if (!props.archived) { 125 + archivePost(props.leaflet.id); 126 + toaster({ 127 + content: ( 128 + <div className="font-bold flex gap-2"> 129 + Archived{props.draft ? " Draft" : " Leaflet"}! 130 + <ButtonTertiary 131 + className="underline text-accent-2!" 132 + onClick={() => { 133 + unarchivePost(props.leaflet.id); 134 + toaster({ 135 + content: ( 136 + <div className="font-bold flex gap-2"> 137 + Unarchived! 138 + </div> 139 + ), 140 + type: "success", 141 + }); 142 + }} 143 + > 144 + Undo? 145 + </ButtonTertiary> 146 + </div> 147 + ), 148 + type: "success", 149 + }); 150 + } else { 151 + unarchivePost(props.leaflet.id); 152 + toaster({ 153 + content: <div className="font-bold">Unarchived!</div>, 154 + type: "success", 155 + }); 156 + } 157 + }} 158 + > 122 159 <ArchiveSmall /> 123 - Archive{props.draft ? " Draft" : " Leaflet"} 160 + {!props.archived ? " Archive" : "Unarchive"} 161 + {props.draft ? " Draft" : " Leaflet"} 124 162 </MenuItem> 125 163 <MenuItem 126 164 onSelect={(e) => { ··· 214 252 </ButtonTertiary> 215 253 <ButtonPrimary 216 254 onClick={async () => { 217 - //TODO refresh local data 218 255 if (props.document_uri) { 219 256 await deletePost(props.document_uri); 220 257 } 221 258 deleteLeaflet(props.leaflet); 222 - console.log("deleting leaflet"); 223 259 224 260 toaster({ 225 261 content: ( ··· 234 270 ), 235 271 type: "success", 236 272 }); 237 - console.log("toasting"); 238 273 }} 239 274 > 240 275 Delete it!
-1
app/lish/[did]/[publication]/dashboard/deletePost.ts
··· 30 30 .delete() 31 31 .eq("doc", document_uri), 32 32 ]); 33 - console.log("called delete"); 34 33 35 34 return revalidatePath("/lish/[did]/[publication]/dashboard", "layout"); 36 35 }
+1
app/lish/createPub/createPublication.ts
··· 101 101 await supabaseServerClient 102 102 .from("custom_domains") 103 103 .insert({ domain, confirmed: true, identity: null }); 104 + 104 105 await supabaseServerClient 105 106 .from("publication_domains") 106 107 .insert({ domain, publication: result.uri, identity: identity.atp_did });