2023-03-06 15:31:58 +01:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import { AppRoute } from '$lib/constants';
|
|
|
|
|
import Magnify from 'svelte-material-icons/Magnify.svelte';
|
|
|
|
|
import Close from 'svelte-material-icons/Close.svelte';
|
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
|
import { savedSearchTerms } from '$lib/stores/search.store';
|
|
|
|
|
import { fly } from 'svelte/transition';
|
|
|
|
|
export let value = '';
|
|
|
|
|
export let grayTheme: boolean;
|
2023-03-06 15:31:58 +01:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
let showBigSearchBar = false;
|
|
|
|
|
$: showClearIcon = value.length > 0;
|
2023-03-06 15:31:58 +01:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
function onSearch(saveSearch: boolean) {
|
|
|
|
|
let clipSearch = 'true';
|
|
|
|
|
let searchValue = value;
|
2023-03-23 17:57:49 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
if (value.slice(0, 2) == 'm:') {
|
|
|
|
|
clipSearch = 'false';
|
|
|
|
|
searchValue = value.slice(2);
|
|
|
|
|
}
|
2023-03-23 17:57:49 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
if (saveSearch) {
|
|
|
|
|
saveSearchTerm(value);
|
|
|
|
|
}
|
2023-03-23 17:57:49 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const params = new URLSearchParams({
|
|
|
|
|
q: searchValue,
|
|
|
|
|
clip: clipSearch,
|
|
|
|
|
});
|
2023-03-06 15:31:58 +01:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
goto(`${AppRoute.SEARCH}?${params}`);
|
|
|
|
|
}
|
2023-03-23 17:57:49 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const saveSearchTerm = (saveValue: string) => {
|
|
|
|
|
$savedSearchTerms = [saveValue, ...$savedSearchTerms];
|
2023-03-23 17:57:49 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
if ($savedSearchTerms.length > 5) {
|
|
|
|
|
$savedSearchTerms = $savedSearchTerms.slice(0, 5);
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-03-23 17:57:49 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const clearSearchTerm = () => {
|
|
|
|
|
$savedSearchTerms = [];
|
|
|
|
|
};
|
2023-03-06 15:31:58 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<form
|
2023-07-01 00:50:47 -04:00
|
|
|
draggable="false"
|
|
|
|
|
autocomplete="off"
|
|
|
|
|
class="relative text-sm"
|
|
|
|
|
action={AppRoute.SEARCH}
|
|
|
|
|
on:reset={() => (value = '')}
|
|
|
|
|
on:submit|preventDefault={() => onSearch(true)}
|
|
|
|
|
on:focusin={() => (showBigSearchBar = true)}
|
|
|
|
|
on:focusout={() => (showBigSearchBar = false)}
|
2023-03-06 15:31:58 +01:00
|
|
|
>
|
2023-07-01 00:50:47 -04:00
|
|
|
<label>
|
|
|
|
|
<div class="absolute inset-y-0 left-0 flex items-center pl-6">
|
|
|
|
|
<div class="pointer-events-none dark:text-immich-dark-fg/75">
|
|
|
|
|
<Magnify size="1.5em" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
name="q"
|
|
|
|
|
class="w-full transition-all {grayTheme
|
|
|
|
|
? 'dark:bg-immich-dark-gray'
|
2023-07-18 13:19:39 -05:00
|
|
|
: 'dark:bg-immich-dark-bg'} px-14 py-4 text-immich-fg/75 dark:text-immich-dark-fg {showBigSearchBar
|
|
|
|
|
? 'rounded-t-3xl border border-gray-200 bg-white dark:border-gray-800'
|
|
|
|
|
: 'rounded-3xl border border-transparent bg-gray-200'}"
|
2023-07-01 00:50:47 -04:00
|
|
|
placeholder="Search your photos"
|
|
|
|
|
required
|
|
|
|
|
pattern="^(?!m:$).*$"
|
|
|
|
|
bind:value
|
|
|
|
|
/>
|
|
|
|
|
</label>
|
|
|
|
|
{#if showClearIcon}
|
|
|
|
|
<div class="absolute inset-y-0 right-0 flex items-center pr-4">
|
|
|
|
|
<button
|
|
|
|
|
type="reset"
|
2023-07-18 13:19:39 -05:00
|
|
|
class="rounded-full p-2 hover:bg-immich-primary/5 active:bg-immich-primary/10 dark:text-immich-dark-fg/75 dark:hover:bg-immich-dark-primary/25 dark:active:bg-immich-dark-primary/[.35]"
|
2023-07-01 00:50:47 -04:00
|
|
|
>
|
|
|
|
|
<Close size="1.5em" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2023-03-23 17:57:49 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
{#if showBigSearchBar}
|
|
|
|
|
<div
|
|
|
|
|
transition:fly={{ y: 25, duration: 250 }}
|
2023-07-18 13:19:39 -05:00
|
|
|
class="absolute w-full rounded-b-3xl border border-gray-200 bg-white pb-5 shadow-2xl transition-all dark:border-gray-800 dark:bg-immich-dark-gray dark:text-gray-300"
|
2023-07-01 00:50:47 -04:00
|
|
|
>
|
|
|
|
|
<div class="px-5 pt-5 text-xs">
|
|
|
|
|
<p>
|
|
|
|
|
Smart search is enabled by default, to search for metadata use the syntax <span
|
2023-07-18 13:19:39 -05:00
|
|
|
class="rounded-lg bg-gray-100 p-2 font-mono font-semibold leading-7 text-immich-primary dark:bg-gray-900 dark:text-immich-dark-primary"
|
2023-07-01 00:50:47 -04:00
|
|
|
>m:your-search-term</span
|
|
|
|
|
>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
2023-03-23 21:13:28 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
{#if $savedSearchTerms.length > 0}
|
2023-07-18 13:19:39 -05:00
|
|
|
<div class="flex justify-between px-5 pt-5 text-xs">
|
2023-07-01 00:50:47 -04:00
|
|
|
<p>RECENT SEARCHES</p>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2023-07-18 13:19:39 -05:00
|
|
|
class="rounded-lg p-2 font-semibold text-immich-primary hover:bg-immich-primary/25 dark:text-immich-dark-primary"
|
2023-07-01 00:50:47 -04:00
|
|
|
on:click={clearSearchTerm}>Clear all</button
|
|
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2023-03-23 17:57:49 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
{#each $savedSearchTerms as savedSearchTerm, i (i)}
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2023-07-18 13:19:39 -05:00
|
|
|
class="flex w-full cursor-pointer gap-3 px-5 py-3 text-black hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-500/10"
|
2023-07-01 00:50:47 -04:00
|
|
|
on:click={() => {
|
|
|
|
|
value = savedSearchTerm;
|
|
|
|
|
onSearch(false);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Magnify size="1.5em" />
|
|
|
|
|
{savedSearchTerm}
|
|
|
|
|
</button>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2023-03-06 15:31:58 +01:00
|
|
|
</form>
|