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 (
<>
-