fix: failed scrolling with comment jumping
This commit is contained in:
6 files changed
+34
-31
No files matched your search
@@ -16,6 +16,7 @@
|
|||||||
import ShieldIcon from '../moderation/ShieldIcon.svelte'
|
import ShieldIcon from '../moderation/ShieldIcon.svelte'
|
||||||
import CommentForm from './CommentForm.svelte'
|
import CommentForm from './CommentForm.svelte'
|
||||||
import type { CommentNodeI } from './comments.svelte'
|
import type { CommentNodeI } from './comments.svelte'
|
||||||
|
import { page } from '$app/state'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
node: CommentNodeI
|
node: CommentNodeI
|
||||||
@@ -109,12 +110,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<li
|
<li
|
||||||
class={[
|
class={['py-3 relative', clazz]}
|
||||||
'py-3 relative',
|
|
||||||
node.comment_view.comment.distinguished &&
|
|
||||||
' text-primary-900 dark:text-primary-100 bg-green-400/5 -mx-4 sm:-mx-6 px-4 sm:px-6',
|
|
||||||
clazz,
|
|
||||||
]}
|
|
||||||
id={node.comment_view.comment.id.toString()}
|
id={node.comment_view.comment.id.toString()}
|
||||||
>
|
>
|
||||||
{#if meta}
|
{#if meta}
|
||||||
@@ -176,12 +172,21 @@
|
|||||||
<div class={['expand max-w-full', open && 'open', contentClass]}>
|
<div class={['expand max-w-full', open && 'open', contentClass]}>
|
||||||
<div id="comment-content">
|
<div id="comment-content">
|
||||||
<div
|
<div
|
||||||
class="flex flex-col whitespace-pre-wrap
|
class={[
|
||||||
max-w-full gap-1 mt-1 relative w-full"
|
'flex flex-col whitespace-pre-wrap max-w-full gap-1 mt-1 relative w-full',
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<Markdown
|
<Markdown
|
||||||
source={node.comment_view.comment.content}
|
source={node.comment_view.comment.content}
|
||||||
class="text-[15px] text-slate-800 dark:text-zinc-200 leading-[1.3]"
|
class={[
|
||||||
|
'text-[15px] text-slate-800 dark:text-zinc-200 leading-[1.3]',
|
||||||
|
|
||||||
|
node.comment_view.comment.distinguished
|
||||||
|
? 'bg-green-400/10 p-1 rounded-lg w-max font-medium'
|
||||||
|
: page.url.hash.slice(1) ==
|
||||||
|
node.comment_view.comment.id.toString() &&
|
||||||
|
'bg-slate-100 dark:bg-zinc-800 p-1 rounded-lg w-max font-medium',
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
{#if actions}
|
{#if actions}
|
||||||
<CommentActions
|
<CommentActions
|
||||||
|
|||||||
@@ -50,7 +50,6 @@
|
|||||||
{#snippet item(index)}
|
{#snippet item(index)}
|
||||||
<div class="-mx-4 sm:-mx-6 px-4 sm:px-6">
|
<div class="-mx-4 sm:-mx-6 px-4 sm:px-6">
|
||||||
<Comments
|
<Comments
|
||||||
isParent={true}
|
|
||||||
bind:nodes={() => [nodes[index]], v => (nodes[index] = v[0])}
|
bind:nodes={() => [nodes[index]], v => (nodes[index] = v[0])}
|
||||||
{post}
|
{post}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
import { errorMessage } from '$lib/lemmy/error'
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
import type { Post } from 'lemmy-js-client'
|
import type { Post } from 'lemmy-js-client'
|
||||||
import { Button, toast } from 'mono-svelte'
|
import { Button, toast } from 'mono-svelte'
|
||||||
import { onMount } from 'svelte'
|
|
||||||
import { ArrowDownCircle, Icon } from 'svelte-hero-icons'
|
import { ArrowDownCircle, Icon } from 'svelte-hero-icons'
|
||||||
import Comment from './Comment.svelte'
|
import Comment from './Comment.svelte'
|
||||||
import Comments from './Comments.svelte'
|
import Comments from './Comments.svelte'
|
||||||
@@ -15,23 +14,10 @@
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
nodes: CommentNodeI[]
|
nodes: CommentNodeI[]
|
||||||
isParent: boolean
|
|
||||||
post: Post
|
post: Post
|
||||||
}
|
}
|
||||||
|
|
||||||
let { nodes = $bindable(), isParent, post }: Props = $props()
|
let { nodes = $bindable(), post }: Props = $props()
|
||||||
|
|
||||||
let hydrated = $state(false)
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
hydrated = true
|
|
||||||
if (isParent && page.url.hash && browser) {
|
|
||||||
document.getElementById(page.url.hash)?.scrollIntoView({
|
|
||||||
behavior: 'smooth',
|
|
||||||
block: 'center',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
let childrenPage = 0
|
let childrenPage = 0
|
||||||
|
|
||||||
@@ -114,12 +100,12 @@
|
|||||||
bind:open={nodes[index].expanded}
|
bind:open={nodes[index].expanded}
|
||||||
>
|
>
|
||||||
{#if node.children?.length > 0}
|
{#if node.children?.length > 0}
|
||||||
<Comments {post} bind:nodes={nodes[index].children} isParent={false} />
|
<Comments {post} bind:nodes={nodes[index].children} />
|
||||||
{/if}
|
{/if}
|
||||||
</Comment>
|
</Comment>
|
||||||
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
|
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
|
||||||
<svelte:element
|
<svelte:element
|
||||||
this={hydrated ? 'div' : 'a'}
|
this={browser ? 'div' : 'a'}
|
||||||
class="w-full h-10 border-y-0! -mt-2 -ml-2.5"
|
class="w-full h-10 border-y-0! -mt-2 -ml-2.5"
|
||||||
href="/comment/{page.params.instance}/{node.comment_view.comment.id}"
|
href="/comment/{page.params.instance}/{node.comment_view.comment.id}"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -116,6 +116,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import SvelteMarkdown from 'svelte-markdown'
|
import SvelteMarkdown from 'svelte-markdown'
|
||||||
import { setContext } from 'svelte'
|
import { setContext } from 'svelte'
|
||||||
|
import type { ClassValue } from 'svelte/elements'
|
||||||
|
|
||||||
interface RendererOptions {
|
interface RendererOptions {
|
||||||
autoloadImages: boolean
|
autoloadImages: boolean
|
||||||
@@ -126,7 +127,7 @@
|
|||||||
inline?: boolean
|
inline?: boolean
|
||||||
noStyle?: boolean
|
noStyle?: boolean
|
||||||
style?: string
|
style?: string
|
||||||
class?: string
|
class?: ClassValue
|
||||||
rendererOptions?: RendererOptions
|
rendererOptions?: RendererOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,7 @@
|
|||||||
class="flex flex-col gap-4 my-auto h-full justify-center max-w-md w-full mx-auto"
|
class="flex flex-col gap-4 my-auto h-full justify-center max-w-md w-full mx-auto"
|
||||||
>
|
>
|
||||||
<h1
|
<h1
|
||||||
class="text-primary-900 dark:text-primary-100 text-6xl font-black flex items-center flex-row gap-2
|
class="text-primary-900 dark:text-primary-100 text-6xl font-black flex items-center flex-row gap-2 border-b pb-4 border-slate-200 dark:border-zinc-800 font-mono"
|
||||||
font-display border-b pb-4 border-slate-200 dark:border-zinc-800"
|
|
||||||
>
|
>
|
||||||
{page.status}
|
{page.status}
|
||||||
</h1>
|
</h1>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { browser } from '$app/environment'
|
||||||
|
import { page } from '$app/state'
|
||||||
import { profile } from '$lib/auth.svelte'
|
import { profile } from '$lib/auth.svelte'
|
||||||
import CommentForm from '$lib/components/lemmy/comment/CommentForm.svelte'
|
import CommentForm from '$lib/components/lemmy/comment/CommentForm.svelte'
|
||||||
import CommentListVirtualizer from '$lib/components/lemmy/comment/CommentListVirtualizer.svelte'
|
import CommentListVirtualizer from '$lib/components/lemmy/comment/CommentListVirtualizer.svelte'
|
||||||
@@ -13,6 +15,7 @@
|
|||||||
GetPostResponse,
|
GetPostResponse,
|
||||||
} from 'lemmy-js-client'
|
} from 'lemmy-js-client'
|
||||||
import { Button, Option, Select } from 'mono-svelte'
|
import { Button, Option, Select } from 'mono-svelte'
|
||||||
|
import { onMount } from 'svelte'
|
||||||
import {
|
import {
|
||||||
ArrowPath,
|
ArrowPath,
|
||||||
ArrowTrendingDown,
|
ArrowTrendingDown,
|
||||||
@@ -49,6 +52,16 @@
|
|||||||
$effect(() => {
|
$effect(() => {
|
||||||
tree = buildCommentsTree(comments.comments)
|
tree = buildCommentsTree(comments.comments)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
if (browser && page.url.hash)
|
||||||
|
// hack because virtual list needs to calc heights
|
||||||
|
setTimeout(() => {
|
||||||
|
document
|
||||||
|
.getElementById(page.url.hash.slice(1))
|
||||||
|
?.scrollIntoView({ behavior: 'instant', block: 'center' })
|
||||||
|
}, 100)
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if profile.current?.jwt}
|
{#if profile.current?.jwt}
|
||||||
@@ -154,7 +167,7 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<div class="divide-y divide-slate-200 dark:divide-zinc-800">
|
<div class="divide-y divide-slate-200 dark:divide-zinc-800">
|
||||||
<div class="-mx-4 sm:-mx-6 px-4 sm:px-6">
|
<div class="-mx-4 sm:-mx-6 px-4 sm:px-6">
|
||||||
<Comments isParent={true} nodes={tree} post={post.post_view.post} />
|
<Comments nodes={tree} post={post.post_view.post} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
Reference in new issue
Block a user