Skip to content

Commit 7b5fbbe

Browse files
committed
feat: fixed min search error message
1 parent ef85bd3 commit 7b5fbbe

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

src/lib/components/mods/ModGrid.svelte

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,19 @@
4545
let totalMods: number;
4646
4747
let searchField = search;
48+
let searchDisabled = true;
49+
let searchButtonClass = 'variant-filled-primary';
50+
const showPagination: boolean = !$mods.error && !$mods.fetching;
4851
4952
let timer: number;
5053
$: {
54+
if (searchField.length > 2) {
55+
searchDisabled = false;
56+
searchButtonClass = 'variant-filled-primary';
57+
} else {
58+
searchDisabled = true;
59+
searchButtonClass = 'variant-filled-surface';
60+
}
5161
clearTimeout(timer);
5262
timer = setTimeout(() => {
5363
if (searchField && searchField.length > 2) {
@@ -70,7 +80,7 @@
7080
$: if (browser) {
7181
const url = new URL(window.location.origin + window.location.pathname);
7282
url.searchParams.append('p', page.toString());
73-
searchField !== '' && searchField !== null && url.searchParams.append('q', searchField);
83+
searchField.length > 2 && searchField !== '' && searchField !== null && url.searchParams.append('q', searchField);
7484
goto(url.toString(), { keepFocus: true });
7585
}
7686
@@ -149,7 +159,7 @@
149159
class="border-0 bg-transparent p-1.5 ring-0"
150160
name="search"
151161
placeholder={$t('search.placeholder-text')} />
152-
<button class="material-icons variant-filled-primary">arrow_forward</button>
162+
<button class="material-icons {searchButtonClass}" disabled={searchDisabled}>arrow_forward</button>
153163
</div>
154164
</div>
155165
{#if tagsOpen}
@@ -178,16 +188,17 @@
178188
{#if newMod && $user !== null}
179189
<a class="variant-ghost-primary btn self-end" href="{base}/new-mod">{$t('mods.new')}</a>
180190
{/if}
181-
182-
<div class="self-end">
183-
<Paginator
184-
bind:settings={paginationSettings}
185-
showFirstLastButtons={true}
186-
showPreviousNextButtons={true}
187-
on:page={(p) => (page = p.detail)}
188-
on:amount={(p) => (perPage = p.detail)}
189-
controlVariant="variant-filled-surface" />
190-
</div>
191+
{#if showPagination}
192+
<div class="self-end">
193+
<Paginator
194+
bind:settings={paginationSettings}
195+
showFirstLastButtons={true}
196+
showPreviousNextButtons={true}
197+
on:page={(p) => (page = p.detail)}
198+
on:amount={(p) => (perPage = p.detail)}
199+
controlVariant="variant-filled-surface" />
200+
</div>
201+
{/if}
191202
</div>
192203
</div>
193204

@@ -197,6 +208,8 @@
197208
<FicsitCard fake />
198209
{/each}
199210
</div>
211+
{:else if $mods.error && $mods.error.message.includes("'Search' failed on the 'min' tag")}
212+
<p>Your search query does not seem valid, please provide more than two characters!</p>
200213
{:else if $mods.error}
201214
<p>Oh no... {$mods.error.message}</p>
202215
{:else}
@@ -207,17 +220,19 @@
207220
</div>
208221
{/if}
209222

210-
<div class="ml-auto mt-5 flex justify-end">
211-
<div>
212-
<Paginator
213-
bind:settings={paginationSettings}
214-
showFirstLastButtons={true}
215-
showPreviousNextButtons={true}
216-
on:page={(p) => (page = p.detail)}
217-
on:amount={(p) => (perPage = p.detail)}
218-
controlVariant="variant-filled-surface" />
223+
{#if showPagination}
224+
<div class="ml-auto mt-5 flex justify-end">
225+
<div>
226+
<Paginator
227+
bind:settings={paginationSettings}
228+
showFirstLastButtons={true}
229+
showPreviousNextButtons={true}
230+
on:page={(p) => (page = p.detail)}
231+
on:amount={(p) => (perPage = p.detail)}
232+
controlVariant="variant-filled-surface" />
233+
</div>
219234
</div>
220-
</div>
235+
{/if}
221236

222237
<style lang="postcss">
223238
* :global(.search-paper) {

0 commit comments

Comments
 (0)