diff --git a/actions/deleteLeaflet.ts b/actions/deleteLeaflet.ts index 3e64b942..5302b5c4 100644 --- a/actions/deleteLeaflet.ts +++ b/actions/deleteLeaflet.ts @@ -42,36 +42,31 @@ export async function archivePost(token: string) { let identity = await getIdentityData(); if (!identity) throw new Error("No Identity"); + // Archive on homepage await supabaseServerClient .from("permission_token_on_homepage") .update({ archived: true }) .eq("token", token) .eq("identity", identity.id); - refresh(); - return; -} -export async function archivePublicationDraft( - token: string, - publication: string, -) { - console.log("ARCHIVING", token, publication); - let identity = await getIdentityData(); - if (!identity) throw new Error("No Identity"); - let { data: pub } = await supabaseServerClient - .from("publications") - .select("*") - .eq("uri", publication) - .single(); - if (!pub || pub.identity_did !== identity.atp_did) return; + // Check if leaflet is in any publications where user is the creator + let { data: leafletInPubs } = await supabaseServerClient + .from("leaflets_in_publications") + .select("publication, publications!inner(identity_did)") + .eq("leaflet", token); + + if (leafletInPubs) { + for (let pub of leafletInPubs) { + if (pub.publications.identity_did === identity.atp_did) { + await supabaseServerClient + .from("leaflets_in_publications") + .update({ archived: true }) + .eq("leaflet", token) + .eq("publication", pub.publication); + } + } + } - console.log( - await supabaseServerClient - .from("leaflets_in_publications") - .update({ archived: true }) - .eq("leaflet", token) - .eq("publication", publication), - ); refresh(); return; } @@ -80,11 +75,31 @@ export async function unarchivePost(token: string) { let identity = await getIdentityData(); if (!identity) throw new Error("No Identity"); + // Unarchive on homepage await supabaseServerClient .from("permission_token_on_homepage") .update({ archived: false }) .eq("token", token) .eq("identity", identity.id); + + // Check if leaflet is in any publications where user is the creator + let { data: leafletInPubs } = await supabaseServerClient + .from("leaflets_in_publications") + .select("publication, publications!inner(identity_did)") + .eq("leaflet", token); + + if (leafletInPubs) { + for (let pub of leafletInPubs) { + if (pub.publications.identity_did === identity.atp_did) { + await supabaseServerClient + .from("leaflets_in_publications") + .update({ archived: false }) + .eq("leaflet", token) + .eq("publication", pub.publication); + } + } + } + refresh(); return; } diff --git a/app/(home-pages)/home/LeafletList/LeafletListItem.tsx b/app/(home-pages)/home/LeafletList/LeafletListItem.tsx index b3658449..bb596b82 100644 --- a/app/(home-pages)/home/LeafletList/LeafletListItem.tsx +++ b/app/(home-pages)/home/LeafletList/LeafletListItem.tsx @@ -51,25 +51,26 @@ export const LeafletListItem = (props: { if (props.display === "list") return ( <> - -
- {props.showPreview && ( - - )} - -
-
+ + {props.showPreview && ( + + )} + + {props.cardBorderHidden && (
); return ( - -
-
- -
- + style={{ + backgroundColor: props.cardBorderHidden + ? "transparent" + : "rgba(var(--bg-page), var(--bg-page-alpha))", + }} + > + +
+
- + +
); }; -const LeafletLink = (props: { - id: string; - children: React.ReactNode; - className: string; -}) => { +const LeafletLink = (props: { id: string; className: string }) => { return ( - {props.children} - + /> ); }; diff --git a/app/(home-pages)/home/LeafletList/LeafletOptions.tsx b/app/(home-pages)/home/LeafletList/LeafletOptions.tsx index a76a47e4..7781906b 100644 --- a/app/(home-pages)/home/LeafletList/LeafletOptions.tsx +++ b/app/(home-pages)/home/LeafletList/LeafletOptions.tsx @@ -11,7 +11,6 @@ import { MoreOptionsVerticalTiny } from "components/Icons/MoreOptionsVerticalTin import { DeleteSmall } from "components/Icons/DeleteSmall"; import { archivePost, - archivePublicationDraft, deleteLeaflet, unarchivePost, } from "actions/deleteLeaflet"; @@ -124,11 +123,7 @@ const DefaultOptions = (props: { { if (!props.archived) { - if (props.draftInPublication) - await archivePublicationDraft( - props.leaflet.id, - props.draftInPublication, - ); + await archivePost(props.leaflet.id); toaster({ content: (
diff --git a/app/(home-pages)/home/LeafletList/LeafletPreview.tsx b/app/(home-pages)/home/LeafletList/LeafletPreview.tsx index 0b92c225..e3530f8a 100644 --- a/app/(home-pages)/home/LeafletList/LeafletPreview.tsx +++ b/app/(home-pages)/home/LeafletList/LeafletPreview.tsx @@ -133,12 +133,12 @@ export const LeafletGridPreview = (props: { ); return ( -
-
+
+
{ + console.log("UPDATING"); + mutate(key, props.publication_data); + }, [props.publication_data]); return (