a tool for shared writing and social publishing
0

Configure Feed

Select the types of activity you want to include in your feed.

handle signed out users side bar actions

Jared Pereira (May 7, 2026, 4:56 PM EDT) ff498dcf 03fb3086

+44 -45
+11 -4
app/[leaflet_id]/Footer.tsx
··· 19 19 import { useEntity, useReplicache } from "src/replicache"; 20 20 import { block } from "sharp"; 21 21 import { PostSettings } from "components/PostSettings"; 22 + import useSWR from "swr"; 23 + import { getHomeDocs } from "app/(home-pages)/(writer)/home/storage"; 22 24 23 25 export function hasBlockToolbar(blockType: string | null | undefined) { 24 26 return ( ··· 36 38 let { identity } = useIdentityData(); 37 39 let { permission_token } = useReplicache(); 38 40 let { data: pub } = useLeafletPublicationData(); 41 + let { data: localLeaflets } = useSWR("leaflets", () => getHomeDocs(), { 42 + fallbackData: [], 43 + }); 39 44 let blockType = useEntity(focusedBlock?.entityID || null, "block/type")?.data 40 45 .value; 46 + let isOnHome = identity 47 + ? !!identity.permission_token_on_homepage.find( 48 + (pth) => pth.permission_tokens.id === permission_token.id, 49 + ) 50 + : !!localLeaflets.find((f) => f.token.id === permission_token.id); 41 51 42 52 return ( 43 53 <Media ··· 82 92 )} 83 93 84 94 <div className="mobileLeafletActions flex gap-2 shrink-0"> 85 - {identity && 86 - !identity.permission_token_on_homepage.find( 87 - (pth) => pth.permission_tokens.id === permission_token.id, 88 - ) ? ( 95 + {!isOnHome ? ( 89 96 <AddToHomeButton primary /> 90 97 ) : ( 91 98 <PublishButton entityID={props.entityID} />
-2
app/[leaflet_id]/Leaflet.tsx
··· 9 9 } from "components/ThemeManager/ThemeProvider"; 10 10 import { LeafletFooter } from "./Footer"; 11 11 import { EntitySetProvider } from "components/EntitySetProvider"; 12 - import { AddLeafletToHomepage } from "components/utils/AddLeafletToHomepage"; 13 12 import { UpdateLeafletTitle } from "components/utils/UpdateLeafletTitle"; 14 13 import { useUIState } from "src/useUIState"; 15 14 import { LeafletLayout } from "components/LeafletLayout"; ··· 38 37 > 39 38 <ThemeBackgroundProvider entityID={props.leaflet_id}> 40 39 <UpdateLeafletTitle entityID={props.leaflet_id} /> 41 - <AddLeafletToHomepage /> 42 40 <SelectionManager /> 43 41 {/* we need the padding bottom here because if we don't have it the mobile footer will cut off... 44 42 the dropshadow on the page... the padding is compensated by a negative top margin in mobile footer */}
+11 -4
app/[leaflet_id]/Sidebar.tsx
··· 16 16 import { BackToPubButton } from "./actions/BackToPubButton"; 17 17 import { useIdentityData } from "components/IdentityProvider"; 18 18 import { useReplicache } from "src/replicache"; 19 + import useSWR from "swr"; 20 + import { getHomeDocs } from "app/(home-pages)/(writer)/home/storage"; 19 21 20 22 export function LeafletSidebar() { 21 23 let entity_set = useEntitySetContext(); ··· 23 25 let { data: pub } = useLeafletPublicationData(); 24 26 let { identity } = useIdentityData(); 25 27 let { permission_token } = useReplicache(); 28 + let { data: localLeaflets } = useSWR("leaflets", () => getHomeDocs(), { 29 + fallbackData: [], 30 + }); 31 + let isOnHome = identity 32 + ? !!identity.permission_token_on_homepage.find( 33 + (pth) => pth.permission_tokens.id === permission_token.id, 34 + ) 35 + : !!localLeaflets.find((f) => f.token.id === permission_token.id); 26 36 27 37 return ( 28 38 <Media mobile={false} className="w-0 h-full relative"> ··· 33 43 <div className="sidebarContainer flex flex-col justify-end h-full w-16 relative"> 34 44 {entity_set.permissions.write && ( 35 45 <Sidebar className="my-0!"> 36 - {identity && 37 - !identity.permission_token_on_homepage.find( 38 - (pth) => pth.permission_tokens.id === permission_token.id, 39 - ) ? ( 46 + {!isOnHome ? ( 40 47 <AddToHomeButton /> 41 48 ) : ( 42 49 <PublishButton entityID={rootEntity} />
+22 -15
app/[leaflet_id]/actions/HomeButton.tsx
··· 10 10 import { AddToHomeSmall } from "../../../components/Icons/AddToHomeSmall"; 11 11 import { HomeSmall } from "../../../components/Icons/HomeSmall"; 12 12 import { produce } from "immer"; 13 + import { addDocToHome } from "app/(home-pages)/(writer)/home/storage"; 14 + import { mutate as swrMutate } from "swr"; 13 15 14 16 export function HomeButton() { 15 17 let { permissions } = useEntitySetContext(); ··· 40 42 labelOnMobile 41 43 className="sm:w-full! w-fit!" 42 44 onClick={async (e) => { 43 - await addLeafletToHome(permission_token.id); 44 - mutate((identity) => { 45 - if (!identity) return; 46 - return produce<typeof identity>((draft) => { 47 - draft.permission_token_on_homepage.push({ 48 - created_at: new Date().toISOString(), 49 - archived: null, 50 - permission_tokens: { 51 - ...permission_token, 52 - leaflets_to_documents: [], 53 - leaflets_in_publications: [], 54 - }, 55 - }); 56 - })(identity); 57 - }); 45 + if (identity) { 46 + await addLeafletToHome(permission_token.id); 47 + mutate((identity) => { 48 + if (!identity) return; 49 + return produce<typeof identity>((draft) => { 50 + draft.permission_token_on_homepage.push({ 51 + created_at: new Date().toISOString(), 52 + archived: null, 53 + permission_tokens: { 54 + ...permission_token, 55 + leaflets_to_documents: [], 56 + leaflets_in_publications: [], 57 + }, 58 + }); 59 + })(identity); 60 + }); 61 + } else { 62 + addDocToHome(permission_token); 63 + swrMutate("leaflets"); 64 + } 58 65 smoker({ 59 66 position: { 60 67 x: e.clientX + 64,
-20
components/utils/AddLeafletToHomepage.tsx
··· 1 - "use client"; 2 - 3 - import { addDocToHome } from "app/(home-pages)/(writer)/home/storage"; 4 - import { useIdentityData } from "components/IdentityProvider"; 5 - import { useEffect } from "react"; 6 - import { useReplicache } from "src/replicache"; 7 - 8 - export function AddLeafletToHomepage() { 9 - let { permission_token } = useReplicache(); 10 - let { identity } = useIdentityData(); 11 - useEffect(() => { 12 - if (identity) return; 13 - if (permission_token.permission_token_rights[0].write) { 14 - try { 15 - addDocToHome(permission_token); 16 - } catch (e) {} 17 - } 18 - }, [permission_token, identity]); 19 - return null; 20 - }