Merge branch 'main' into keybinds

This commit is contained in:
Xylight authored and GitHub committed 2025-08-11 20:46:21 +00:00
commit 70b039be4c
5 files changed
+68 -44

No files matched your search

+14 -1
View File
@@ -14,8 +14,21 @@ export async function load({ params, fetch }) {
id: Number(params.id),
})
const split = comment.comment_view.comment.path.split('.')
const threadPath =
split.length > 4
? comment.comment_view.comment.id
: split.slice(-5).join('.')
redirect(
302,
`/post/${profile.current.instance}/${comment.comment_view.post.id}?thread=${comment.comment_view.comment.path}#${comment.comment_view.comment.id}`,
resolveRoute(
`/post/[instance]/[id]?thread=${threadPath}#${comment.comment_view.comment.id}`,
{
instance: params.instance,
id: comment.comment_view.post.id.toString(),
},
),
)
}
@@ -194,13 +194,12 @@
{#await data.post.value.meta then meta}
{@const crossposts = meta.cross_posts}
{#if crossposts?.length > 0}
<Expandable
class="text-base mt-2 w-full cursor-pointer"
open={crossposts?.length <= 3}
>
<Expandable class="text-base mt-2 w-full cursor-pointer">
{#snippet title()}
<div
class="flex items-center gap-1 w-full text-left text-base font-normal"
class={[
'flex items-center gap-1 w-full text-left text-base font-normal',
]}
>
<span class="font-bold">{crossposts.length}</span>
{$t('routes.post.crosspostCount')}
@@ -222,32 +221,37 @@
{/if}
{/await}
</article>
{#if data.thread.value.showContext || data.thread.value.singleThread}
<div
class="sticky mx-auto z-50 max-w-md min-w-0 flex flex-col items-center overflow-auto gap-1
{#await data.comments.value then comments}
{#if data.thread.value.showContext || data.thread.value.singleThread}
<div
class="sticky mx-auto z-50 max-w-md min-w-0 flex flex-col items-center overflow-auto gap-1
bg-slate-50/50 dark:bg-zinc-900/50 backdrop-blur-xl border border-slate-200/50 dark:border-zinc-800/50
p-1 rounded-full justify-between top-6 lg:top-22"
>
<Button
color="none"
rounding="pill"
{loading}
disabled={loading}
href={data.thread.value.showContext
? `/comment/${page.params.instance}/${data.thread.value.showContext}`
: undefined}
class="hover:bg-white/50 dark:hover:bg-zinc-800/30"
onclick={data.thread.value.singleThread ? reloadComments : undefined}
>
{data.thread.value.showContext
? $t('routes.post.thread.context')
: $t('routes.post.thread.allComments')}
{#snippet suffix()}
<Icon src={ArrowRight} size="16" micro />
{/snippet}
</Button>
</div>
{/if}
<Button
color="none"
rounding="pill"
{loading}
disabled={loading}
href={data.thread.value.showContext
? `/comment/${
// split first comment path to get 5 before
comments.comments[0].comment.path.split('.').slice(-5)[0]
}`
: undefined}
class="hover:bg-white/50 dark:hover:bg-zinc-800/30"
onclick={data.thread.value.singleThread ? reloadComments : undefined}
>
{data.thread.value.showContext
? $t('routes.post.thread.context')
: $t('routes.post.thread.allComments')}
{#snippet suffix()}
<Icon src={ArrowRight} size="16" micro />
{/snippet}
</Button>
</div>
{/if}
{/await}
<section class="mt-4 flex flex-col gap-2 w-full" id="comments">
<header>
<div class="text-base">
@@ -25,21 +25,19 @@ interface PartialPost {
function buildContext(thread?: string) {
let parentId: number | undefined
let showContext: string | undefined
let max_depth = 3
let showContext: boolean = false
const max_depth = 3
if (thread) {
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])
} else {
parentId = Number(split[1])
if (split[0] == '0') parentId = Number(thread.split('.')[1])
else {
parentId = Number(thread.split('.')[0])
showContext = true
}
}
if (parentId) max_depth = 10
return { parentId, showContext, max_depth, focus: thread?.split('.').at(-1) }
}
@@ -77,16 +75,19 @@ export async function load({ params, url, fetch }) {
// TODO use Lemmy profile default settings
const sort = settings?.defaultSort?.comments ?? 'Hot'
const { parentId, showContext, focus } = buildContext(
url.searchParams.get('thread') || undefined,
)
const cachedPost =
findInFeed(Number(params.id), 'main') ??
findInFeed(Number(params.id), 'community')
const max_depth = (cachedPost?.post_view.counts.comments ?? 0) > 100 ? 1 : 3
const {
parentId,
showContext,
focus,
max_depth: passedMaxDepth,
} = buildContext(url.searchParams.get('thread') || undefined)
const max_depth =
(cachedPost?.post_view.counts.comments ?? 0) > 100 ? 1 : passedMaxDepth
const commentParams: GetComments = {
post_id: Number(params.id),
type_: 'All',