From cddd92b2988e4ea39ea8952b5f117153516765f5 Mon Sep 17 00:00:00 2001 From: Zachary Knight Date: Mon, 23 Sep 2024 00:23:04 +0000 Subject: [PATCH] feat: fixed min search error message --- src/lib/components/mods/ModGrid.svelte | 58 ++++++++++++++++---------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/src/lib/components/mods/ModGrid.svelte b/src/lib/components/mods/ModGrid.svelte index 72b9ecf75..4a880da28 100644 --- a/src/lib/components/mods/ModGrid.svelte +++ b/src/lib/components/mods/ModGrid.svelte @@ -45,9 +45,18 @@ let totalMods: number; let searchField = search; + let searchDisabled = true; + let searchButtonClass = 'variant-filled-primary'; let timer: number; $: { + if (searchField.length > 2) { + searchDisabled = false; + searchButtonClass = 'variant-filled-primary'; + } else { + searchDisabled = true; + searchButtonClass = 'variant-filled-surface'; + } clearTimeout(timer); timer = setTimeout(() => { if (searchField && searchField.length > 2) { @@ -70,7 +79,7 @@ $: if (browser) { const url = new URL(window.location.origin + window.location.pathname); url.searchParams.append('p', page.toString()); - searchField !== '' && searchField !== null && url.searchParams.append('q', searchField); + searchField.length > 2 && searchField !== '' && searchField !== null && url.searchParams.append('q', searchField); goto(url.toString(), { keepFocus: true }); } @@ -149,7 +158,7 @@ class="border-0 bg-transparent p-1.5 ring-0" name="search" placeholder={$t('search.placeholder-text')} /> - + {#if tagsOpen} @@ -178,16 +187,17 @@ {#if newMod && $user !== null} {$t('mods.new')} {/if} - -
- (page = p.detail)} - on:amount={(p) => (perPage = p.detail)} - controlVariant="variant-filled-surface" /> -
+ {#if !$mods.error && !$mods.fetching} +
+ (page = p.detail)} + on:amount={(p) => (perPage = p.detail)} + controlVariant="variant-filled-surface" /> +
+ {/if} @@ -197,6 +207,8 @@ {/each} +{:else if $mods.error && $mods.error.message.includes("'Search' failed on the 'min' tag")} +

Your search query does not seem valid, please provide more than two characters!

{:else if $mods.error}

Oh no... {$mods.error.message}

{:else} @@ -207,17 +219,19 @@ {/if} -
-
- (page = p.detail)} - on:amount={(p) => (perPage = p.detail)} - controlVariant="variant-filled-surface" /> +{#if !$mods.error && !$mods.fetching} +
+
+ (page = p.detail)} + on:amount={(p) => (perPage = p.detail)} + controlVariant="variant-filled-surface" /> +
-
+{/if}