fix: add show context for long threads, close #215
This commit is contained in:
1 parent
2e4bfd8912
commit
a548ab145c
4 files changed
+41
-7
No files matched your search
@@ -16,6 +16,7 @@
|
|||||||
import { toast } from 'mono-svelte'
|
import { toast } from 'mono-svelte'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import { Button } from 'mono-svelte'
|
import { Button } from 'mono-svelte'
|
||||||
|
import { afterNavigate } from '$app/navigation'
|
||||||
|
|
||||||
export let nodes: CommentNodeI[]
|
export let nodes: CommentNodeI[]
|
||||||
export let isParent: boolean
|
export let isParent: boolean
|
||||||
@@ -25,6 +26,8 @@
|
|||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
hydrated = true
|
hydrated = true
|
||||||
|
})
|
||||||
|
afterNavigate(() => {
|
||||||
if (isParent && $page.url.hash) {
|
if (isParent && $page.url.hash) {
|
||||||
document.getElementById($page.url.hash)?.scrollIntoView({
|
document.getElementById($page.url.hash)?.scrollIntoView({
|
||||||
behavior: 'smooth',
|
behavior: 'smooth',
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ export async function load({ params, fetch }) {
|
|||||||
|
|
||||||
redirect(
|
redirect(
|
||||||
302,
|
302,
|
||||||
`/post/${params.instance}/${comment.comment_view.post.id}?thread=${comment.comment_view.comment.path}#${comment.comment_view.comment.id}`
|
`/post/${params.instance}/${comment.comment_view.post.id}?thread=${comment.comment_view.comment.path}#${comment.comment_view.comment.id}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@
|
|||||||
max_depth: data.post.post_view.counts.comments > 100 ? 1 : 3,
|
max_depth: data.post.post_view.counts.comments > 100 ? 1 : 3,
|
||||||
})
|
})
|
||||||
loading = false
|
loading = false
|
||||||
data.singleThread = false
|
data.thread.singleThread = false
|
||||||
commentsPage = 1
|
commentsPage = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +235,27 @@
|
|||||||
</Expandable>
|
</Expandable>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{#if data.singleThread}
|
{#if data.thread.showContext}
|
||||||
|
<Material
|
||||||
|
elevation="max"
|
||||||
|
padding="none"
|
||||||
|
color="distinct"
|
||||||
|
class="py-2 px-4 text-sm flex flex-row justify-between items-center
|
||||||
|
flex-wrap gap-4 sticky top-20 w-full box-border z-20 mt-4"
|
||||||
|
>
|
||||||
|
<p class="font-medium text-sm flex items-center gap-2">
|
||||||
|
<Icon src={InformationCircle} mini size="20" />
|
||||||
|
You're viewing part of a thread.
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
{loading}
|
||||||
|
disabled={loading}
|
||||||
|
href="/comment/{$page.params.instance}/{data.thread.showContext}"
|
||||||
|
>
|
||||||
|
Show Context
|
||||||
|
</Button>
|
||||||
|
</Material>
|
||||||
|
{:else if data.thread.singleThread}
|
||||||
<Material
|
<Material
|
||||||
elevation="max"
|
elevation="max"
|
||||||
padding="none"
|
padding="none"
|
||||||
|
|||||||
@@ -15,9 +15,17 @@ export async function load({ params, url, fetch }) {
|
|||||||
|
|
||||||
const thread = url.searchParams.get('thread')
|
const thread = url.searchParams.get('thread')
|
||||||
let parentId: number | undefined
|
let parentId: number | undefined
|
||||||
|
let showContext: string | undefined = undefined
|
||||||
|
|
||||||
if (thread) {
|
if (thread) {
|
||||||
parentId = Number(thread.split('.')[1])
|
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 (!Number.isInteger(parentId)) {
|
if (!Number.isInteger(parentId)) {
|
||||||
parentId = undefined
|
parentId = undefined
|
||||||
@@ -42,10 +50,13 @@ export async function load({ params, url, fetch }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
singleThread: parentId != undefined,
|
thread: {
|
||||||
|
showContext: showContext,
|
||||||
|
singleThread: parentId != undefined
|
||||||
|
},
|
||||||
post: post,
|
post: post,
|
||||||
commentSort: sort,
|
commentSort: sort,
|
||||||
comments: await getClient(params.instance, fetch).getComments(commentParams),
|
comments: await getClient(params.instance, fetch).getComments(commentParams),
|
||||||
slots: {
|
slots: {
|
||||||
sidebar: {
|
sidebar: {
|
||||||
component: CommunityCard,
|
component: CommunityCard,
|
||||||
|
|||||||
Reference in new issue
Block a user