diff --git a/actions/deleteLeaflet.ts b/actions/deleteLeaflet.ts index 5584a325..ec46bbc0 100644 --- a/actions/deleteLeaflet.ts +++ b/actions/deleteLeaflet.ts @@ -9,6 +9,8 @@ import { import { eq } from "drizzle-orm"; import { PermissionToken } from "src/replicache"; import { pool } from "supabase/pool"; +import { getIdentityData } from "./getIdentityData"; +import { supabaseServerClient } from "supabase/serverClient"; export async function deleteLeaflet(permission_token: PermissionToken) { const client = await pool.connect(); @@ -34,3 +36,27 @@ export async function deleteLeaflet(permission_token: PermissionToken) { client.release(); return; } + +export async function archivePost(token: string) { + let identity = await getIdentityData(); + if (!identity) throw new Error("No Identity"); + + await supabaseServerClient + .from("permission_token_on_homepage") + .update({ archived: true }) + .eq("token", token) + .eq("identity", identity.id); + return; +} + +export async function unarchivePost(token: string) { + let identity = await getIdentityData(); + if (!identity) throw new Error("No Identity"); + + await supabaseServerClient + .from("permission_token_on_homepage") + .update({ archived: false }) + .eq("token", token) + .eq("identity", identity.id); + return; +} diff --git a/app/(home-pages)/home/LeafletList/LeafletInfo.tsx b/app/(home-pages)/home/LeafletList/LeafletInfo.tsx index 7d44d013..b1c50611 100644 --- a/app/(home-pages)/home/LeafletList/LeafletInfo.tsx +++ b/app/(home-pages)/home/LeafletList/LeafletInfo.tsx @@ -25,7 +25,6 @@ export const LeafletInfo = (props: { }) => { let [prefetch, setPrefetch] = useState(false); let prettyCreatedAt = props.added_at ? timeAgo(props.added_at) : ""; - let prettyPublishedAt = props.publishedAt ? timeAgo(props.publishedAt) : ""; return ( @@ -79,6 +78,9 @@ export const LeafletInfo = (props: { ) : (
{prettyCreatedAt}
)} + {props.archived && ( +
archived
+ )} {props.isTemplate && props.display === "grid" ? (
diff --git a/app/(home-pages)/home/LeafletList/LeafletOptions.tsx b/app/(home-pages)/home/LeafletList/LeafletOptions.tsx index 63191ff8..7d952704 100644 --- a/app/(home-pages)/home/LeafletList/LeafletOptions.tsx +++ b/app/(home-pages)/home/LeafletList/LeafletOptions.tsx @@ -1,31 +1,30 @@ "use client"; import { Menu, MenuItem } from "components/Layout"; -import { useReplicache, type PermissionToken } from "src/replicache"; -import { hideDoc } from "../storage"; import { useState } from "react"; import { ButtonPrimary, ButtonTertiary } from "components/Buttons"; import { useTemplateState } from "../Actions/CreateNewButton"; import { useSmoker, useToaster } from "components/Toast"; -import { removeLeafletFromHome } from "actions/removeLeafletFromHome"; -import { useIdentityData } from "components/IdentityProvider"; -import { HideSmall } from "components/Icons/HideSmall"; -import { MoreOptionsTiny } from "components/Icons/MoreOptionsTiny"; import { TemplateRemoveSmall } from "components/Icons/TemplateRemoveSmall"; import { TemplateSmall } from "components/Icons/TemplateSmall"; import { MoreOptionsVerticalTiny } from "components/Icons/MoreOptionsVerticalTiny"; import { DeleteSmall } from "components/Icons/DeleteSmall"; -import { deleteLeaflet } from "actions/deleteLeaflet"; +import { + archivePost, + deleteLeaflet, + unarchivePost, +} from "actions/deleteLeaflet"; import { ArchiveSmall } from "components/Icons/ArchiveSmall"; import { UnpublishSmall } from "components/Icons/UnpublishSmall"; import { deletePost, unpublishPost, } from "app/lish/[did]/[publication]/dashboard/deletePost"; -import { usePublicationData } from "app/lish/[did]/[publication]/dashboard/PublicationSWRProvider"; import { ShareButton } from "components/ShareOptions"; import { ShareSmall } from "components/Icons/ShareSmall"; +import { PermissionToken } from "src/replicache"; + export const LeafletOptions = (props: { leaflet: PermissionToken; isTemplate?: boolean; @@ -97,7 +96,9 @@ const DefaultOptions = (props: { leaflet: PermissionToken; isTemplate: boolean | undefined; shareLink: string; + archived?: boolean | null; }) => { + let toaster = useToaster(); return ( <>
- {}}> + { + if (!props.archived) { + archivePost(props.leaflet.id); + toaster({ + content: ( +
+ Archived{props.draft ? " Draft" : " Leaflet"}! + { + unarchivePost(props.leaflet.id); + toaster({ + content: ( +
+ Unarchived! +
+ ), + type: "success", + }); + }} + > + Undo? +
+
+ ), + type: "success", + }); + } else { + unarchivePost(props.leaflet.id); + toaster({ + content:
Unarchived!
, + type: "success", + }); + } + }} + > - Archive{props.draft ? " Draft" : " Leaflet"} + {!props.archived ? " Archive" : "Unarchive"} + {props.draft ? " Draft" : " Leaflet"}
{ @@ -214,12 +252,10 @@ const DeleteAreYouSureForm = (props: { { - //TODO refresh local data if (props.document_uri) { await deletePost(props.document_uri); } deleteLeaflet(props.leaflet); - console.log("deleting leaflet"); toaster({ content: ( @@ -234,7 +270,6 @@ const DeleteAreYouSureForm = (props: { ), type: "success", }); - console.log("toasting"); }} > Delete it! diff --git a/app/lish/[did]/[publication]/dashboard/deletePost.ts b/app/lish/[did]/[publication]/dashboard/deletePost.ts index aaec272d..1723ed0f 100644 --- a/app/lish/[did]/[publication]/dashboard/deletePost.ts +++ b/app/lish/[did]/[publication]/dashboard/deletePost.ts @@ -30,7 +30,6 @@ export async function deletePost(document_uri: string) { .delete() .eq("doc", document_uri), ]); - console.log("called delete"); return revalidatePath("/lish/[did]/[publication]/dashboard", "layout"); } diff --git a/app/lish/createPub/createPublication.ts b/app/lish/createPub/createPublication.ts index bd4f7ab2..9ce067cb 100644 --- a/app/lish/createPub/createPublication.ts +++ b/app/lish/createPub/createPublication.ts @@ -101,6 +101,7 @@ export async function createPublication({ await supabaseServerClient .from("custom_domains") .insert({ domain, confirmed: true, identity: null }); + await supabaseServerClient .from("publication_domains") .insert({ domain, publication: result.uri, identity: identity.atp_did });