tangled
alpha
login
or
join now
isuggest.selfce.st
/
strand
3
fork
atom
alternative tangled frontend (extremely wip)
3
fork
atom
overview
issues
pulls
pipelines
feat: get trending from stitch (thank you bailey!)
serenity
2 weeks ago
70a32184
8cb800e3
+42
1 changed file
expand all
collapse all
unified
split
src
lib
queries
get-trending-from-stitch.ts
+42
src/lib/queries/get-trending-from-stitch.ts
···
1
1
+
import { appBskyFeedPostSchema } from "@/lib/types/lexicons/app/bsky/feed/post";
2
2
+
import { comAtprotoRepoGetRecordOutputSchema } from "@/lib/types/lexicons/com/atproto/repo/getRecord";
3
3
+
import { useQuery } from "@tanstack/react-query";
4
4
+
import { z } from "zod/v4";
5
5
+
6
6
+
const STITCH_DID = "did:plc:vsicp7h3rpa2pbfid3zzwqoy";
7
7
+
const STITCH_PDS_URL = new URL("https://selfhosted.social");
8
8
+
9
9
+
export const getTrendingFromStitch = async () => {
10
10
+
const trendingReq = new Request(
11
11
+
`${STITCH_PDS_URL}/xrpc/com.atproto.listRecords?repo=${STITCH_DID}&collection=app.bsky.feed.post&limit=20`,
12
12
+
);
13
13
+
const res = await fetch(trendingReq);
14
14
+
if (!res.ok) throw new Error("Fetching posts from Stitch failed.");
15
15
+
const data: unknown = res.json();
16
16
+
17
17
+
const {
18
18
+
success,
19
19
+
error,
20
20
+
data: parseData,
21
21
+
} = z
22
22
+
.object({
23
23
+
cursor: z.string(),
24
24
+
records: z.array(
25
25
+
comAtprotoRepoGetRecordOutputSchema(appBskyFeedPostSchema),
26
26
+
),
27
27
+
})
28
28
+
.safeParse(data);
29
29
+
30
30
+
if (!success) throw new Error(error.message);
31
31
+
32
32
+
return parseData.records;
33
33
+
};
34
34
+
35
35
+
const stitchTrendingQueryKey = ["bsky", "posts", STITCH_DID];
36
36
+
37
37
+
export const useTrendingQuery = () => {
38
38
+
return useQuery({
39
39
+
queryKey: stitchTrendingQueryKey,
40
40
+
queryFn: () => getTrendingFromStitch(),
41
41
+
});
42
42
+
};