tangled
alpha
login
or
join now
zeu.dev
/
potatonet-app
12
fork
atom
Read-it-later social network
12
fork
atom
overview
issues
pulls
pipelines
init explore, /pub page
zeu.dev
2 months ago
51e534bd
65ce338a
+138
-4
4 changed files
expand all
collapse all
unified
split
src
lib
utils.ts
routes
+page.svelte
[handle]
bookmarks
+page.svelte
pub
+page.svelte
+27
src/lib/utils.ts
···
14
14
const info = await result.json();
15
15
return info;
16
16
}
17
17
+
18
18
+
export type Node = {
19
19
+
uri: string;
20
20
+
cid: string;
21
21
+
did: string;
22
22
+
indexedAt: string;
23
23
+
actorHandle: string;
24
24
+
}
25
25
+
26
26
+
export type PublicationNode = Node & { value: {
27
27
+
url: string;
28
28
+
name: string;
29
29
+
description: string;
30
30
+
}}
31
31
+
32
32
+
export type DocumentNode = Node & { value: {
33
33
+
title: string;
34
34
+
site: string;
35
35
+
publishedAt: string;
36
36
+
path?: string;
37
37
+
content?: string;
38
38
+
bskyPostRef?: string;
39
39
+
description?: string;
40
40
+
textContent?: string;
41
41
+
tags?: string[];
42
42
+
updatedAt?: string;
43
43
+
}}
+50
-2
src/routes/+page.svelte
···
1
1
<script lang="ts">
2
2
+
import type { PublicationNode } from '$lib/utils';
3
3
+
import { createInfiniteQuery, createQuery } from '@tanstack/svelte-query';
4
4
+
2
5
let { data } = $props();
3
3
-
let query = $state("");
4
4
-
let filterTags = $state<string[]>([]);
6
6
+
let { atclient, user } = data;
7
7
+
8
8
+
const publicationsQuery = createInfiniteQuery(() => ({
9
9
+
queryKey: ["publications"],
10
10
+
queryFn: async ({ pageParam }) => {
11
11
+
const query = `
12
12
+
query GetPublications {
13
13
+
siteStandardPublication(first: 20, after: "${pageParam}") {
14
14
+
edges {}
15
15
+
pageInfo {
16
16
+
hasNextPage
17
17
+
endCursor
18
18
+
}
19
19
+
}
20
20
+
}
21
21
+
`;
22
22
+
const data = await atclient.publicQuery(query);
23
23
+
return data as {
24
24
+
siteStandardPublication: {
25
25
+
edges: { node: PublicationNode, cursor: string }[],
26
26
+
pageInfo: {
27
27
+
hasNextPage: boolean;
28
28
+
endCursor: string;
29
29
+
}
30
30
+
}
31
31
+
}
32
32
+
},
33
33
+
staleTime: 1000000,
34
34
+
initialPageParam: "",
35
35
+
getNextPageParam: (lastPage) => lastPage.siteStandardPublication.pageInfo.endCursor
36
36
+
}));
5
37
</script>
38
38
+
39
39
+
{#if publicationsQuery.isFetching}
40
40
+
<p>Fetching...</p>
41
41
+
{:else if publicationsQuery.isError}
42
42
+
<p>Error</p>
43
43
+
{:else if publicationsQuery.isSuccess}
44
44
+
{@const publications = publicationsQuery.data.pages.map((p) => p.siteStandardPublication.edges.map((edge) => edge.node)).flat()}
45
45
+
{#each publications as publication}
46
46
+
<a href={`/pub?uri=${publication.uri}`}>{publication.uri}</a>
47
47
+
<p>{publication.value.url}</p>
48
48
+
{/each}
49
49
+
{#if publicationsQuery.hasNextPage}
50
50
+
<button onclick={() => publicationsQuery.fetchNextPage()}>Next Page</button>
51
51
+
{/if}
52
52
+
{/if}
53
53
+
-2
src/routes/[handle]/bookmarks/+page.svelte
···
1
1
-
<script lang="ts">
2
2
-
</script>
+61
src/routes/pub/+page.svelte
···
1
1
+
<script lang="ts">
2
2
+
import { page } from '$app/state';
3
3
+
import type { DocumentNode, PublicationNode } from '$lib/utils';
4
4
+
import { createInfiniteQuery, createQuery } from '@tanstack/svelte-query';
5
5
+
6
6
+
let { data } = $props();
7
7
+
let { atclient, user } = data;
8
8
+
9
9
+
let uri = $derived(page.url.searchParams.get("uri"));
10
10
+
$inspect(uri);
11
11
+
12
12
+
const documentsQuery = createQuery(() => ({
13
13
+
queryKey: ["documents", uri],
14
14
+
queryFn: async ({ pageParam }) => {
15
15
+
const query = `
16
16
+
query GetDocuments {
17
17
+
siteStandardDocument(where: {
18
18
+
site: {
19
19
+
eq: "${uri}"
20
20
+
}
21
21
+
}) {
22
22
+
edges {}
23
23
+
pageInfo {
24
24
+
hasNextPage
25
25
+
endCursor
26
26
+
}
27
27
+
}
28
28
+
}
29
29
+
`;
30
30
+
const data = await atclient.publicQuery(query);
31
31
+
console.log(data);
32
32
+
return data as {
33
33
+
siteStandardDocument: {
34
34
+
edges: { node: DocumentNode, cursor: string }[],
35
35
+
pageInfo: {
36
36
+
hasNextPage: boolean;
37
37
+
endCursor: string;
38
38
+
}
39
39
+
}
40
40
+
}
41
41
+
},
42
42
+
// @ts-ignore
43
43
+
select: (data) => data.siteStandardDocument.edges.map((edge) => edge.node)
44
44
+
}));
45
45
+
</script>
46
46
+
47
47
+
{#if documentsQuery.isFetching}
48
48
+
<p>Fetching...</p>
49
49
+
{:else if documentsQuery.isError}
50
50
+
<p>Error</p>
51
51
+
{:else if documentsQuery.isSuccess}
52
52
+
{@const documents = documentsQuery.data}
53
53
+
{#if documents.length === 0}
54
54
+
<p>No documents...</p>
55
55
+
{:else}
56
56
+
{#each documents as document}
57
57
+
<p>{document.value.title}</p>
58
58
+
{/each}
59
59
+
{/if}
60
60
+
{/if}
61
61
+