feat(web): new shortcuts (#3111)

* feat: shortcuts

Signed-off-by: martabal <74269598+martabal@users.noreply.github.com>

* fix: remove listener on component destroy

Signed-off-by: martabal <74269598+martabal@users.noreply.github.com>

* revert delete shortcut

Signed-off-by: martabal <74269598+martabal@users.noreply.github.com>

* feat: new notifications

Signed-off-by: martabal <74269598+martabal@users.noreply.github.com>

* fix: use handleError

Signed-off-by: martabal <74269598+martabal@users.noreply.github.com>

---------

Signed-off-by: martabal <74269598+martabal@users.noreply.github.com>
This commit is contained in:
martin
2023-07-17 05:16:14 +02:00
committed by GitHub
parent e287b18435
commit f9032866e7
3 changed files with 66 additions and 25 deletions

View File

@@ -26,6 +26,10 @@
import AssetDateGroup from './asset-date-group.svelte';
import MemoryLane from './memory-lane.svelte';
import { AppRoute } from '$lib/constants';
import { goto } from '$app/navigation';
import { browser } from '$app/environment';
export let user: UserResponseDto | undefined = undefined;
export let isAlbumSelectionMode = false;
export let showMemoryLane = false;
@@ -35,7 +39,10 @@
let assetGridElement: HTMLElement;
let bucketInfo: AssetCountByTimeBucketResponseDto;
const onKeyboardPress = (event: KeyboardEvent) => handleKeyboardPress(event);
onMount(async () => {
document.addEventListener('keydown', onKeyboardPress);
const { data: assetCountByTimebucket } = await api.assetApi.getAssetCountByTimeBucket({
getAssetCountByTimeBucketDto: {
timeGroup: TimeGroupEnum.Month,
@@ -67,9 +74,21 @@
});
onDestroy(() => {
if (browser) document.removeEventListener('keydown', handleKeyboardPress);
assetStore.setInitialState(0, 0, { totalCount: 0, buckets: [] }, undefined);
});
const handleKeyboardPress = (event: KeyboardEvent) => {
if (event.key === '/') event.preventDefault();
if (!$isViewingAssetStoreState) {
switch (event.key) {
case '/':
goto(AppRoute.EXPLORE);
return;
}
}
};
function intersectedHandler(event: CustomEvent) {
const el = event.detail.container as HTMLElement;
const target = el.firstChild as HTMLElement;
@@ -128,14 +147,14 @@
let shiftKeyIsDown = false;
const onKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Shift') {
if (e.shiftKey && e.key !== '/') {
e.preventDefault();
shiftKeyIsDown = true;
}
};
const onKeyUp = (e: KeyboardEvent) => {
if (e.key === 'Shift') {
if (e.shiftKey && e.key !== '/') {
e.preventDefault();
shiftKeyIsDown = false;
}