Revert "misc: possibly fix comments not working"
This reverts commit fa20d7a6a8.
modified: src/lib/components/lemmy/comment/Comments.svelte
modified: src/lib/components/lemmy/comment/comments.ts
This commit is contained in:
1 parent
3d19318355
commit
55a3b5cfb8
2 files changed
+5
-48
No files matched your search
@@ -9,6 +9,8 @@
|
|||||||
import type { CommentView, Post } from 'lemmy-js-client'
|
import type { CommentView, Post } from 'lemmy-js-client'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
import { toast, ToastType } from '$lib/components/ui/toasts/toasts.js'
|
import { toast, ToastType } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
|
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||||
|
|
||||||
export let nodes: CommentNodeI[]
|
export let nodes: CommentNodeI[]
|
||||||
export let isParent: boolean
|
export let isParent: boolean
|
||||||
@@ -57,7 +59,7 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const tree = buildCommentsTree(newComments.comments, true, 1)
|
const tree = buildCommentsTree(newComments.comments, false)
|
||||||
|
|
||||||
// 0.18.2 -> 0.18.3 broke this
|
// 0.18.2 -> 0.18.3 broke this
|
||||||
// so i'm adding this check
|
// so i'm adding this check
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ function getDepthFromComment(comment?: Comment): number | undefined {
|
|||||||
|
|
||||||
export function buildCommentsTree(
|
export function buildCommentsTree(
|
||||||
comments: CommentView[],
|
comments: CommentView[],
|
||||||
parentComment: boolean,
|
parentComment: boolean
|
||||||
baseDepth: number = 0
|
|
||||||
): CommentNodeI[] {
|
): CommentNodeI[] {
|
||||||
const map = new Map<number, CommentNodeI>()
|
const map = new Map<number, CommentNodeI>()
|
||||||
const depthOffset = !parentComment
|
const depthOffset = !parentComment
|
||||||
@@ -38,7 +37,7 @@ export function buildCommentsTree(
|
|||||||
const node: CommentNodeI = {
|
const node: CommentNodeI = {
|
||||||
comment_view,
|
comment_view,
|
||||||
children: [],
|
children: [],
|
||||||
depth: depth + baseDepth,
|
depth,
|
||||||
}
|
}
|
||||||
map.set(comment_view.comment.id, { ...node })
|
map.set(comment_view.comment.id, { ...node })
|
||||||
}
|
}
|
||||||
@@ -74,50 +73,6 @@ export function buildCommentsTree(
|
|||||||
return tree
|
return tree
|
||||||
}
|
}
|
||||||
|
|
||||||
export function searchCommentTree(
|
|
||||||
tree: CommentNodeI[],
|
|
||||||
id: number
|
|
||||||
): CommentNodeI | undefined {
|
|
||||||
for (const node of tree) {
|
|
||||||
if (node.comment_view.comment.id === id) {
|
|
||||||
return node
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const child of node.children) {
|
|
||||||
const res = searchCommentTree([child], id)
|
|
||||||
|
|
||||||
if (res) {
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
export function insertCommentIntoTree(
|
|
||||||
tree: CommentNodeI[],
|
|
||||||
cv: CommentView,
|
|
||||||
parentComment: boolean
|
|
||||||
) {
|
|
||||||
// Building a fake node to be used for later
|
|
||||||
const node: CommentNodeI = {
|
|
||||||
comment_view: cv,
|
|
||||||
children: [],
|
|
||||||
depth: 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
const parentId = getCommentParentId(cv.comment)
|
|
||||||
if (parentId) {
|
|
||||||
const parent_comment = searchCommentTree(tree, parentId)
|
|
||||||
if (parent_comment) {
|
|
||||||
node.depth = parent_comment.depth + 1
|
|
||||||
parent_comment.children.unshift(node)
|
|
||||||
}
|
|
||||||
} else if (!parentComment) {
|
|
||||||
tree.unshift(node)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function buildCommentsTreeAsync(
|
export async function buildCommentsTreeAsync(
|
||||||
comments: CommentView[],
|
comments: CommentView[],
|
||||||
parentComment: boolean
|
parentComment: boolean
|
||||||
|
|||||||
Reference in new issue
Block a user