misc: add #comments for comments button
This commit is contained in:
1 parent
0ea98f41dc
commit
e6bd415749
5 files changed
+35
-30
No files matched your search
@@ -107,7 +107,7 @@
|
||||
class="py-3 relative {node.comment_view.comment.distinguished
|
||||
? ' text-primary-900 dark:text-primary-100'
|
||||
: ''} {highlight} {$$props.class}"
|
||||
id="#{node.comment_view.comment.id.toString()}"
|
||||
id={node.comment_view.comment.id.toString()}
|
||||
>
|
||||
<button
|
||||
on:click={() => (open = !open)}
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
import { createWindowVirtualizer } from '@tanstack/svelte-virtual'
|
||||
import Comments from './Comments.svelte'
|
||||
import { browser } from '$app/environment'
|
||||
import { onMount } from 'svelte'
|
||||
|
||||
export let nodes: CommentNodeI[]
|
||||
export let post: Post
|
||||
export let scrollTo: string | undefined
|
||||
|
||||
let virtualListEl: HTMLElement | undefined = undefined
|
||||
|
||||
@@ -18,6 +20,7 @@
|
||||
height: 1500,
|
||||
width: 99999,
|
||||
},
|
||||
overscan: 5,
|
||||
})
|
||||
|
||||
let virtualItemEls: HTMLElement[] = []
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
|
||||
<Button
|
||||
size="custom"
|
||||
href={postLink(post.post)}
|
||||
href="{postLink(post.post)}#comments"
|
||||
class="!text-inherit h-full px-3 relative"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
|
||||
@@ -290,7 +290,7 @@
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
<section class="mt-4 flex flex-col gap-2 w-full">
|
||||
<section class="mt-4 flex flex-col gap-2 w-full" id="comments">
|
||||
<header>
|
||||
<div class="text-base">
|
||||
<span class="font-bold">
|
||||
@@ -391,6 +391,7 @@
|
||||
($userSettings.hidePosts.removed && c.comment.removed)
|
||||
)
|
||||
)}
|
||||
scrollTo={data.thread.focus}
|
||||
/>
|
||||
{#if comments.comments.length == 0}
|
||||
<Placeholder
|
||||
|
||||
@@ -1,62 +1,63 @@
|
||||
import { browser } from "$app/environment";
|
||||
import { env } from "$env/dynamic/public";
|
||||
import { profile } from "$lib/auth.js";
|
||||
import CommunityCard from "$lib/components/lemmy/community/CommunityCard.svelte";
|
||||
import { getClient } from "$lib/lemmy.js";
|
||||
import { awaitIfServer } from "$lib/promise.js";
|
||||
import { SSR_ENABLED, userSettings } from "$lib/settings.js";
|
||||
import { error } from "@sveltejs/kit";
|
||||
import type { GetComments } from "lemmy-js-client";
|
||||
import { get } from "svelte/store";
|
||||
import { browser } from '$app/environment'
|
||||
import { env } from '$env/dynamic/public'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { awaitIfServer } from '$lib/promise.js'
|
||||
import { SSR_ENABLED, userSettings } from '$lib/settings.js'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import type { GetComments } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ params, url, fetch }) {
|
||||
const thread = url.searchParams.get("thread");
|
||||
let parentId: number | undefined;
|
||||
let showContext: string | undefined = undefined;
|
||||
const thread = url.searchParams.get('thread')
|
||||
let parentId: number | undefined
|
||||
let showContext: string | undefined = undefined
|
||||
|
||||
let max_depth = 3;
|
||||
let max_depth = 3
|
||||
|
||||
if (thread) {
|
||||
const split = thread.split(".");
|
||||
const split = thread.split('.')
|
||||
if (split.length >= 9) {
|
||||
const sliced = split.slice(0, split.length - 4);
|
||||
showContext = sliced[sliced.length - 1];
|
||||
parentId = Number(split[split.length - 5]);
|
||||
const sliced = split.slice(0, split.length - 4)
|
||||
showContext = sliced[sliced.length - 1]
|
||||
parentId = Number(split[split.length - 5])
|
||||
} else {
|
||||
parentId = Number(split[1]);
|
||||
parentId = Number(split[1])
|
||||
}
|
||||
|
||||
if (!Number.isInteger(parentId)) {
|
||||
parentId = undefined;
|
||||
parentId = undefined
|
||||
}
|
||||
}
|
||||
|
||||
if (parentId) {
|
||||
max_depth = 10;
|
||||
max_depth = 10
|
||||
}
|
||||
|
||||
const sort = get(userSettings)?.defaultSort?.comments ?? "Hot";
|
||||
const sort = get(userSettings)?.defaultSort?.comments ?? 'Hot'
|
||||
|
||||
const commentParams: GetComments = {
|
||||
post_id: Number(params.id),
|
||||
type_: "All",
|
||||
type_: 'All',
|
||||
limit: 50,
|
||||
page: 1,
|
||||
max_depth: max_depth,
|
||||
saved_only: false,
|
||||
sort: sort,
|
||||
parent_id: parentId,
|
||||
};
|
||||
}
|
||||
|
||||
const comments = getClient(params.instance, fetch).getComments(commentParams);
|
||||
const comments = getClient(params.instance, fetch).getComments(commentParams)
|
||||
const post = await getClient(params.instance.toLowerCase(), fetch).getPost({
|
||||
id: Number(params.id),
|
||||
});
|
||||
})
|
||||
|
||||
return {
|
||||
thread: {
|
||||
showContext: showContext,
|
||||
singleThread: parentId != undefined,
|
||||
focus: thread?.split('.').at(-1),
|
||||
},
|
||||
post: post,
|
||||
commentSort: sort,
|
||||
@@ -69,5 +70,5 @@ export async function load({ params, url, fetch }) {
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user