Skip to content

Commit 19ddc59

Browse files
author
Elise Bach
committed
A bit of data/styling
1 parent bd06846 commit 19ddc59

File tree

4 files changed

+92
-52
lines changed

4 files changed

+92
-52
lines changed

app/page.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
display: flex;
33
flex-direction: column;
44
gap: 16px;
5-
/* justify-content: ; */
65
align-items: center;
76
padding: 6rem;
87
min-height: 100vh;

app/page.tsx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,41 @@ export const fetchCache = "force-no-store";
55

66
const apiKey = process.env.PLAIN_API_KEY;
77
if (!apiKey) {
8-
throw new Error("Please set the `PLAIN_API_KEY` environment variable");
8+
throw new Error("Please set the `PLAIN_API_KEY` environment variable");
99
}
1010

1111
const client = new PlainClient({
12-
apiKey,
12+
apiKey,
1313
});
1414

1515
export default async function Home({
16-
params,
17-
searchParams,
16+
params,
17+
searchParams,
1818
}: {
19-
params: { slug: string };
20-
searchParams: { [key: string]: string | string[] | undefined };
19+
params: { slug: string };
20+
searchParams: { [key: string]: string | string[] | undefined };
2121
}) {
22-
const threads = await client.getThreads({
23-
filters: {
24-
// customerIds: ["c_01J28ZQKJX9CVRXVHBMAXNSV5G"],
25-
tenantIdentifiers: [{ tenantId: "te_01J299SM3E25EJHT7JKYS6G7K5" }],
26-
},
27-
});
22+
const threads = await client.getThreads({
23+
filters: {
24+
// customerIds: ["c_01J28ZQKJX9CVRXVHBMAXNSV5G"],
25+
tenantIdentifiers: [{ tenantId: "te_01J299SM3E25EJHT7JKYS6G7K5" }],
26+
},
27+
});
2828

29-
console.log(threads.data?.threads.length);
29+
console.log(threads.data?.threads.length);
3030

31-
return (
32-
<main className={styles.main}>
33-
<h1>Hello</h1>
34-
<div>
35-
{threads.data?.threads.map((thread) => {
36-
return (
37-
<div key={`thread-row-${thread.id}`}>
38-
<a href={`/thread/${thread.id}`}>{thread.title}</a>
39-
</div>
40-
);
41-
})}
42-
</div>
43-
</main>
44-
);
31+
return (
32+
<main className={styles.main}>
33+
<h1>Plain Headless Portal</h1>
34+
<div>
35+
{threads.data?.threads.map((thread) => {
36+
return (
37+
<div key={`thread-row-${thread.id}`}>
38+
<a href={`/thread/${thread.id}`}>{thread.title}</a>
39+
</div>
40+
);
41+
})}
42+
</div>
43+
</main>
44+
);
4545
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.main {
2+
display: flex;
3+
flex-direction: column;
4+
gap: 16px;
5+
align-items: center;
6+
padding: 6rem;
7+
min-height: 100vh;
8+
}
9+
10+
.message {
11+
border: 1px solid #ccc;
12+
border-radius: 8px;
13+
padding: 12px;
14+
}

app/thread/[threadId]/page.tsx

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
import styles from "./page.module.css";
2+
13
export default async function ThreadPage({
2-
params,
4+
params,
35
}: {
4-
params: { threadId: string };
6+
params: { threadId: string };
57
}) {
6-
const data = await fetch("https://core-api.uk.plain.com/graphql/v1", {
7-
method: "POST",
8-
body: JSON.stringify({
9-
query: `{
10-
8+
const data = await fetch("https://core-api.uk.plain.com/graphql/v1", {
9+
method: "POST",
10+
body: JSON.stringify({
11+
query: `{
1112
thread(threadId: "th_01J299WQGA3VNQ4FDECV7JK6MC") {
13+
title
1214
timelineEntries {
1315
edges {
1416
node {
@@ -41,29 +43,54 @@ export default async function ThreadPage({
4143
components {
4244
__typename
4345
... on ComponentText {
44-
text
46+
text
4547
}
4648
}
4749
}
4850
}
4951
}
5052
}
5153
}
52-
}
53-
54-
54+
}
5555
}`,
56-
}),
57-
headers: {
58-
"Content-Type": "application/json",
59-
"Plain-Workspace-Id": "w_01J28VHKDK5PV3DJSZAA01XGAN",
60-
Authorization:
61-
"Bearer GIT_HISTORY_OVERWRITTEN",
62-
},
63-
})
64-
.then((res) => res.json())
65-
.catch((err) => {
66-
console.log(err);
67-
});
68-
return <div>{JSON.stringify(data, null, 2)}</div>;
56+
}),
57+
headers: {
58+
"Content-Type": "application/json",
59+
"Plain-Workspace-Id": "w_01J28VHKDK5PV3DJSZAA01XGAN",
60+
Authorization:
61+
"Bearer GIT_HISTORY_OVERWRITTEN",
62+
},
63+
})
64+
.then((res) => res.json())
65+
.catch((err) => {
66+
console.log(err);
67+
});
68+
69+
const thread = data.data.thread;
70+
const timelineEntries = thread.timelineEntries;
71+
console.log(thread);
72+
73+
return (
74+
<main className={styles.main}>
75+
<h1>{thread.title}</h1>
76+
<div className={styles.message}>
77+
{timelineEntries.edges.map((entry) => {
78+
console.log("ENTRY", entry);
79+
return (
80+
<div key={entry.node.id}>
81+
{entry.node.entry.components.map((component, idx) => {
82+
if (component.__typename === "ComponentText") {
83+
return (
84+
<div key={`comp_${component.text}`}>{component.text}</div>
85+
);
86+
}
87+
88+
return <div key={`comp_${idx}`}>TODO</div>;
89+
})}
90+
</div>
91+
);
92+
})}
93+
</div>
94+
</main>
95+
);
6996
}

0 commit comments

Comments
 (0)