~james/core

core/web/src/lib/components/comment/CommentSection.svelte -rw-r--r-- 1.8 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<script lang="ts">
	import { getAuth } from "#lib/auth.svelte.ts";
	import type { KnotOrigin } from "#lib/api/syntax.ts";
	import CommentBox from "#lib/components/comment/CommentBox.svelte";
	import CommentList from "#lib/components/comment/CommentList.svelte";
	import OlderComments from "#lib/components/comment/OlderComments.svelte";
	import SignupPrompt from "#lib/components/ui/SignupPrompt.svelte";
	import {
		threadsOf,
		withComment,
		withEdited,
		withOlderPage,
		withRemoved,
		type CommentPage,
		type ThreadInput
	} from "#lib/components/comment/comments.ts";
	import type { MarkupContext } from "#lib/markup/paths.ts";

	interface Props {
		comments: CommentPage;
		subjectUri: string;
		subjectCid?: string;
		markup: MarkupContext;
		knot?: KnotOrigin;
		bobbinUrl?: string;
		class?: string;
	}

	let {
		comments = $bindable(),
		subjectUri,
		subjectCid,
		markup,
		knot,
		bobbinUrl,
		class: className = ""
	}: Props = $props();

	const auth = getAuth();

	const threads = $derived(threadsOf(comments));
	const onsubmitted = (submitted: ThreadInput) => {
		comments = withComment(comments, submitted);
	};
	const onedited = (edited: ThreadInput) => {
		comments = withEdited(comments, edited);
	};
	const ondeleted = (uri: string) => {
		comments = withRemoved(comments, uri);
	};
</script>

<div class={["flex flex-col gap-md", className]}>
	<OlderComments
		{subjectUri}
		cursor={comments.cursor}
		{bobbinUrl}
		onpage={(page) => (comments = withOlderPage(comments, page))}
	/>
	<CommentList
		{threads}
		{subjectUri}
		{subjectCid}
		{markup}
		{knot}
		{onsubmitted}
		{onedited}
		{ondeleted}
	/>

	{#if auth.currentDid}
		<CommentBox
			{subjectUri}
			{subjectCid}
			authorDid={auth.currentDid}
			authorHandle={auth.currentUser?.handle ?? ""}
			{markup}
			{knot}
			{onsubmitted}
		/>
	{:else}
		<SignupPrompt />
	{/if}
</div>