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
27
pulls
pipelines
make first block text in pub drafts
awarm.space
10 months ago
d20d76a4
3a03ee52
+47
-21
5 changed files
expand all
collapse all
unified
split
actions
createNewLeaflet.ts
createPublicationDraft.ts
app
home
CreateNewButton.tsx
new
route.ts
route.ts
+32
-16
actions/createNewLeaflet.ts
···
17
17
import { sql, eq, and } from "drizzle-orm";
18
18
import { cookies } from "next/headers";
19
19
20
20
-
export async function createNewLeaflet(
21
21
-
pageType: "canvas" | "doc",
22
22
-
redirectUser: boolean,
23
23
-
) {
20
20
+
export async function createNewLeaflet({
21
21
+
pageType,
22
22
+
redirectUser,
23
23
+
firstBlockType,
24
24
+
}: {
25
25
+
pageType: "canvas" | "doc";
26
26
+
redirectUser: boolean;
27
27
+
firstBlockType?: "h1" | "text";
28
28
+
}) {
24
29
const client = postgres(process.env.DB_URL as string, { idle_timeout: 5 });
25
30
let auth_token = (await cookies()).get("auth_token")?.value;
26
31
const db = drizzle(client);
···
107
112
attribute: "card/block",
108
113
data: sql`${{ type: "ordered-reference", value: blockEntity.id, position: "a0" }}::jsonb`,
109
114
},
110
110
-
{
111
111
-
id: v7(),
112
112
-
entity: blockEntity.id,
113
113
-
attribute: "block/type",
114
114
-
data: sql`${{ type: "block-type-union", value: "heading" }}::jsonb`,
115
115
-
},
116
116
-
{
117
117
-
id: v7(),
118
118
-
entity: blockEntity.id,
119
119
-
attribute: "block/heading-level",
120
120
-
data: sql`${{ type: "number", value: 1 }}::jsonb`,
121
121
-
},
115
115
+
...(firstBlockType === "text"
116
116
+
? [
117
117
+
{
118
118
+
id: v7(),
119
119
+
entity: blockEntity.id,
120
120
+
attribute: "block/type",
121
121
+
data: sql`${{ type: "block-type-union", value: "text" }}::jsonb`,
122
122
+
},
123
123
+
]
124
124
+
: [
125
125
+
{
126
126
+
id: v7(),
127
127
+
entity: blockEntity.id,
128
128
+
attribute: "block/type",
129
129
+
data: sql`${{ type: "block-type-union", value: "heading" }}::jsonb`,
130
130
+
},
131
131
+
{
132
132
+
id: v7(),
133
133
+
entity: blockEntity.id,
134
134
+
attribute: "block/heading-level",
135
135
+
data: sql`${{ type: "number", value: 1 }}::jsonb`,
136
136
+
},
137
137
+
]),
122
138
]);
123
139
}
124
140
if (auth_token) {
+5
-1
actions/createPublicationDraft.ts
···
6
6
export async function createPublicationDraft(publication_uri: string) {
7
7
let identity = await getIdentityData();
8
8
if (!identity || !identity.atp_did) return null;
9
9
-
let newLeaflet = await createNewLeaflet("doc", false);
9
9
+
let newLeaflet = await createNewLeaflet({
10
10
+
pageType: "doc",
11
11
+
redirectUser: false,
12
12
+
firstBlockType: "text",
13
13
+
});
10
14
console.log(
11
15
await supabaseServerClient
12
16
.from("leaflets_in_publications")
+8
-2
app/home/CreateNewButton.tsx
···
62
62
>
63
63
<MenuItem
64
64
onSelect={async () => {
65
65
-
let id = await createNewLeaflet("doc", false);
65
65
+
let id = await createNewLeaflet({
66
66
+
pageType: "doc",
67
67
+
redirectUser: false,
68
68
+
});
66
69
openNewLeaflet(id);
67
70
}}
68
71
>
···
76
79
</MenuItem>
77
80
<MenuItem
78
81
onSelect={async () => {
79
79
-
let id = await createNewLeaflet("canvas", false);
82
82
+
let id = await createNewLeaflet({
83
83
+
pageType: "canvas",
84
84
+
redirectUser: false,
85
85
+
});
80
86
openNewLeaflet(id);
81
87
}}
82
88
>
+1
-1
app/new/route.ts
···
5
5
export const fetchCache = "force-no-store";
6
6
7
7
export async function GET() {
8
8
-
await createNewLeaflet("doc", true);
8
8
+
await createNewLeaflet({ pageType: "doc", redirectUser: true });
9
9
}
+1
-1
app/route.ts
···
9
9
export async function GET() {
10
10
let auth_token = (await cookies()).get("auth_token")?.value;
11
11
if (auth_token) redirect("/home");
12
12
-
else await createNewLeaflet("doc", true);
12
12
+
else await createNewLeaflet({ pageType: "doc", redirectUser: true });
13
13
}