tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
28
pulls
pipelines
get theme from correct place and fix pub metadata
awarm.space
3 months ago
37cdeb97
49372abb
+64
-29
5 changed files
expand all
collapse all
unified
split
app
[leaflet_id]
page.tsx
lish
[did]
[publication]
[rkey]
PublishedPageBlock.tsx
getPostPageData.ts
components
PageSWRDataProvider.tsx
src
utils
getPublicationMetadataFromLeafletData.ts
+2
-5
app/[leaflet_id]/page.tsx
···
13
13
import { supabaseServerClient } from "supabase/serverClient";
14
14
import { get_leaflet_data } from "app/api/rpc/[command]/get_leaflet_data";
15
15
import { NotFoundLayout } from "components/PageLayouts/NotFoundLayout";
16
16
+
import { getPublicationMetadataFromLeafletData } from "src/utils/getPublicationMetadataFromLeafletData";
16
17
17
18
export const preferredRegion = ["sfo1"];
18
19
export const dynamic = "force-dynamic";
···
70
71
);
71
72
let rootEntity = res.data?.root_entity;
72
73
if (!rootEntity || !res.data) return { title: "Leaflet not found" };
73
73
-
let publication_data =
74
74
-
res.data?.leaflets_in_publications?.[0] ||
75
75
-
res.data?.permission_token_rights[0].entity_sets?.permission_tokens?.find(
76
76
-
(p) => p.leaflets_in_publications.length,
77
77
-
)?.leaflets_in_publications?.[0];
74
74
+
let publication_data = getPublicationMetadataFromLeafletData(res.data);
78
75
if (publication_data) {
79
76
return {
80
77
title: publication_data.title || "Untitled",
+2
-3
app/lish/[did]/[publication]/[rkey]/PublishedPageBlock.tsx
···
151
151
let previewRef = useRef<HTMLDivElement | null>(null);
152
152
let { rootEntity } = useReplicache();
153
153
let data = useContext(PostPageContext);
154
154
-
let theme = data?.documents_in_publications[0]?.publications
155
155
-
?.record as PubLeafletPublication.Record;
154
154
+
let theme = data?.theme;
156
155
let pageWidth = `var(--page-width-unitless)`;
157
157
-
let cardBorderHidden = !theme.theme?.showPageBackground;
156
156
+
let cardBorderHidden = !theme?.showPageBackground;
158
157
return (
159
158
<div
160
159
ref={previewRef}
+8
-1
app/lish/[did]/[publication]/[rkey]/getPostPageData.ts
···
1
1
import { supabaseServerClient } from "supabase/serverClient";
2
2
import { AtUri } from "@atproto/syntax";
3
3
-
import { PubLeafletPublication } from "lexicons/api";
3
3
+
import { PubLeafletDocument, PubLeafletPublication } from "lexicons/api";
4
4
5
5
export async function getPostPageData(uri: string) {
6
6
let { data: document } = await supabaseServerClient
···
43
43
...uniqueBacklinks,
44
44
];
45
45
46
46
+
let theme =
47
47
+
(
48
48
+
document?.documents_in_publications[0]?.publications
49
49
+
?.record as PubLeafletPublication.Record
50
50
+
)?.theme || (document?.data as PubLeafletDocument.Record)?.theme;
51
51
+
46
52
return {
47
53
...document,
48
54
quotesAndMentions,
55
55
+
theme,
49
56
};
50
57
}
51
58
+2
-20
components/PageSWRDataProvider.tsx
···
7
7
import { getPollData } from "actions/pollActions";
8
8
import type { GetLeafletDataReturnType } from "app/api/rpc/[command]/get_leaflet_data";
9
9
import { createContext, useContext } from "react";
10
10
+
import { getPublicationMetadataFromLeafletData } from "src/utils/getPublicationMetadataFromLeafletData";
10
11
11
12
export const StaticLeafletDataContext = createContext<
12
13
null | GetLeafletDataReturnType["result"]["data"]
···
68
69
let { data, mutate } = useLeafletData();
69
70
70
71
// First check for leaflets in publications
71
71
-
let pubData =
72
72
-
data?.leaflets_in_publications?.[0] ||
73
73
-
data?.permission_token_rights[0].entity_sets?.permission_tokens?.find(
74
74
-
(p) => p.leaflets_in_publications.length,
75
75
-
)?.leaflets_in_publications?.[0];
76
76
-
77
77
-
// If not found, check for standalone documents
78
78
-
let standaloneDoc =
79
79
-
data?.leaflets_to_documents?.[0] ||
80
80
-
data?.permission_token_rights[0].entity_sets?.permission_tokens.find(
81
81
-
(p) => p.leaflets_to_documents.length,
82
82
-
)?.leaflets_to_documents?.[0];
83
83
-
if (!pubData && standaloneDoc) {
84
84
-
// Transform standalone document data to match the expected format
85
85
-
pubData = {
86
86
-
...standaloneDoc,
87
87
-
publications: null, // No publication for standalone docs
88
88
-
doc: standaloneDoc.document,
89
89
-
} as any;
90
90
-
}
72
72
+
let pubData = getPublicationMetadataFromLeafletData(data);
91
73
92
74
return {
93
75
data: pubData || null,
+50
src/utils/getPublicationMetadataFromLeafletData.ts
···
1
1
+
import { GetLeafletDataReturnType } from "app/api/rpc/[command]/get_leaflet_data";
2
2
+
import { Json } from "supabase/database.types";
3
3
+
4
4
+
export function getPublicationMetadataFromLeafletData(
5
5
+
data?: GetLeafletDataReturnType["result"]["data"],
6
6
+
) {
7
7
+
if (!data) return null;
8
8
+
9
9
+
let pubData:
10
10
+
| {
11
11
+
description: string;
12
12
+
title: string;
13
13
+
leaflet: string;
14
14
+
doc: string | null;
15
15
+
publications: {
16
16
+
identity_did: string;
17
17
+
name: string;
18
18
+
indexed_at: string;
19
19
+
record: Json | null;
20
20
+
uri: string;
21
21
+
} | null;
22
22
+
documents: {
23
23
+
data: Json;
24
24
+
indexed_at: string;
25
25
+
uri: string;
26
26
+
} | null;
27
27
+
}
28
28
+
| undefined
29
29
+
| null =
30
30
+
data?.leaflets_in_publications?.[0] ||
31
31
+
data?.permission_token_rights[0].entity_sets?.permission_tokens?.find(
32
32
+
(p) => p.leaflets_in_publications.length,
33
33
+
)?.leaflets_in_publications?.[0];
34
34
+
35
35
+
// If not found, check for standalone documents
36
36
+
let standaloneDoc =
37
37
+
data?.leaflets_to_documents?.[0] ||
38
38
+
data?.permission_token_rights[0].entity_sets?.permission_tokens.find(
39
39
+
(p) => p.leaflets_to_documents.length,
40
40
+
)?.leaflets_to_documents?.[0];
41
41
+
if (!pubData && standaloneDoc) {
42
42
+
// Transform standalone document data to match the expected format
43
43
+
pubData = {
44
44
+
...standaloneDoc,
45
45
+
publications: null, // No publication for standalone docs
46
46
+
doc: standaloneDoc.document,
47
47
+
};
48
48
+
}
49
49
+
return pubData;
50
50
+
}