Added hotkey to navigate scans
This commit is contained in:
parent
f7c0c3f784
commit
c1363afb55
|
@ -1,5 +1,4 @@
|
||||||
---
|
---
|
||||||
import Button from "components/Button.astro";
|
|
||||||
import {
|
import {
|
||||||
type EndpointCredit,
|
type EndpointCredit,
|
||||||
type EndpointImage,
|
type EndpointImage,
|
||||||
|
@ -14,6 +13,7 @@ import type { ComponentProps } from "astro/types";
|
||||||
import AppLayoutDescription from "./AppLayout/components/AppLayoutDescription.astro";
|
import AppLayoutDescription from "./AppLayout/components/AppLayoutDescription.astro";
|
||||||
import Attributes from "./Attributes.astro";
|
import Attributes from "./Attributes.astro";
|
||||||
import { sizesToSrcset } from "src/utils/img";
|
import { sizesToSrcset } from "src/utils/img";
|
||||||
|
import { Icon } from "astro-icon/components";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
previousImageHref?: string | undefined;
|
previousImageHref?: string | undefined;
|
||||||
|
@ -55,10 +55,11 @@ const hasNavigation = previousImageHref || nextImageHref;
|
||||||
{
|
{
|
||||||
hasNavigation && (
|
hasNavigation && (
|
||||||
<a
|
<a
|
||||||
class:list={{ hidden: !previousImageHref }}
|
id="previous-button"
|
||||||
|
class:list={{ hidden: !previousImageHref, pressable: true }}
|
||||||
href={previousImageHref}
|
href={previousImageHref}
|
||||||
data-astro-history="replace">
|
data-astro-history="replace">
|
||||||
<Button icon="material-symbols:chevron-left" />
|
<Icon name="material-symbols:chevron-left" />
|
||||||
</a>
|
</a>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -76,10 +77,11 @@ const hasNavigation = previousImageHref || nextImageHref;
|
||||||
{
|
{
|
||||||
hasNavigation && (
|
hasNavigation && (
|
||||||
<a
|
<a
|
||||||
class:list={{ hidden: !nextImageHref }}
|
id="next-button"
|
||||||
|
class:list={{ hidden: !nextImageHref, pressable: true }}
|
||||||
href={nextImageHref}
|
href={nextImageHref}
|
||||||
data-astro-history="replace">
|
data-astro-history="replace">
|
||||||
<Button icon="material-symbols:chevron-right" />
|
<Icon name="material-symbols:chevron-right" />
|
||||||
</a>
|
</a>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -160,3 +162,33 @@ const hasNavigation = previousImageHref || nextImageHref;
|
||||||
overflow-wrap: anywhere;
|
overflow-wrap: anywhere;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
{/* ------------------------------------------- JS --------------------------------------------- */}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { navigate } from "astro:transitions/client";
|
||||||
|
|
||||||
|
let queueCount = 0;
|
||||||
|
|
||||||
|
document.addEventListener("keydown", async (e) => {
|
||||||
|
queueCount++;
|
||||||
|
if (queueCount > 1) return;
|
||||||
|
|
||||||
|
const handle = async () => {
|
||||||
|
const previousHref = document.getElementById("previous-button")?.getAttribute("href");
|
||||||
|
const nextHref = document.getElementById("next-button")?.getAttribute("href");
|
||||||
|
|
||||||
|
if (previousHref && e.key === "ArrowLeft") {
|
||||||
|
await navigate(previousHref);
|
||||||
|
} else if (nextHref && e.key === "ArrowRight") {
|
||||||
|
await navigate(nextHref);
|
||||||
|
}
|
||||||
|
|
||||||
|
queueCount--;
|
||||||
|
};
|
||||||
|
|
||||||
|
while (queueCount > 0) {
|
||||||
|
await handle();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue