feat: handle escape key and higher wheel zoom ratio (#3471)

This commit is contained in:
martin
2023-07-30 18:03:08 +02:00
committed by GitHub
parent 95c75c289c
commit e368b9e50b
5 changed files with 63 additions and 12 deletions

View File

@@ -23,6 +23,9 @@
import { AppRoute } from '$lib/constants';
import AlbumCard from '$lib/components/album-page/album-card.svelte';
import { flip } from 'svelte/animate';
import { onDestroy, onMount } from 'svelte';
import { browser } from '$app/environment';
import { isViewingAssetStoreState } from '$lib/stores/asset-interaction.store';
export let data: PageData;
@@ -32,6 +35,28 @@
let previousRoute = AppRoute.EXPLORE as string;
$: albums = data.results.albums.items;
const onKeyboardPress = (event: KeyboardEvent) => handleKeyboardPress(event);
onMount(async () => {
document.addEventListener('keydown', onKeyboardPress);
});
onDestroy(() => {
if (browser) {
document.removeEventListener('keydown', onKeyboardPress);
}
});
const handleKeyboardPress = (event: KeyboardEvent) => {
if (!$isViewingAssetStoreState) {
switch (event.key) {
case 'Escape':
goto(previousRoute);
return;
}
}
};
afterNavigate(({ from }) => {
// Prevent setting previousRoute to the current page.
if (from && from.route.id !== $page.route.id) {