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 pub data from related entity_sets if neccessary
awarm.space
8 months ago
83cf9374
8a411f0b
+33
-4
3 changed files
expand all
collapse all
unified
split
app
api
rpc
[command]
get_leaflet_data.ts
components
PageSWRDataProvider.tsx
Pages
PublicationMetadata.tsx
+23
-3
app/api/rpc/[command]/get_leaflet_data.ts
···
5
5
export type GetLeafletDataReturnType = Awaited<
6
6
ReturnType<(typeof get_leaflet_data)["handler"]>
7
7
>;
8
8
+
9
9
+
const leaflets_in_publications_query = `leaflets_in_publications(*, publications(*, documents_in_publications(count)), documents(*))`;
8
10
export const get_leaflet_data = makeRoute({
9
11
route: "get_leaflet_data",
10
12
input: z.object({
11
13
token_id: z.string(),
12
14
}),
15
15
+
13
16
handler: async ({ token_id }, { supabase }: Pick<Env, "supabase">) => {
14
17
let res = await supabase
15
18
.from("permission_tokens")
16
19
.select(
17
20
`*,
18
18
-
permission_token_rights(*),
21
21
+
permission_token_rights(*, entity_sets(permission_tokens(${leaflets_in_publications_query}))),
19
22
custom_domain_routes!custom_domain_routes_edit_permission_token_fkey(*),
20
20
-
leaflets_in_publications(*, publications(*, documents_in_publications(count)), documents(*)) `,
23
23
+
${leaflets_in_publications_query}`,
21
24
)
22
25
.eq("id", token_id)
23
26
.single();
24
27
25
25
-
return { result: res };
28
28
+
type t = typeof res;
29
29
+
type data = Exclude<t["data"], null>;
30
30
+
31
31
+
//All of these shenanigans are to make entity_set optional so that we don't have to write it when we create this data elsewhere, mainly in LeafletList
32
32
+
return {
33
33
+
result: res as Omit<t, "data"> & {
34
34
+
data:
35
35
+
| null
36
36
+
| (Omit<data, "permission_token_rights"> & {
37
37
+
permission_token_rights: (Omit<
38
38
+
data["permission_token_rights"][0],
39
39
+
"entity_sets"
40
40
+
> & {
41
41
+
entity_sets?: data["permission_token_rights"][0]["entity_sets"];
42
42
+
})[];
43
43
+
});
44
44
+
},
45
45
+
};
26
46
},
27
47
});
+6
-1
components/PageSWRDataProvider.tsx
···
67
67
export function useLeafletPublicationData() {
68
68
let { data, mutate } = useLeafletData();
69
69
return {
70
70
-
data: data?.leaflets_in_publications?.[0] || null,
70
70
+
data:
71
71
+
data?.leaflets_in_publications?.[0] ||
72
72
+
data?.permission_token_rights[0].entity_sets?.permission_tokens?.find(
73
73
+
(p) => p.leaflets_in_publications.length,
74
74
+
)?.leaflets_in_publications?.[0] ||
75
75
+
null,
71
76
mutate,
72
77
};
73
78
}
+4
components/Pages/PublicationMetadata.tsx
···
17
17
getPublicationURL,
18
18
} from "app/lish/createPub/getPublicationURL";
19
19
import { useSubscribe } from "src/replicache/useSubscribe";
20
20
+
import { useEntitySetContext } from "components/EntitySetProvider";
20
21
export const PublicationMetadata = ({
21
22
cardBorderHidden,
22
23
}: {
···
28
29
let description = useSubscribe(rep, (tx) =>
29
30
tx.get<string>("publication_description"),
30
31
);
32
32
+
let { permissions } = useEntitySetContext();
31
33
32
34
let record = pub?.documents?.data as PubLeafletDocument.Record | null;
33
35
let publishedAt = record?.publishedAt;
···
56
58
</div>
57
59
</div>
58
60
<AsyncValueAutosizeTextarea
61
61
+
disabled={!permissions.write}
59
62
className="text-xl font-bold outline-none bg-transparent"
60
63
value={title}
61
64
onChange={async (e) => {
···
67
70
placeholder="Untitled"
68
71
/>
69
72
<AsyncValueAutosizeTextarea
73
73
+
disabled={!permissions.write}
70
74
placeholder="add an optional description..."
71
75
className="italic text-secondary outline-none bg-transparent"
72
76
value={description}