a tool for shared writing and social publishing

get pub data from related entity_sets if neccessary

+33 -4
+23 -3
app/api/rpc/[command]/get_leaflet_data.ts
··· 5 5 export type GetLeafletDataReturnType = Awaited< 6 6 ReturnType<(typeof get_leaflet_data)["handler"]> 7 7 >; 8 + 9 + const leaflets_in_publications_query = `leaflets_in_publications(*, publications(*, documents_in_publications(count)), documents(*))`; 8 10 export const get_leaflet_data = makeRoute({ 9 11 route: "get_leaflet_data", 10 12 input: z.object({ 11 13 token_id: z.string(), 12 14 }), 15 + 13 16 handler: async ({ token_id }, { supabase }: Pick<Env, "supabase">) => { 14 17 let res = await supabase 15 18 .from("permission_tokens") 16 19 .select( 17 20 `*, 18 - permission_token_rights(*), 21 + permission_token_rights(*, entity_sets(permission_tokens(${leaflets_in_publications_query}))), 19 22 custom_domain_routes!custom_domain_routes_edit_permission_token_fkey(*), 20 - leaflets_in_publications(*, publications(*, documents_in_publications(count)), documents(*)) `, 23 + ${leaflets_in_publications_query}`, 21 24 ) 22 25 .eq("id", token_id) 23 26 .single(); 24 27 25 - return { result: res }; 28 + type t = typeof res; 29 + type data = Exclude<t["data"], null>; 30 + 31 + //All of these shenanigans are to make entity_set optional so that we don't have to write it when we create this data elsewhere, mainly in LeafletList 32 + return { 33 + result: res as Omit<t, "data"> & { 34 + data: 35 + | null 36 + | (Omit<data, "permission_token_rights"> & { 37 + permission_token_rights: (Omit< 38 + data["permission_token_rights"][0], 39 + "entity_sets" 40 + > & { 41 + entity_sets?: data["permission_token_rights"][0]["entity_sets"]; 42 + })[]; 43 + }); 44 + }, 45 + }; 26 46 }, 27 47 });
+6 -1
components/PageSWRDataProvider.tsx
··· 67 67 export function useLeafletPublicationData() { 68 68 let { data, mutate } = useLeafletData(); 69 69 return { 70 - data: data?.leaflets_in_publications?.[0] || null, 70 + data: 71 + data?.leaflets_in_publications?.[0] || 72 + data?.permission_token_rights[0].entity_sets?.permission_tokens?.find( 73 + (p) => p.leaflets_in_publications.length, 74 + )?.leaflets_in_publications?.[0] || 75 + null, 71 76 mutate, 72 77 }; 73 78 }
+4
components/Pages/PublicationMetadata.tsx
··· 17 17 getPublicationURL, 18 18 } from "app/lish/createPub/getPublicationURL"; 19 19 import { useSubscribe } from "src/replicache/useSubscribe"; 20 + import { useEntitySetContext } from "components/EntitySetProvider"; 20 21 export const PublicationMetadata = ({ 21 22 cardBorderHidden, 22 23 }: { ··· 28 29 let description = useSubscribe(rep, (tx) => 29 30 tx.get<string>("publication_description"), 30 31 ); 32 + let { permissions } = useEntitySetContext(); 31 33 32 34 let record = pub?.documents?.data as PubLeafletDocument.Record | null; 33 35 let publishedAt = record?.publishedAt; ··· 56 58 </div> 57 59 </div> 58 60 <AsyncValueAutosizeTextarea 61 + disabled={!permissions.write} 59 62 className="text-xl font-bold outline-none bg-transparent" 60 63 value={title} 61 64 onChange={async (e) => { ··· 67 70 placeholder="Untitled" 68 71 /> 69 72 <AsyncValueAutosizeTextarea 73 + disabled={!permissions.write} 70 74 placeholder="add an optional description..." 71 75 className="italic text-secondary outline-none bg-transparent" 72 76 value={description}