a tool for shared writing and social publishing
at feature/page-blocks 104 lines 3.3 kB view raw
1import { cookies } from "next/headers"; 2import { Fact, ReplicacheProvider } from "src/replicache"; 3import type { Attribute } from "src/replicache/attributes"; 4import { 5 ThemeBackgroundProvider, 6 ThemeProvider, 7} from "components/ThemeManager/ThemeProvider"; 8import { EntitySetProvider } from "components/EntitySetProvider"; 9import { getIdentityData } from "actions/getIdentityData"; 10import { supabaseServerClient } from "supabase/serverClient"; 11 12import { NotFoundLayout } from "components/PageLayouts/NotFoundLayout"; 13import { DashboardLayout } from "components/PageLayouts/DashboardLayout"; 14import { ReaderContent, ReaderEmpty } from "./ReaderContent"; 15import { 16 SubscriptionsContent, 17 SubscriptionsEmpty, 18} from "./SubscriptionsContent"; 19import { getReaderFeed } from "./getReaderFeed"; 20import { getSubscriptions } from "./getSubscriptions"; 21 22export default async function Reader(props: {}) { 23 let cookieStore = await cookies(); 24 let auth_res = await getIdentityData(); 25 let identity: string | undefined; 26 let permission_token = auth_res?.home_leaflet; 27 if (!permission_token) 28 return ( 29 <DashboardLayout 30 id="reader" 31 cardBorderHidden={false} 32 currentPage="reader" 33 defaultTab="Read" 34 actions={null} 35 tabs={{ 36 Read: { 37 controls: null, 38 content: <ReaderEmpty />, 39 }, 40 Subscriptions: { 41 controls: null, 42 content: <SubscriptionsEmpty />, 43 }, 44 }} 45 /> 46 ); 47 let [homeLeafletFacts] = await Promise.all([ 48 supabaseServerClient.rpc("get_facts", { 49 root: permission_token.root_entity, 50 }), 51 ]); 52 let initialFacts = 53 (homeLeafletFacts.data as unknown as Fact<Attribute>[]) || []; 54 let root_entity = permission_token.root_entity; 55 56 if (!auth_res?.atp_did) return; 57 let posts = await getReaderFeed(); 58 let publications = await getSubscriptions(); 59 return ( 60 <ReplicacheProvider 61 rootEntity={root_entity} 62 token={permission_token} 63 name={root_entity} 64 initialFacts={initialFacts} 65 > 66 <EntitySetProvider 67 set={permission_token.permission_token_rights[0].entity_set} 68 > 69 <ThemeProvider entityID={root_entity}> 70 <ThemeBackgroundProvider entityID={root_entity}> 71 <DashboardLayout 72 id="reader" 73 cardBorderHidden={false} 74 currentPage="reader" 75 defaultTab="Read" 76 actions={null} 77 tabs={{ 78 Read: { 79 controls: null, 80 content: ( 81 <ReaderContent 82 root_entity={root_entity} 83 nextCursor={posts.nextCursor} 84 posts={posts.posts} 85 /> 86 ), 87 }, 88 Subscriptions: { 89 controls: null, 90 content: ( 91 <SubscriptionsContent 92 publications={publications.subscriptions} 93 nextCursor={publications.nextCursor} 94 /> 95 ), 96 }, 97 }} 98 /> 99 </ThemeBackgroundProvider> 100 </ThemeProvider> 101 </EntitySetProvider> 102 </ReplicacheProvider> 103 ); 104}