diff --git a/materialious/electron/package-lock.json b/materialious/electron/package-lock.json index d56f21e9..0066cb29 100644 --- a/materialious/electron/package-lock.json +++ b/materialious/electron/package-lock.json @@ -1,12 +1,12 @@ { "name": "Materialious", - "version": "1.12.11", + "version": "1.13.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "Materialious", - "version": "1.12.11", + "version": "1.13.0", "license": "MIT", "dependencies": { "@capacitor-community/electron": "^5.0.0", diff --git a/materialious/src/lib/components/Search.svelte b/materialious/src/lib/components/Search.svelte index bf97e207..2e7d69e8 100644 --- a/materialious/src/lib/components/Search.svelte +++ b/materialious/src/lib/components/Search.svelte @@ -1,6 +1,5 @@
{ showSearchBox = true; await tick(); @@ -157,7 +149,7 @@ onkeydown={handleKeyDown} onkeyup={(event) => { if (event.key === 'Enter') { - handleSubmit(); + onSubmit(); } else { debouncedSearch(event); } @@ -165,35 +157,37 @@ /> close - {#if searchSuggestions} - {#each suggestionsForSearch as suggestion, index (index)} -
  • - { - search = suggestion; - handleSubmit(); - }} - class:selected={index === selectedSuggestionIndex} - href={resolve(`/search/[search]`, { search: encodeURIComponent(suggestion) })} - > -
    {suggestion}
    -
    -
  • - {/each} - {/if} - {#if !suggestionsForSearch.length && $interfaceSearchHistoryEnabled} - {#each $searchHistoryStore as history (history)} -
  • - { - search = history; - }} - href={resolve(`/search/[search]`, { search: encodeURIComponent(history) })} - > -
    {history}
    -
    -
  • - {/each} + {#if !hideSearchSuggestionsAndHistory} + {#if $interfaceSearchSuggestionsStore} + {#each suggestionsForSearch as suggestion, index (index)} +
  • + { + search = suggestion; + onSubmit(); + }} + class:selected={index === selectedSuggestionIndex} + href={resolve(`/search/[search]`, { search: encodeURIComponent(suggestion) })} + > +
    {suggestion}
    +
    +
  • + {/each} + {/if} + {#if !suggestionsForSearch.length && $interfaceSearchHistoryEnabled} + {#each $searchHistoryStore as history (history)} +
  • + { + search = history; + }} + href={resolve(`/search/[search]`, { search: encodeURIComponent(history) })} + > +
    {history}
    +
    +
  • + {/each} + {/if} {/if} {/if} diff --git a/materialious/src/lib/css/global.css b/materialious/src/lib/css/global.css index f54de7bd..ce41868f 100644 --- a/materialious/src/lib/css/global.css +++ b/materialious/src/lib/css/global.css @@ -41,7 +41,7 @@ button, } nav.top { - padding-bottom: 1em; + padding: 1em 0; } main.root { diff --git a/materialious/src/lib/search.ts b/materialious/src/lib/search.ts new file mode 100644 index 00000000..0fbea77b --- /dev/null +++ b/materialious/src/lib/search.ts @@ -0,0 +1,27 @@ +import { goto } from '$app/navigation'; +import { resolve } from '$app/paths'; +import { get } from 'svelte/store'; +import { isVideoID } from './misc'; +import { interfaceSearchHistoryEnabled, searchHistoryStore } from './store'; + +export function goToSearch(searchValue: string) { + const searchTrimed = searchValue.trim(); + + if (!searchTrimed) return; + + if (isVideoID(searchTrimed)) { + // Go directly to video if Video ID provided + goto(resolve('/watch/[videoId]', { videoId: searchTrimed })); + return; + } + + goto(resolve(`/search/[search]`, { search: encodeURIComponent(searchTrimed) })); + + if (get(interfaceSearchHistoryEnabled) && !get(searchHistoryStore).includes(searchTrimed)) { + const pastHistory = get(searchHistoryStore); + if (pastHistory.length > 15) { + pastHistory.pop(); + } + searchHistoryStore.set([searchTrimed, ...pastHistory]); + } +} diff --git a/materialious/src/routes/(app)/+layout.svelte b/materialious/src/routes/(app)/+layout.svelte index cf6bc3f5..a3098bf1 100644 --- a/materialious/src/routes/(app)/+layout.svelte +++ b/materialious/src/routes/(app)/+layout.svelte @@ -38,7 +38,7 @@ import 'beercss'; import ui from 'beercss'; import 'material-dynamic-colors'; - import { onDestroy, onMount } from 'svelte'; + import { onDestroy, onMount, tick } from 'svelte'; import { _ } from '$lib/i18n'; import { get } from 'svelte/store'; import { pwaInfo } from 'virtual:pwa-info'; @@ -216,20 +216,6 @@ } } - if ($isAndroidTvStore) { - const topContent = document.getElementById('top-content') as HTMLElement; - Mousetrap.bind( - 'down', - () => { - if (topContent.contains(document.activeElement)) { - document.getElementById('main-content')?.focus(); - return true; - } - }, - 'keyup' - ); - } - if (Capacitor.getPlatform() === 'android') { document.addEventListener('click', async (event: MouseEvent) => { // Handles opening links in browser for android. @@ -257,12 +243,6 @@ } }); - onDestroy(() => { - if ($isAndroidTvStore) { - Mousetrap.unbind('down', 'keyup'); - } - }); - let webManifestLink = $derived(pwaInfo ? pwaInfo.webManifest.linkTag : ''); @@ -282,6 +262,10 @@ > + + search +
    {$_('searchPlaceholder')}
    +
    {#each getPages() as navPage (navPage)} {#if !navPage.requiresAuth || isLoggedIn} {/if} {/each} - - + {#if !$isAndroidTvStore} + + {/if}