feat: add basic forward/backward feed keybinds
This commit is contained in:
3 files changed
+33
-8
No files matched your search
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
function onClick(e: Event) {
|
function onClick(e: Event) {
|
||||||
const event = e as Event
|
const event = e as Event
|
||||||
const parent = document.getElementById(post.post.id.toString())
|
const parent = document.getElementById(`post-${post.post.id.toString()}`)
|
||||||
|
|
||||||
if (event.target == parent) {
|
if (event.target == parent) {
|
||||||
goto(postLink(post.post))
|
goto(postLink(post.post))
|
||||||
@@ -96,10 +96,8 @@
|
|||||||
view == 'cozy' && 'py-5 flex flex-col gap-2',
|
view == 'cozy' && 'py-5 flex flex-col gap-2',
|
||||||
clazz,
|
clazz,
|
||||||
]}
|
]}
|
||||||
id={post.post.id.toString()}
|
id="post-{post.post.id.toString()}"
|
||||||
onclick={e => {
|
onclick={onClick}
|
||||||
onClick(e)
|
|
||||||
}}
|
|
||||||
onkeydown={e => {
|
onkeydown={e => {
|
||||||
if (e.key == 'Enter') onClick(e)
|
if (e.key == 'Enter') onClick(e)
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@
|
|||||||
|
|
||||||
<footer
|
<footer
|
||||||
class={[
|
class={[
|
||||||
'flex flex-row gap-2 items-center shrink-0 text-slate-600 dark:text-zinc-400',
|
'flex flex-row gap-2 items-center shrink-0 text-slate-600 dark:text-zinc-300',
|
||||||
buttonHeight,
|
buttonHeight,
|
||||||
]}
|
]}
|
||||||
class:flex-row-reverse={settings.posts.reverseActions}
|
class:flex-row-reverse={settings.posts.reverseActions}
|
||||||
|
|||||||
@@ -168,8 +168,36 @@
|
|||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
abortLoad?.abort()
|
abortLoad?.abort()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function onkeydown(
|
||||||
|
event: KeyboardEvent & { currentTarget: EventTarget & HTMLElement },
|
||||||
|
) {
|
||||||
|
const direction = event.key == 'j' ? 'up' : event.key == 'k' ? 'down' : null
|
||||||
|
if (!direction) return
|
||||||
|
|
||||||
|
const focusedPost =
|
||||||
|
document.activeElement?.closest('[data-index]') ??
|
||||||
|
document
|
||||||
|
.elementFromPoint(window.innerWidth / 2, window.innerHeight / 2)
|
||||||
|
?.closest('[data-index]')
|
||||||
|
if (!focusedPost) return
|
||||||
|
|
||||||
|
const sibling =
|
||||||
|
direction == 'up'
|
||||||
|
? focusedPost.previousSibling
|
||||||
|
: focusedPost.nextElementSibling
|
||||||
|
if (sibling instanceof HTMLElement) {
|
||||||
|
const postDiv = sibling.querySelector('[id^="post"]')
|
||||||
|
if (postDiv instanceof HTMLElement) {
|
||||||
|
postDiv.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||||
|
postDiv.focus({})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:body {onkeydown} />
|
||||||
|
|
||||||
<ul class="flex flex-col list-none" bind:this={listEl}>
|
<ul class="flex flex-col list-none" bind:this={listEl}>
|
||||||
{#key posts}
|
{#key posts}
|
||||||
{#if posts?.length == 0}
|
{#if posts?.length == 0}
|
||||||
@@ -200,10 +228,9 @@
|
|||||||
>
|
>
|
||||||
{#snippet item(row)}
|
{#snippet item(row)}
|
||||||
<li
|
<li
|
||||||
data-index={row}
|
|
||||||
style={row < 7 ? `--anim-delay: ${row * 50}ms` : ''}
|
style={row < 7 ? `--anim-delay: ${row * 50}ms` : ''}
|
||||||
class={[
|
class={[
|
||||||
'relative post-container px-3 sm:px-6',
|
'relative post-container px-3 sm:px-6 z-0',
|
||||||
row < 7 && 'pop-in opacity-0',
|
row < 7 && 'pop-in opacity-0',
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in new issue
Block a user