a tool for shared writing and social publishing
0
fork

Configure Feed

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

provide static leaflet_data to home docs

+49 -17
+32 -9
app/home/LeafletList.tsx
··· 9 9 import type { Attribute } from "src/replicache/attributes"; 10 10 import { getIdentityData } from "actions/getIdentityData"; 11 11 import { callRPC } from "app/api/rpc/client"; 12 + import { StaticLeafletDataContext } from "components/PageSWRDataProvider"; 12 13 13 14 export function LeafletList(props: { 14 15 initialFacts: { ··· 37 38 mutate(); 38 39 }, [localLeaflets.length, mutate]); 39 40 let leaflets: Array< 40 - PermissionToken & { leaflets_in_publications?: Array<{ doc: string }> } 41 + PermissionToken & { 42 + leaflets_in_publications?: Array<{ 43 + doc: string; 44 + description: string; 45 + publication: string; 46 + leaflet: string; 47 + title: string; 48 + publications: null; 49 + documents: null; 50 + }>; 51 + } 41 52 > = identity 42 53 ? identity.permission_token_on_homepage 43 54 .sort((a, b) => ··· 68 79 name={leaflet.root_entity} 69 80 initialFacts={initialFacts?.[leaflet.root_entity] || []} 70 81 > 71 - <LeafletPreview 72 - index={index} 73 - token={leaflet} 74 - draft={!!leaflet.leaflets_in_publications?.length} 75 - published={!!leaflet.leaflets_in_publications?.find((l) => l.doc)} 76 - leaflet_id={leaflet.root_entity} 77 - loggedIn={!!identity} 78 - /> 82 + <StaticLeafletDataContext 83 + value={{ 84 + ...leaflet, 85 + leaflets_in_publications: 86 + leaflet.leaflets_in_publications || [], 87 + blocked_by_admin: null, 88 + custom_domain_routes: [], 89 + }} 90 + > 91 + <LeafletPreview 92 + index={index} 93 + token={leaflet} 94 + draft={!!leaflet.leaflets_in_publications?.length} 95 + published={ 96 + !!leaflet.leaflets_in_publications?.find((l) => l.doc) 97 + } 98 + leaflet_id={leaflet.root_entity} 99 + loggedIn={!!identity} 100 + /> 101 + </StaticLeafletDataContext> 79 102 </ReplicacheProvider> 80 103 ))} 81 104 </div>
+17 -8
components/PageSWRDataProvider.tsx
··· 6 6 import { callRPC } from "app/api/rpc/client"; 7 7 import { getPollData } from "actions/pollActions"; 8 8 import type { GetLeafletDataReturnType } from "app/api/rpc/[command]/get_leaflet_data"; 9 + import { createContext, useContext } from "react"; 9 10 11 + export const StaticLeafletDataContext = createContext< 12 + null | GetLeafletDataReturnType["result"]["data"] 13 + >(null); 10 14 export function PageSWRDataProvider(props: { 11 15 leaflet_id: string; 12 16 leaflet_data: GetLeafletDataReturnType["result"]; ··· 20 24 fallback: { 21 25 rsvp_data: props.rsvp_data, 22 26 poll_data: props.poll_data, 23 - [`${props.leaflet_id}-leaflet_data`]: props.leaflet_data, 27 + [`${props.leaflet_id}-leaflet_data`]: props.leaflet_data.data, 24 28 }, 25 29 }} 26 30 > ··· 48 52 49 53 let useLeafletData = () => { 50 54 let { permission_token } = useReplicache(); 51 - return useSWR(`${permission_token.id}-leaflet_data`, async () => 52 - permission_token.id 53 - ? (await callRPC("get_leaflet_data", { token_id: permission_token.id })) 54 - ?.result 55 - : undefined, 55 + let staticLeafletData = useContext(StaticLeafletDataContext); 56 + let res = useSWR( 57 + staticLeafletData ? null : `${permission_token.id}-leaflet_data`, 58 + async () => 59 + permission_token.id 60 + ? (await callRPC("get_leaflet_data", { token_id: permission_token.id })) 61 + ?.result.data 62 + : undefined, 56 63 ); 64 + if (staticLeafletData) return { data: staticLeafletData, mutate: res.mutate }; 65 + return res; 57 66 }; 58 67 export function useLeafletPublicationData() { 59 68 let { data, mutate } = useLeafletData(); 60 69 return { 61 - data: data?.data?.leaflets_in_publications?.[0] || null, 70 + data: data?.leaflets_in_publications?.[0] || null, 62 71 mutate, 63 72 }; 64 73 } 65 74 export function useLeafletDomains() { 66 75 let { data, mutate } = useLeafletData(); 67 - return { data: data?.data?.custom_domain_routes, mutate: mutate }; 76 + return { data: data?.custom_domain_routes, mutate: mutate }; 68 77 }