From 3462fd5e02522faf8c162e8c3466911206e808e2 Mon Sep 17 00:00:00 2001 From: bloodwiing Date: Tue, 14 May 2024 10:14:38 +0300 Subject: [PATCH] Refactor: New CommentList system --- src/comp/comment.svelte | 67 +++++++++++++------------------------ src/comp/commentlist.svelte | 59 ++++++++++++++++++++++++++++++++ src/comp/page/post.svelte | 35 ++++++------------- 3 files changed, 93 insertions(+), 68 deletions(-) create mode 100644 src/comp/commentlist.svelte diff --git a/src/comp/comment.svelte b/src/comp/comment.svelte index d13d9a2..d4411bd 100644 --- a/src/comp/comment.svelte +++ b/src/comp/comment.svelte @@ -6,12 +6,12 @@ import Tablericon from "./tablericon.svelte"; /** - * @type {import("$types/base").CommentTreeNode} + * @type {import("$types/base").Comment} */ - export let commentNode; + export let comment; /** - * @type {import("$types/base").CommentTreeNode | null} + * @type {import("$types/base").Comment | null} */ export let replyTo = null; @@ -20,8 +20,6 @@ */ export let getTags = undefined; - $: comment = commentNode.parent; - $: tags = getTags ? getTags(comment) : []; @@ -61,13 +59,6 @@ color: var(--white-dim); } - .comment { - display: flex; - flex-flow: column nowrap; - width: 100%; - gap: 32px; - } - .replyBar { display: flex; flex-flow: row nowrap; @@ -80,40 +71,30 @@
-
-
-
-
- - {#each tags as tag} - {tag} - {/each} +
+
+
+ + {#each tags as tag} + {tag} + {/each} - {#if replyTo} - - - reply - - - {/if} -
- - {moment(comment.commentDate).fromNow()} -
- -

{comment.content}

- -
- + {#if replyTo} + + + reply + + + {/if}
+ + {moment(comment.commentDate).fromNow()}
- - {#if commentNode.children.length} -
- {#each commentNode.children as reply} - - {/each} + +

{comment.content}

+ +
+
- {/if}
diff --git a/src/comp/commentlist.svelte b/src/comp/commentlist.svelte new file mode 100644 index 0000000..f17f8b1 --- /dev/null +++ b/src/comp/commentlist.svelte @@ -0,0 +1,59 @@ + + + + +
+
+ {#each commentTreeList as commentTree} + + + {#if commentTree.children.length} +
+
+ +
+
+ {/if} + {/each} +
+
diff --git a/src/comp/page/post.svelte b/src/comp/page/post.svelte index f5a2304..dca0418 100644 --- a/src/comp/page/post.svelte +++ b/src/comp/page/post.svelte @@ -7,6 +7,7 @@ import { getNamedId, gotoNamedId } from "$lib/util"; import { onMount } from "svelte"; import Rating from "$comp/rating.svelte"; + import CommentList from "$comp/commentlist.svelte"; /** * @type {import("$types/base").Post} @@ -42,13 +43,7 @@ } } - .commentList { - display: flex; - flex-flow: column nowrap; - gap: 32px; - } - - .comments { + .commentsPart { display: flex; flex-flow: column nowrap; gap: 32px; @@ -77,26 +72,16 @@ - - - - {#if commentTree} -
+

Comments

-
- {#each commentTree as reply} - { - if (comment.author?.id == post.author?.id) { - return ["OP 🖋️"]; - } - return []; - }}> - {/each} -
-
+ { + if (comment.author?.id == post.author?.id) { + return ["OP 🖋️"]; + } + return []; + }}> +
{/if}