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