Revert "feat: add customizable keyboard navigation"

This commit is contained in:
Xylight authored and GitHub committed 2025-08-15 06:31:23 -07:00
1 parent 4e7c37bd89
commit f9a6e775f3
17 files changed
+39 -306

No files matched your search

@@ -25,7 +25,6 @@
import CommentForm from './CommentForm.svelte'
import type { CommentNodeI } from './comments.svelte'
import { page } from '$app/state'
import { keybindComment } from '$lib/ui/keybinds.svelte'
import { settings } from '$lib/settings.svelte'
interface Props {
@@ -119,15 +118,9 @@
</Modal>
{/if}
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
<li
class={['py-3 relative focus:outline-0', clazz]}
class={['py-3 relative', clazz]}
id={node.comment_view.comment.id.toString()}
data-type="comment"
onkeydown={e =>
keybindComment(e, node.comment_view.comment.id, () => (open = !open))}
tabindex="0"
>
{#if meta}
<button
@@ -29,7 +29,6 @@
replying?: boolean
disabled?: boolean
onedit?: (comment: CommentView) => void
voteComponent?: { castVote: (vote: number) => void }
}
let {
@@ -37,7 +36,6 @@
replying = $bindable(false),
disabled = false,
onedit,
voteComponent,
}: Props = $props()
</script>
@@ -50,7 +48,6 @@
downvotes={comment.counts.downvotes}
vote={comment.my_vote}
commentId={comment.comment.id}
bind:this={voteComponent}
/>
<Button
size="sm"
@@ -76,7 +73,7 @@
class="text-slate-600 dark:text-zinc-400"
>
{#snippet prefix()}
<Icon src={EllipsisHorizontal} size="16" micro />
<Icon src={EllipsisHorizontal} width={16} height={16} mini />
{/snippet}
</Button>
{/snippet}
@@ -4,7 +4,6 @@
import type { CommentNodeI } from './comments.svelte'
import Comments from './CommentTree.svelte'
import { onMount } from 'svelte'
import { keybindFeed } from '$lib/ui/keybinds.svelte'
interface Props {
nodes: CommentNodeI[]
@@ -14,8 +13,8 @@
onMount(() => {
if (scrollTo) {
const element = document?.getElementById(scrollTo)
setTimeout(() => {
const element = document?.getElementById(scrollTo)
element?.scrollIntoView({ behavior: 'smooth', block: 'start' })
}, 100)
}
@@ -39,8 +38,6 @@
let initialOffset = $derived(offsetEl?.offsetTop)
</script>
<svelte:body onkeydown={keybindFeed('li[data-type^="comment"]', 'start')} />
<div bind:this={offsetEl}>
{#if offsetEl}
<VirtualList
@@ -2,7 +2,7 @@
import { profile } from '$lib/auth.svelte.js'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { t } from '$lib/i18n/translations'
import { client } from '$lib/lemmy.svelte'
import { getClient } from '$lib/lemmy.svelte'
import { buttonColor, toast } from 'mono-svelte'
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
import { backOut } from 'svelte/easing'
@@ -24,37 +24,18 @@
commentId,
}: Props = $props()
export const castVote = async (newVote: number) => {
const castVote = async (newVote: number) => {
if (!profile.current?.jwt) {
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
return
}
switch (vote ?? 0) {
case 0:
// nothing was removed
if (newVote == 1) upvotes++
else downvotes++
break
case 1:
// removed an upvote
upvotes--
if (newVote == -1) downvotes++
break
case -1:
// removed a downvote
downvotes--
if (newVote == 1) upvotes++
break
}
vote = newVote
client()
.likeComment({
comment_id: commentId,
score: vote,
})
.then(res => ({ upvotes, downvotes } = res.comment_view.counts))
const res = await getClient().likeComment({
comment_id: commentId,
score: vote,
})
;({ upvotes, downvotes } = res.comment_view.counts)
}
let voteRatio = $derived(
+8 -16
View File
@@ -14,7 +14,6 @@
import type { PostView } from 'lemmy-js-client'
import type { ClassValue } from 'svelte/elements'
import PostBody from './PostBody.svelte'
import { keybindPost } from '$lib/ui/keybinds.svelte'
function getTagRule(tags: Tag[]): 'blur-sm' | 'hide' | undefined {
const tagContent = tags.map(t => t.content.toLowerCase())
@@ -29,9 +28,9 @@
return rule
}
function onclick(e: Event) {
function onClick(e: Event) {
const event = e as Event
const parent = document.getElementById(`item-${post.post.id.toString()}`)
const parent = document.getElementById(post.post.id.toString())
if (event.target == parent) {
goto(postLink(post.post))
@@ -80,8 +79,6 @@
admin: post.creator_is_admin,
moderator: post.creator_is_moderator,
})
let voteComponent = $state<{ castVote: (vote: number) => void }>()
</script>
<!--
@@ -99,11 +96,12 @@
view == 'cozy' && 'py-5 flex flex-col gap-2',
clazz,
]}
id="item-{post.post.id.toString()}"
{onclick}
id={post.post.id.toString()}
onclick={e => {
onClick(e)
}}
onkeydown={e => {
if (e.key === 'Enter') onclick(e)
keybindPost(e, post, voteComponent?.castVote)
if (e.key == 'Enter') onClick(e)
}}
tabindex="0"
{style}
@@ -160,13 +158,7 @@
/>
{/if}
{#if actions}
<PostActions
{onhide}
bind:voteComponent
bind:post
style="grid-area: actions;"
{view}
/>
<PostActions {onhide} bind:post style="grid-area: actions;" {view} />
{/if}
<div
class="absolute overflow-hidden inset-0
@@ -51,7 +51,7 @@
let loading = $state(false)
export const castVote = async (newVote: number) => {
const castVote = async (newVote: number) => {
if (!profile.current?.jwt) {
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
return
@@ -34,7 +34,6 @@
style?: string
onedit?: (post: PostView) => void
onhide?: (hide: boolean) => void
voteComponent?: { castVote: (vote: number) => void }
}
let {
@@ -42,7 +41,6 @@
view = 'cozy',
debug = $bindable(false),
style = '',
voteComponent = $bindable(),
onedit,
onhide,
}: Props = $props()
@@ -79,7 +77,7 @@
<footer
class={[
'flex flex-row gap-2 items-center shrink-0 text-slate-600 dark:text-zinc-300',
'flex flex-row gap-2 items-center shrink-0 text-slate-600 dark:text-zinc-400',
buttonHeight,
]}
class:flex-row-reverse={settings.posts.reverseActions}
@@ -91,7 +89,6 @@
bind:score={post.counts.score}
bind:upvotes={post.counts.upvotes}
bind:downvotes={post.counts.downvotes}
bind:this={voteComponent}
showCounts={profile.current?.user?.local_user_view?.local_user
?.show_scores ?? true}
/>
@@ -12,7 +12,6 @@
type PostFeedID,
} from '$lib/lemmy/postfeed.svelte'
import { settings } from '$lib/settings.svelte.js'
import { keybindFeed } from '$lib/ui/keybinds.svelte'
import type { PostView } from 'lemmy-js-client'
import { Button } from 'mono-svelte'
import { onDestroy, onMount, untrack } from 'svelte'
@@ -171,8 +170,6 @@
})
</script>
<svelte:body onkeydown={keybindFeed()} />
<ul class="flex flex-col list-none" bind:this={listEl}>
{#key posts}
{#if posts?.length == 0}
@@ -203,9 +200,10 @@
>
{#snippet item(row)}
<li
data-index={row}
style={row < 7 ? `--anim-delay: ${row * 50}ms` : ''}
class={[
'relative post-container px-3 sm:px-6 z-0',
'relative post-container px-3 sm:px-6',
row < 7 && 'pop-in opacity-0',
]}
>