mirror of
https://github.com/immich-app/immich.git
synced 2025-01-04 02:46:47 +01:00
fix(web): cannot use semicolon on the search bar in asset grid page (#3334)
* fix(web): cannot use semicolon on the search bar * fix(web): cannot use semicolon on the search bar * remove console log * fix: disable hotkey when search is enable * format * fix event listener removal
This commit is contained in:
parent
f0302670d2
commit
9f7bf36786
3 changed files with 36 additions and 6 deletions
|
@ -29,6 +29,7 @@
|
||||||
import { AppRoute } from '$lib/constants';
|
import { AppRoute } from '$lib/constants';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
|
import { isSearchEnabled } from '$lib/stores/search.store';
|
||||||
|
|
||||||
export let user: UserResponseDto | undefined = undefined;
|
export let user: UserResponseDto | undefined = undefined;
|
||||||
export let isAlbumSelectionMode = false;
|
export let isAlbumSelectionMode = false;
|
||||||
|
@ -74,12 +75,22 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
if (browser) document.removeEventListener('keydown', handleKeyboardPress);
|
if (browser) {
|
||||||
|
document.removeEventListener('keydown', onKeyboardPress);
|
||||||
|
}
|
||||||
|
|
||||||
assetStore.setInitialState(0, 0, { totalCount: 0, buckets: [] }, undefined);
|
assetStore.setInitialState(0, 0, { totalCount: 0, buckets: [] }, undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleKeyboardPress = (event: KeyboardEvent) => {
|
const handleKeyboardPress = (event: KeyboardEvent) => {
|
||||||
if (event.key === '/') event.preventDefault();
|
if ($isSearchEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.key === '/') {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
if (!$isViewingAssetStoreState) {
|
if (!$isViewingAssetStoreState) {
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case '/':
|
case '/':
|
||||||
|
@ -147,13 +158,20 @@
|
||||||
let shiftKeyIsDown = false;
|
let shiftKeyIsDown = false;
|
||||||
|
|
||||||
const onKeyDown = (e: KeyboardEvent) => {
|
const onKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if ($isSearchEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.shiftKey && e.key !== '/') {
|
if (e.shiftKey && e.key !== '/') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
shiftKeyIsDown = true;
|
shiftKeyIsDown = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onKeyUp = (e: KeyboardEvent) => {
|
const onKeyUp = (e: KeyboardEvent) => {
|
||||||
|
if ($isSearchEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.shiftKey && e.key !== '/') {
|
if (e.shiftKey && e.key !== '/') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
shiftKeyIsDown = false;
|
shiftKeyIsDown = false;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import Magnify from 'svelte-material-icons/Magnify.svelte';
|
import Magnify from 'svelte-material-icons/Magnify.svelte';
|
||||||
import Close from 'svelte-material-icons/Close.svelte';
|
import Close from 'svelte-material-icons/Close.svelte';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { savedSearchTerms } from '$lib/stores/search.store';
|
import { isSearchEnabled, savedSearchTerms } from '$lib/stores/search.store';
|
||||||
import { fly } from 'svelte/transition';
|
import { fly } from 'svelte/transition';
|
||||||
export let value = '';
|
export let value = '';
|
||||||
export let grayTheme: boolean;
|
export let grayTheme: boolean;
|
||||||
|
@ -43,6 +43,16 @@
|
||||||
const clearSearchTerm = () => {
|
const clearSearchTerm = () => {
|
||||||
$savedSearchTerms = [];
|
$savedSearchTerms = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onFocusIn = () => {
|
||||||
|
showBigSearchBar = true;
|
||||||
|
$isSearchEnabled = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onFocusOut = () => {
|
||||||
|
showBigSearchBar = false;
|
||||||
|
$isSearchEnabled = false;
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
|
@ -52,8 +62,8 @@
|
||||||
action={AppRoute.SEARCH}
|
action={AppRoute.SEARCH}
|
||||||
on:reset={() => (value = '')}
|
on:reset={() => (value = '')}
|
||||||
on:submit|preventDefault={() => onSearch(true)}
|
on:submit|preventDefault={() => onSearch(true)}
|
||||||
on:focusin={() => (showBigSearchBar = true)}
|
on:focusin={onFocusIn}
|
||||||
on:focusout={() => (showBigSearchBar = false)}
|
on:focusout={onFocusOut}
|
||||||
>
|
>
|
||||||
<label>
|
<label>
|
||||||
<div class="absolute inset-y-0 left-0 flex items-center pl-6">
|
<div class="absolute inset-y-0 left-0 flex items-center pl-6">
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
import { persisted } from 'svelte-local-storage-store';
|
import { persisted } from 'svelte-local-storage-store';
|
||||||
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
export const savedSearchTerms = persisted<string[]>('search-terms', [], {});
|
export const savedSearchTerms = persisted<string[]>('search-terms', [], {});
|
||||||
|
export const isSearchEnabled = writable<boolean>(false);
|
||||||
|
|
Loading…
Reference in a new issue