tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
a tool for shared writing and social publishing
284
fork
atom
overview
issues
27
pulls
pipelines
add basic looseleaf page
awarm.space
2 months ago
8ea2c33f
1138f273
+56
-3
2 changed files
expand all
collapse all
unified
split
app
(home-pages)
home
HomeLayout.tsx
looseleafs
LooseleafsLayout.tsx
+1
-1
app/(home-pages)/home/HomeLayout.tsx
···
31
PublicationBanner,
32
} from "./HomeEmpty/HomeEmpty";
33
34
-
type Leaflet = {
35
added_at: string;
36
token: PermissionToken & {
37
leaflets_in_publications?: Exclude<
···
31
PublicationBanner,
32
} from "./HomeEmpty/HomeEmpty";
33
34
+
export type Leaflet = {
35
added_at: string;
36
token: PermissionToken & {
37
leaflets_in_publications?: Exclude<
+55
-2
app/(home-pages)/looseleafs/LooseleafsLayout.tsx
···
3
import { useCardBorderHidden } from "components/Pages/useCardBorderHidden";
4
import { useState } from "react";
5
import { useDebouncedEffect } from "src/hooks/useDebouncedEffect";
6
-
import { Fact } from "src/replicache";
7
import { Attribute } from "src/replicache/attributes";
8
import { Actions } from "../home/Actions/Actions";
0
0
0
0
0
9
10
export const LooseleafsLayout = (props: {
11
entityID: string | null;
···
58
searchValue: string;
59
cardBorderHidden: boolean;
60
}) => {
61
-
return <div>hello</div>;
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
62
};
···
3
import { useCardBorderHidden } from "components/Pages/useCardBorderHidden";
4
import { useState } from "react";
5
import { useDebouncedEffect } from "src/hooks/useDebouncedEffect";
6
+
import { Fact, PermissionToken } from "src/replicache";
7
import { Attribute } from "src/replicache/attributes";
8
import { Actions } from "../home/Actions/Actions";
9
+
import { callRPC } from "app/api/rpc/client";
10
+
import { useIdentityData } from "components/IdentityProvider";
11
+
import useSWR from "swr";
12
+
import { getHomeDocs } from "../home/storage";
13
+
import { Leaflet, LeafletList } from "../home/HomeLayout";
14
15
export const LooseleafsLayout = (props: {
16
entityID: string | null;
···
63
searchValue: string;
64
cardBorderHidden: boolean;
65
}) => {
66
+
let { identity } = useIdentityData();
67
+
let { data: initialFacts } = useSWR(
68
+
"home-leaflet-data",
69
+
async () => {
70
+
if (identity) {
71
+
let { result } = await callRPC("getFactsFromHomeLeaflets", {
72
+
tokens: identity.permission_token_on_homepage.map(
73
+
(ptrh) => ptrh.permission_tokens.root_entity,
74
+
),
75
+
});
76
+
let titles = {
77
+
...result.titles,
78
+
...identity.permission_token_on_homepage.reduce(
79
+
(acc, tok) => {
80
+
let title =
81
+
tok.permission_tokens.leaflets_in_publications[0]?.title;
82
+
if (title) acc[tok.permission_tokens.root_entity] = title;
83
+
return acc;
84
+
},
85
+
{} as { [k: string]: string },
86
+
),
87
+
};
88
+
return { ...result, titles };
89
+
}
90
+
},
91
+
{ fallbackData: { facts: props.initialFacts, titles: props.titles } },
92
+
);
93
+
94
+
let leaflets: Leaflet[] = identity
95
+
? identity.permission_token_on_homepage
96
+
.filter(
97
+
(ptoh) => ptoh.permission_tokens.leaflets_to_documents.length > 0,
98
+
)
99
+
.map((ptoh) => ({
100
+
added_at: ptoh.created_at,
101
+
token: ptoh.permission_tokens as PermissionToken,
102
+
}))
103
+
: [];
104
+
return (
105
+
<LeafletList
106
+
defaultDisplay="list"
107
+
searchValue={props.searchValue}
108
+
leaflets={leaflets}
109
+
titles={initialFacts?.titles || {}}
110
+
cardBorderHidden={props.cardBorderHidden}
111
+
initialFacts={initialFacts?.facts || {}}
112
+
showPreview
113
+
/>
114
+
);
115
};