Skip to content

Commit 57fc589

Browse files
committed
Thread page and filter by tenant
1 parent 8323c54 commit 57fc589

File tree

3 files changed

+104
-24
lines changed

3 files changed

+104
-24
lines changed

app/globals.css

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,6 @@ body {
8585
overflow-x: hidden;
8686
}
8787

88-
body {
89-
color: rgb(var(--foreground-rgb));
90-
background: linear-gradient(
91-
to bottom,
92-
transparent,
93-
rgb(var(--background-end-rgb))
94-
)
95-
rgb(var(--background-start-rgb));
96-
}
9788

9889
a {
9990
color: inherit;

app/page.tsx

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
11
import styles from "./page.module.css";
22
import { PlainClient } from "@team-plain/typescript-sdk";
33

4+
export const fetchCache = "force-no-store";
5+
6+
const apiKey = process.env.PLAIN_API_KEY;
7+
if (!apiKey) {
8+
throw new Error("Please set the `PLAIN_API_KEY` environment variable");
9+
}
10+
11+
const client = new PlainClient({
12+
apiKey,
13+
});
14+
415
export default async function Home({
516
params,
617
searchParams,
718
}: {
819
params: { slug: string };
920
searchParams: { [key: string]: string | string[] | undefined };
1021
}) {
11-
console.log(searchParams);
12-
13-
const apiKey = process.env.PLAIN_API_KEY;
14-
if (!apiKey) {
15-
return (
16-
<main className={styles.main}>
17-
Please set the `PLAIN_API_KEY` environment variable
18-
</main>
19-
);
20-
}
21-
const client = new PlainClient({
22-
apiKey,
22+
const threads = await client.getThreads({
23+
filters: {
24+
tenantIdentifiers: [{ tenantId: "te_01J299SM3E25EJHT7JKYS6G7K5" }],
25+
},
2326
});
24-
const threads = await client.getThreads({});
2527

26-
console.log(threads);
28+
console.log(threads.data?.threads.length);
2729

28-
return <main className={styles.main}>Hello</main>;
30+
return (
31+
<main className={styles.main}>
32+
<h1>Hello</h1>
33+
<div>
34+
{threads.data?.threads.map((thread) => {
35+
return (
36+
<div key={`thread-row-${thread.id}`}>
37+
{thread.title} {thread.id}
38+
</div>
39+
);
40+
})}
41+
</div>
42+
</main>
43+
);
2944
}

app/thread/[threadId]/page.tsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
export default async function ThreadPage({
2+
params,
3+
}: {
4+
params: { threadId: string };
5+
}) {
6+
const data = await fetch("https://core-api.uk.plain.com/graphql/v1", {
7+
method: "POST",
8+
body: JSON.stringify({
9+
query: `{
10+
11+
thread(threadId: "th_01J299WQGA3VNQ4FDECV7JK6MC") {
12+
timelineEntries {
13+
edges {
14+
node {
15+
id
16+
timestamp {
17+
iso8601
18+
}
19+
actor {
20+
__typename
21+
... on UserActor {
22+
user {
23+
fullName
24+
}
25+
}
26+
... on CustomerActor {
27+
customer {
28+
fullName
29+
}
30+
}
31+
... on MachineUserActor {
32+
machineUser {
33+
fullName
34+
}
35+
}
36+
}
37+
entry {
38+
__typename
39+
... on CustomEntry {
40+
title
41+
components {
42+
__typename
43+
... on ComponentText {
44+
text
45+
}
46+
}
47+
}
48+
}
49+
}
50+
}
51+
}
52+
}
53+
54+
55+
}`,
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 (
69+
<div>
70+
{params.threadId}
71+
{JSON.stringify({ data })}
72+
</div>
73+
);
74+
}

0 commit comments

Comments
 (0)