a tool for shared writing and social publishing

make archiving in pubs work

+92 -82
+38 -23
actions/deleteLeaflet.ts
··· 42 42 let identity = await getIdentityData(); 43 43 if (!identity) throw new Error("No Identity"); 44 44 45 + // Archive on homepage 45 46 await supabaseServerClient 46 47 .from("permission_token_on_homepage") 47 48 .update({ archived: true }) 48 49 .eq("token", token) 49 50 .eq("identity", identity.id); 50 - refresh(); 51 - return; 52 - } 53 - export async function archivePublicationDraft( 54 - token: string, 55 - publication: string, 56 - ) { 57 - console.log("ARCHIVING", token, publication); 58 - let identity = await getIdentityData(); 59 - if (!identity) throw new Error("No Identity"); 60 - let { data: pub } = await supabaseServerClient 61 - .from("publications") 62 - .select("*") 63 - .eq("uri", publication) 64 - .single(); 51 + 52 + // Check if leaflet is in any publications where user is the creator 53 + let { data: leafletInPubs } = await supabaseServerClient 54 + .from("leaflets_in_publications") 55 + .select("publication, publications!inner(identity_did)") 56 + .eq("leaflet", token); 65 57 66 - if (!pub || pub.identity_did !== identity.atp_did) return; 58 + if (leafletInPubs) { 59 + for (let pub of leafletInPubs) { 60 + if (pub.publications.identity_did === identity.atp_did) { 61 + await supabaseServerClient 62 + .from("leaflets_in_publications") 63 + .update({ archived: true }) 64 + .eq("leaflet", token) 65 + .eq("publication", pub.publication); 66 + } 67 + } 68 + } 67 69 68 - console.log( 69 - await supabaseServerClient 70 - .from("leaflets_in_publications") 71 - .update({ archived: true }) 72 - .eq("leaflet", token) 73 - .eq("publication", publication), 74 - ); 75 70 refresh(); 76 71 return; 77 72 } ··· 80 75 let identity = await getIdentityData(); 81 76 if (!identity) throw new Error("No Identity"); 82 77 78 + // Unarchive on homepage 83 79 await supabaseServerClient 84 80 .from("permission_token_on_homepage") 85 81 .update({ archived: false }) 86 82 .eq("token", token) 87 83 .eq("identity", identity.id); 84 + 85 + // Check if leaflet is in any publications where user is the creator 86 + let { data: leafletInPubs } = await supabaseServerClient 87 + .from("leaflets_in_publications") 88 + .select("publication, publications!inner(identity_did)") 89 + .eq("leaflet", token); 90 + 91 + if (leafletInPubs) { 92 + for (let pub of leafletInPubs) { 93 + if (pub.publications.identity_did === identity.atp_did) { 94 + await supabaseServerClient 95 + .from("leaflets_in_publications") 96 + .update({ archived: false }) 97 + .eq("leaflet", token) 98 + .eq("publication", pub.publication); 99 + } 100 + } 101 + } 102 + 88 103 refresh(); 89 104 return; 90 105 }
+44 -48
app/(home-pages)/home/LeafletList/LeafletListItem.tsx
··· 51 51 if (props.display === "list") 52 52 return ( 53 53 <> 54 - <LeafletLink 55 - id={props.token.id} 56 - className={`w-full ${props.isHidden ? "hidden" : "block"}`} 54 + <div 55 + ref={previewRef} 56 + className={`relative flex gap-3 w-full 57 + ${props.isHidden ? "hidden" : "flex"} 58 + ${props.cardBorderHidden ? "" : "px-2 py-1 block-border hover:outline-border relative"}`} 59 + style={{ 60 + backgroundColor: props.cardBorderHidden 61 + ? "transparent" 62 + : "rgba(var(--bg-page), var(--bg-page-alpha))", 63 + }} 57 64 > 58 - <div 59 - ref={previewRef} 60 - className={`flex gap-3 w-full ${props.cardBorderHidden ? "" : "px-2 py-1 block-border hover:outline-border relative"}`} 61 - style={{ 62 - backgroundColor: props.cardBorderHidden 63 - ? "transparent" 64 - : "rgba(var(--bg-page), var(--bg-page-alpha))", 65 - }} 66 - > 67 - {props.showPreview && ( 68 - <LeafletListPreview isVisible={isOnScreen} {...props} /> 69 - )} 70 - <LeafletInfo isTemplate={isTemplate} {...props} /> 71 - </div> 72 - </LeafletLink> 65 + <SpeedyLink 66 + href={`/${props.token.id}`} 67 + className={`absolute w-full h-full top-0 left-0 no-underline hover:no-underline! text-primary`} 68 + /> 69 + {props.showPreview && ( 70 + <LeafletListPreview isVisible={isOnScreen} {...props} /> 71 + )} 72 + <LeafletInfo isTemplate={isTemplate} {...props} /> 73 + </div> 73 74 {props.cardBorderHidden && ( 74 75 <hr 75 76 className="last:hidden border-border-light" ··· 81 82 </> 82 83 ); 83 84 return ( 84 - <LeafletLink 85 - id={props.token.id} 86 - className={`leafletGridListItem relative w-full ${props.isHidden ? "hidden" : "flex"}`} 87 - > 88 - <div 89 - ref={previewRef} 90 - className={` 85 + <div 86 + ref={previewRef} 87 + className={` 88 + relative 91 89 flex flex-col gap-1 p-1 h-52 w-full 92 90 block-border border-border! hover:outline-border 91 + ${props.isHidden ? "hidden" : "flex"} 93 92 `} 94 - style={{ 95 - backgroundColor: props.cardBorderHidden 96 - ? "transparent" 97 - : "rgba(var(--bg-page), var(--bg-page-alpha))", 98 - }} 99 - > 100 - <div className="grow"> 101 - <LeafletGridPreview {...props} isVisible={isOnScreen} /> 102 - </div> 103 - <LeafletInfo 104 - isTemplate={isTemplate} 105 - className="px-1 pb-0.5 shrink-0" 106 - {...props} 107 - /> 93 + style={{ 94 + backgroundColor: props.cardBorderHidden 95 + ? "transparent" 96 + : "rgba(var(--bg-page), var(--bg-page-alpha))", 97 + }} 98 + > 99 + <SpeedyLink 100 + href={`/${props.token.id}`} 101 + className={`absolute w-full h-full top-0 left-0 no-underline hover:no-underline! text-primary`} 102 + /> 103 + <div className="grow"> 104 + <LeafletGridPreview {...props} isVisible={isOnScreen} /> 108 105 </div> 109 - </LeafletLink> 106 + <LeafletInfo 107 + isTemplate={isTemplate} 108 + className="px-1 pb-0.5 shrink-0" 109 + {...props} 110 + /> 111 + </div> 110 112 ); 111 113 }; 112 114 113 - const LeafletLink = (props: { 114 - id: string; 115 - children: React.ReactNode; 116 - className: string; 117 - }) => { 115 + const LeafletLink = (props: { id: string; className: string }) => { 118 116 return ( 119 117 <SpeedyLink 120 118 href={`/${props.id}`} 121 119 className={`no-underline hover:no-underline! text-primary ${props.className}`} 122 - > 123 - {props.children} 124 - </SpeedyLink> 120 + /> 125 121 ); 126 122 };
+1 -6
app/(home-pages)/home/LeafletList/LeafletOptions.tsx
··· 11 11 import { DeleteSmall } from "components/Icons/DeleteSmall"; 12 12 import { 13 13 archivePost, 14 - archivePublicationDraft, 15 14 deleteLeaflet, 16 15 unarchivePost, 17 16 } from "actions/deleteLeaflet"; ··· 124 123 <MenuItem 125 124 onSelect={async () => { 126 125 if (!props.archived) { 127 - if (props.draftInPublication) 128 - await archivePublicationDraft( 129 - props.leaflet.id, 130 - props.draftInPublication, 131 - ); 126 + await archivePost(props.leaflet.id); 132 127 toaster({ 133 128 content: ( 134 129 <div className="font-bold flex gap-2">
+3 -3
app/(home-pages)/home/LeafletList/LeafletPreview.tsx
··· 133 133 ); 134 134 return ( 135 135 <ThemeProvider local entityID={root} className="w-full!"> 136 - <div className="border border-border-light rounded-md w-full h-full overflow-hidden relative"> 137 - <div className="relative w-full h-full"> 136 + <div className="border border-border-light rounded-md w-full h-full overflow-hidden "> 137 + <div className="w-full h-full"> 138 138 <ThemeBackgroundProvider entityID={root}> 139 139 <div 140 140 inert 141 - className="leafletPreview relative grow shrink-0 h-full w-full px-2 pt-2 sm:px-3 sm:pt-3 flex items-end pointer-events-none" 141 + className="leafletPreview grow shrink-0 h-full w-full px-2 pt-2 sm:px-3 sm:pt-3 flex items-end pointer-events-none" 142 142 > 143 143 <div 144 144 className={`leafletContentWrapper h-full sm:w-48 w-40 mx-auto overflow-clip ${!cardBorderHidden && "border border-border-light border-b-0 rounded-t-md"}`}
+6 -2
app/lish/[did]/[publication]/dashboard/PublicationSWRProvider.tsx
··· 2 2 3 3 import type { GetPublicationDataReturnType } from "app/api/rpc/[command]/get_publication_data"; 4 4 import { callRPC } from "app/api/rpc/client"; 5 - import { createContext, useContext } from "react"; 6 - import useSWR, { SWRConfig } from "swr"; 5 + import { createContext, useContext, useEffect } from "react"; 6 + import useSWR, { SWRConfig, mutate } from "swr"; 7 7 8 8 const PublicationContext = createContext({ name: "", did: "" }); 9 9 export function PublicationSWRDataProvider(props: { ··· 13 13 children: React.ReactNode; 14 14 }) { 15 15 let key = `publication-data-${props.publication_did}-${props.publication_rkey}`; 16 + useEffect(() => { 17 + console.log("UPDATING"); 18 + mutate(key, props.publication_data); 19 + }, [props.publication_data]); 16 20 return ( 17 21 <PublicationContext 18 22 value={{ name: props.publication_rkey, did: props.publication_did }}