misc: minor tweaks
This commit is contained in:
1 parent
05fcbf09fe
commit
590eedc0fb
4 files changed
+53
-7
No files matched your search
@@ -24,7 +24,8 @@ 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
|
||||||
@@ -37,7 +38,7 @@ export function buildCommentsTree(
|
|||||||
const node: CommentNodeI = {
|
const node: CommentNodeI = {
|
||||||
comment_view,
|
comment_view,
|
||||||
children: [],
|
children: [],
|
||||||
depth,
|
depth: depth + baseDepth,
|
||||||
}
|
}
|
||||||
map.set(comment_view.comment.id, { ...node })
|
map.set(comment_view.comment.id, { ...node })
|
||||||
}
|
}
|
||||||
@@ -73,6 +74,50 @@ 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
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
export let source: string = ''
|
export let source: string = ''
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="break-words flex flex-col markdown gap-2 leading-[1.4]">
|
<div class="break-words flex flex-col markdown gap-2 leading-[1.5]">
|
||||||
{@html md.render(source)}
|
{@html md.render(source)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -52,11 +52,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.markdown :global(li) {
|
.markdown :global(li) {
|
||||||
@apply m-0 leading-[1.4] !important;
|
@apply m-0 leading-[1.5] !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown :global(li > *) {
|
.markdown :global(li > *) {
|
||||||
@apply m-0 leading-[1.4] !important;
|
@apply m-0 leading-[1.5] !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.markdown :global(blockquote) {
|
.markdown :global(blockquote) {
|
||||||
@@ -64,6 +64,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.markdown :global(p) {
|
.markdown :global(p) {
|
||||||
@apply leading-[1.4];
|
@apply leading-[1.5];
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { authData, getClient } from '$lib/lemmy.js'
|
import { authData, getClient } from '$lib/lemmy.js'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export async function load({ params }) {
|
export async function load({ params, url }) {
|
||||||
const post = await getClient(params.instance.toLowerCase()).getPost({
|
const post = await getClient(params.instance.toLowerCase()).getPost({
|
||||||
id: Number(params.id),
|
id: Number(params.id),
|
||||||
auth: get(authData)?.token,
|
auth: get(authData)?.token,
|
||||||
|
|||||||
@@ -92,6 +92,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mt-4" />
|
||||||
<Pageination
|
<Pageination
|
||||||
bind:page={pageNum}
|
bind:page={pageNum}
|
||||||
on:change={(p) => {
|
on:change={(p) => {
|
||||||
|
|||||||
Reference in new issue
Block a user