a tool for shared writing and social publishing
0
fork

Configure Feed

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

pass down leaflet data via swr

+75 -55
-3
app/[leaflet_id]/Sidebar.tsx
··· 4 4 import { HelpPopover } from "components/HelpPopover"; 5 5 import { HomeButton } from "components/HomeButton"; 6 6 import { Media } from "components/Media"; 7 - import { usePublicationContext } from "components/Providers/PublicationContext"; 8 7 import { ShareOptions } from "components/ShareOptions"; 9 - import { PublishToPublication } from "components/ShareOptions/PublicationOptions"; 10 8 import { ThemePopover } from "components/ThemeManager/ThemeSetter"; 11 9 import { Watermark } from "components/Watermark"; 12 10 import { useUIState } from "src/useUIState"; 13 11 14 12 export function LeafletSidebar(props: { leaflet_id: string }) { 15 13 let entity_set = useEntitySetContext(); 16 - let publication = usePublicationContext(); 17 14 return ( 18 15 <div 19 16 className="spacer flex justify-end items-start"
+15 -27
app/[leaflet_id]/page.tsx
··· 3 3 import * as base64 from "base64-js"; 4 4 5 5 import { Fact } from "src/replicache"; 6 - import { Database } from "../../supabase/database.types"; 7 6 import { Attributes } from "src/replicache/attributes"; 8 - import { createServerClient } from "@supabase/ssr"; 9 7 import { YJSFragmentToString } from "components/Blocks/TextBlock/RenderYJSFragment"; 10 8 import { Leaflet } from "./Leaflet"; 11 9 import { scanIndexLocal } from "src/replicache/utils"; ··· 13 11 import { PageSWRDataProvider } from "components/PageSWRDataProvider"; 14 12 import { getPollData } from "actions/pollActions"; 15 13 import { PublicationContextProvider } from "components/Providers/PublicationContext"; 14 + import { supabaseServerClient } from "supabase/serverClient"; 15 + import { get_leaflet_data } from "app/api/rpc/[command]/get_leaflet_data"; 16 16 17 17 export const preferredRegion = ["sfo1"]; 18 18 export const dynamic = "force-dynamic"; 19 19 export const fetchCache = "force-no-store"; 20 20 21 - let supabase = createServerClient<Database>( 22 - process.env.NEXT_PUBLIC_SUPABASE_API_URL as string, 23 - process.env.SUPABASE_SERVICE_ROLE_KEY as string, 24 - { cookies: {} }, 25 - ); 26 21 type Props = { 27 22 // this is now a token id not leaflet! Should probs rename 28 23 params: Promise<{ leaflet_id: string }>; 29 24 }; 30 25 export default async function LeafletPage(props: Props) { 31 - let res = await supabase 32 - .from("permission_tokens") 33 - .select( 34 - "*, permission_token_rights(*), custom_domain_routes!custom_domain_routes_edit_permission_token_fkey(*),leaflets_in_publications(publications(*)) ", 35 - ) 36 - .eq("id", (await props.params).leaflet_id) 37 - .single(); 26 + let { result: res } = await get_leaflet_data.handler( 27 + { token_id: (await props.params).leaflet_id }, 28 + { supabase: supabaseServerClient }, 29 + ); 38 30 let rootEntity = res.data?.root_entity; 39 31 if (!rootEntity || !res.data || res.data.blocked_by_admin) 40 32 return ( ··· 55 47 ); 56 48 57 49 let [{ data }, rsvp_data, poll_data] = await Promise.all([ 58 - supabase.rpc("get_facts", { 50 + supabaseServerClient.rpc("get_facts", { 59 51 root: rootEntity, 60 52 }), 61 53 getRSVPData(res.data.permission_token_rights.map((ptr) => ptr.entity_set)), ··· 67 59 rsvp_data={rsvp_data} 68 60 poll_data={poll_data} 69 61 leaflet_id={res.data.id} 70 - domains={res.data.custom_domain_routes} 62 + leaflet_data={res} 71 63 > 72 - <PublicationContextProvider 73 - publication={res.data.leaflets_in_publications[0]?.publications} 74 - > 75 - <Leaflet 76 - initialFacts={initialFacts} 77 - leaflet_id={rootEntity} 78 - token={res.data} 79 - /> 80 - </PublicationContextProvider> 64 + <Leaflet 65 + initialFacts={initialFacts} 66 + leaflet_id={rootEntity} 67 + token={res.data} 68 + /> 81 69 </PageSWRDataProvider> 82 70 ); 83 71 } 84 72 85 73 export async function generateMetadata(props: Props): Promise<Metadata> { 86 - let res = await supabase 74 + let res = await supabaseServerClient 87 75 .from("permission_tokens") 88 76 .select("*, permission_token_rights(*)") 89 77 .eq("id", (await props.params).leaflet_id) 90 78 .single(); 91 79 let rootEntity = res.data?.root_entity; 92 80 if (!rootEntity || !res.data) return { title: "Leaflet not found" }; 93 - let { data } = await supabase.rpc("get_facts", { 81 + let { data } = await supabaseServerClient.rpc("get_facts", { 94 82 root: rootEntity, 95 83 }); 96 84 let initialFacts = (data as unknown as Fact<keyof typeof Attributes>[]) || [];
-15
app/api/rpc/[command]/domain_routes.ts
··· 25 25 } 26 26 }, 27 27 }); 28 - 29 - export const get_leaflet_domains = makeRoute({ 30 - route: "get_leaflet_domains", 31 - input: z.object({ id: z.string() }), 32 - handler: async ({ id }, { supabase }: Env) => { 33 - let res = await supabase 34 - .from("permission_tokens") 35 - .select( 36 - "*, permission_token_rights(*), custom_domain_routes!custom_domain_routes_edit_permission_token_fkey(*) ", 37 - ) 38 - .eq("id", id) 39 - .single(); 40 - return res.data?.custom_domain_routes || null; 41 - }, 42 - });
+27
app/api/rpc/[command]/get_leaflet_data.ts
··· 1 + import { z } from "zod"; 2 + import { makeRoute } from "../lib"; 3 + import { Env } from "./route"; 4 + 5 + export type GetLeafletDataReturnType = Awaited< 6 + ReturnType<(typeof get_leaflet_data)["handler"]> 7 + >; 8 + export const get_leaflet_data = makeRoute({ 9 + route: "get_leaflet_data", 10 + input: z.object({ 11 + token_id: z.string(), 12 + }), 13 + handler: async ({ token_id }, { supabase }: Pick<Env, "supabase">) => { 14 + let res = await supabase 15 + .from("permission_tokens") 16 + .select( 17 + `*, 18 + permission_token_rights(*), 19 + custom_domain_routes!custom_domain_routes_edit_permission_token_fkey(*), 20 + leaflets_in_publications(*, publications(*)) `, 21 + ) 22 + .eq("id", token_id) 23 + .single(); 24 + 25 + return { result: res }; 26 + }, 27 + });
+3 -2
app/api/rpc/[command]/route.ts
··· 7 7 import { pull } from "./pull"; 8 8 import { getFactsFromHomeLeaflets } from "./getFactsFromHomeLeaflets"; 9 9 import { Vercel } from "@vercel/sdk"; 10 - import { get_domain_status, get_leaflet_domains } from "./domain_routes"; 10 + import { get_domain_status } from "./domain_routes"; 11 + import { get_leaflet_data } from "./get_leaflet_data"; 11 12 12 13 const client = postgres(process.env.DB_URL as string, { idle_timeout: 5 }); 13 14 let supabase = createClient<Database>( ··· 31 32 pull, 32 33 getFactsFromHomeLeaflets, 33 34 get_domain_status, 34 - get_leaflet_domains, 35 + get_leaflet_data, 35 36 ]; 36 37 export async function POST( 37 38 req: Request,
+18 -5
components/PageSWRDataProvider.tsx
··· 5 5 import useSWR from "swr"; 6 6 import { callRPC } from "app/api/rpc/client"; 7 7 import { getPollData } from "actions/pollActions"; 8 + import type { GetLeafletDataReturnType } from "app/api/rpc/[command]/get_leaflet_data"; 8 9 9 10 export function PageSWRDataProvider(props: { 10 11 leaflet_id: string; 11 - domains: { domain: string }[]; 12 + leaflet_data: GetLeafletDataReturnType["result"]; 12 13 rsvp_data: Awaited<ReturnType<typeof getRSVPData>>; 13 14 poll_data: Awaited<ReturnType<typeof getPollData>>; 14 15 children: React.ReactNode; ··· 19 20 fallback: { 20 21 rsvp_data: props.rsvp_data, 21 22 poll_data: props.poll_data, 22 - [`${props.leaflet_id}-domains`]: props.domains, 23 + [`${props.leaflet_id}-leaflet_data`]: props.leaflet_data, 23 24 }, 24 25 }} 25 26 > ··· 44 45 ), 45 46 ); 46 47 } 47 - export function useLeafletDomains() { 48 + 49 + let useLeafletData = () => { 48 50 let { permission_token } = useReplicache(); 49 51 return useSWR( 50 - `${permission_token.id}-domains`, 52 + `${permission_token.id}-leaflet_data`, 51 53 async () => 52 - await callRPC("get_leaflet_domains", { id: permission_token.id }), 54 + (await callRPC("get_leaflet_data", { token_id: permission_token.id })) 55 + ?.result, 53 56 ); 57 + }; 58 + export function useLeafletPublicationData() { 59 + let { data, mutate } = useLeafletData(); 60 + return { 61 + data: data?.data?.leaflets_in_publications, 62 + }; 63 + } 64 + export function useLeafletDomains() { 65 + let { data, mutate } = useLeafletData(); 66 + return { data: data?.data?.custom_domain_routes, mutate: mutate }; 54 67 }
-3
components/Pages/index.tsx
··· 30 30 import { PageShareMenu } from "./PageShareMenu"; 31 31 import { scrollIntoViewIfNeeded } from "src/utils/scrollIntoViewIfNeeded"; 32 32 import { useUndoState } from "src/undoManager"; 33 - import { usePublicationContext } from "components/Providers/PublicationContext"; 34 33 import { CloseTiny } from "components/Icons/CloseTiny"; 35 34 import { MoreOptionsTiny } from "components/Icons/MoreOptionsTiny"; 36 35 import { PaintSmall } from "components/Icons/PaintSmall"; ··· 43 42 let params = useSearchParams(); 44 43 let queryRoot = params.get("page"); 45 44 let firstPage = queryRoot || rootPage?.data.value || props.rootPage; 46 - let entity_set = useEntitySetContext(); 47 - let publication = usePublicationContext(); 48 45 49 46 return ( 50 47 <>
+3
drizzle/schema.ts
··· 29 29 indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 30 30 name: text("name").notNull(), 31 31 identity_did: text("identity_did").notNull(), 32 + record: jsonb("record"), 32 33 }); 33 34 34 35 export const facts = pgTable("facts", { ··· 196 197 publication: text("publication").notNull().references(() => publications.uri), 197 198 doc: text("doc").default('').references(() => documents.uri), 198 199 leaflet: uuid("leaflet").notNull().references(() => permission_tokens.id), 200 + description: text("description").default('').notNull(), 201 + title: text("title").default('').notNull(), 199 202 }, 200 203 (table) => { 201 204 return {
+9
supabase/database.types.ts
··· 356 356 } 357 357 leaflets_in_publications: { 358 358 Row: { 359 + description: string 359 360 doc: string | null 360 361 leaflet: string 361 362 publication: string 363 + title: string 362 364 } 363 365 Insert: { 366 + description?: string 364 367 doc?: string | null 365 368 leaflet: string 366 369 publication: string 370 + title?: string 367 371 } 368 372 Update: { 373 + description?: string 369 374 doc?: string | null 370 375 leaflet?: string 371 376 publication?: string 377 + title?: string 372 378 } 373 379 Relationships: [ 374 380 { ··· 640 646 identity_did: string 641 647 indexed_at: string 642 648 name: string 649 + record: Json | null 643 650 uri: string 644 651 } 645 652 Insert: { 646 653 identity_did: string 647 654 indexed_at?: string 648 655 name: string 656 + record?: Json | null 649 657 uri: string 650 658 } 651 659 Update: { 652 660 identity_did?: string 653 661 indexed_at?: string 654 662 name?: string 663 + record?: Json | null 655 664 uri?: string 656 665 } 657 666 Relationships: []