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
remove /pub page, add publication pagination, update README
zeu.dev
2 months ago
f088a402
51e534bd
+48
-82
3 changed files
expand all
collapse all
unified
split
README.md
src
routes
+page.svelte
pub
+page.svelte
+9
-12
README.md
reviewed
···
2
2
3
3
Get started at [potatonet.app](https://potatonet.app) 🥔
4
4
5
5
-
- [ ] `/<handle>/bookmarks`: bookmarks per user
6
6
-
- [x] fetch bookmarks
7
7
-
- [x] filter by query term
8
8
-
- [x] refresh bookmarks
9
9
-
- [x] filter by tags
10
10
-
- [ ] pagination
11
11
-
- [ ] atproto auth
5
5
+
- [x] atproto auth
12
6
- [x] login/logout
13
13
-
- [ ] bookmark CRUD
14
14
-
- [x] explore
15
15
-
- [x] query all bookmarks
16
16
-
- [x] filter explore
17
17
-
- [ ] pagination
7
7
+
- [ ] site.standard.*
8
8
+
- [x] query all standard.site publications
18
9
- [ ] search bar `/search?q=<term>`
10
10
+
- [ ] community.lexicon.bookmarks
11
11
+
- [ ] publications
12
12
+
- [ ] documents
13
13
+
- [ ] community.lexicon.like
14
14
+
- [ ] publications
15
15
+
- [ ] documents
19
16
20
17
> Special thanks to [pilcrowonpaper](https://pilcrowonpaper.com) for `@oslojs/encoding` library and the
21
18
[encryption gist](https://gist.github.com/pilcrowonpaper/353318556029221c8e25f451b91e5f76) that the `encryption.ts` file is based on.
+39
-9
src/routes/+page.svelte
reviewed
···
5
5
let { data } = $props();
6
6
let { atclient, user } = data;
7
7
8
8
+
let page = $state(0);
9
9
+
8
10
const publicationsQuery = createInfiniteQuery(() => ({
9
11
queryKey: ["publications"],
10
12
queryFn: async ({ pageParam }) => {
···
32
34
},
33
35
staleTime: 1000000,
34
36
initialPageParam: "",
35
35
-
getNextPageParam: (lastPage) => lastPage.siteStandardPublication.pageInfo.endCursor
37
37
+
getNextPageParam: (lastPage) => lastPage.siteStandardPublication.pageInfo.endCursor,
38
38
+
select: (data) => {
39
39
+
const items = data.pages.map((page) => page.siteStandardPublication.edges).flat();
40
40
+
const nodes = items.map((i) => i.node);
41
41
+
return nodes;
42
42
+
}
36
43
}));
44
44
+
45
45
+
let currentPage = $derived(publicationsQuery.data?.slice(page*20, (page*20) + 20));
37
46
</script>
38
47
48
48
+
<menu>
49
49
+
<button
50
50
+
onclick={() => {
51
51
+
if (page > 0) {
52
52
+
page--;
53
53
+
}
54
54
+
}}
55
55
+
class="border"
56
56
+
>
57
57
+
Prev Page
58
58
+
</button>
59
59
+
<number>{page + 1}</number>
60
60
+
{#if publicationsQuery.hasNextPage}
61
61
+
<button
62
62
+
onclick={() => {
63
63
+
page++;
64
64
+
if ((page * 20) + 20 > (publicationsQuery.data?.length || 0)) {
65
65
+
publicationsQuery.fetchNextPage();
66
66
+
}
67
67
+
}}
68
68
+
class="border"
69
69
+
>
70
70
+
Next Page
71
71
+
</button>
72
72
+
{/if}
73
73
+
</menu>
39
74
{#if publicationsQuery.isFetching}
40
75
<p>Fetching...</p>
41
76
{:else if publicationsQuery.isError}
42
77
<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>
78
78
+
{:else}
79
79
+
{#each currentPage as publication (publication.uri)}
80
80
+
<a href={publication.value.url}>{publication.value.url}</a>
48
81
{/each}
49
49
-
{#if publicationsQuery.hasNextPage}
50
50
-
<button onclick={() => publicationsQuery.fetchNextPage()}>Next Page</button>
51
51
-
{/if}
52
82
{/if}
53
83
-61
src/routes/pub/+page.svelte
reviewed
···
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
-