a tool for shared writing and social publishing
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 } from "./ReaderContent";
15import { SubscriptionsContent } from "./SubscriptionsContent";
16import { getReaderFeed } from "./getReaderFeed";
17import { getSubscriptions } from "./getSubscriptions";
18
19export default async function Reader(props: {}) {
20 let cookieStore = await cookies();
21 let auth_res = await getIdentityData();
22 let identity: string | undefined;
23 let permission_token = auth_res?.home_leaflet;
24 if (!permission_token)
25 return (
26 <NotFoundLayout>
27 <p className="font-bold">Sorry, we can't find this page!</p>
28 <p>
29 This may be a glitch on our end. If the issue persists please{" "}
30 <a href="mailto:contact@leaflet.pub">send us a note</a>.
31 </p>
32 </NotFoundLayout>
33 );
34 let [homeLeafletFacts] = await Promise.all([
35 supabaseServerClient.rpc("get_facts", {
36 root: permission_token.root_entity,
37 }),
38 ]);
39 let initialFacts =
40 (homeLeafletFacts.data as unknown as Fact<Attribute>[]) || [];
41 let root_entity = permission_token.root_entity;
42
43 if (!auth_res?.atp_did) return;
44 let posts = await getReaderFeed();
45 let publications = await getSubscriptions();
46 return (
47 <ReplicacheProvider
48 rootEntity={root_entity}
49 token={permission_token}
50 name={root_entity}
51 initialFacts={initialFacts}
52 >
53 <EntitySetProvider
54 set={permission_token.permission_token_rights[0].entity_set}
55 >
56 <ThemeProvider entityID={root_entity}>
57 <ThemeBackgroundProvider entityID={root_entity}>
58 <DashboardLayout
59 id="reader"
60 cardBorderHidden={false}
61 currentPage="reader"
62 defaultTab="Read"
63 actions={null}
64 tabs={{
65 Read: {
66 controls: null,
67 content: (
68 <ReaderContent
69 root_entity={root_entity}
70 nextCursor={posts.nextCursor}
71 posts={posts.posts}
72 />
73 ),
74 },
75 Subscriptions: {
76 controls: null,
77 content: (
78 <SubscriptionsContent
79 publications={publications.subscriptions}
80 nextCursor={publications.nextCursor}
81 />
82 ),
83 },
84 }}
85 />
86 </ThemeBackgroundProvider>
87 </ThemeProvider>
88 </EntitySetProvider>
89 </ReplicacheProvider>
90 );
91}