~james/core

core/web/src/lib/components/comment/OlderComments.svelte -rw-r--r-- 1.1 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<script lang="ts">
	import { createAction } from "#lib/action.svelte.ts";
	import { getAuth } from "#lib/auth.svelte.ts";
	import { createBobbinClient } from "#lib/api/client.ts";
	import { loadCommentPage, type CommentPage } from "#lib/components/comment/comments.ts";
	import Button from "#lib/components/ui/Button.svelte";
	import ErrorBox from "#lib/components/ui/Error.svelte";

	interface Props {
		subjectUri: string;
		cursor: string | null;
		bobbinUrl?: string;
		onpage: (page: CommentPage) => void;
	}

	let { subjectUri, cursor, bobbinUrl, onpage }: Props = $props();

	const auth = getAuth();

	const load = createAction(async () => {
		if (!cursor || !bobbinUrl) return;
		onpage(
			await loadCommentPage(
				createBobbinClient({ serviceUrl: bobbinUrl }),
				subjectUri,
				auth.currentDid ?? undefined,
				cursor
			)
		);
	});
</script>

{#if cursor && bobbinUrl}
	<Button
		data-testid="loadOlderComments"
		onclick={() => load.run()}
		loading={load.loading}
		disabled={load.loading}
		class="w-full"
	>
		Load older comments
	</Button>
{/if}
{#if load.error}
	<ErrorBox label={load.error} />
{/if}