Skip to content

Commit 9950e3e

Browse files
fix: min search error message (#186)
* feat: fixed min search error message * fix: ensure translation script is run with bash to avoid `[[: not found` issue * feat: tooltip on disabled search button * chore: add line ending visualizer to devcontainer extensions * feat: localize search failed message * fix: switch to ternary expressions for search * fix: invalid if statement * fix: pagination incorrectly disappearing --------- Co-authored-by: Rob B <computerguy440+gh@gmail.com>
1 parent 6f9cb6c commit 9950e3e

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"me-dutour-mathieu.vscode-github-actions",
3838
"eamodio.gitlens",
3939
"GitHub.copilot",
40-
"GitHub.vscode-pull-request-github"
40+
"GitHub.vscode-pull-request-github",
41+
"medo64.render-crlf"
4142
]
4243
}
4344
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"postinstall": "svelte-kit sync",
2020
"start": "svelte-kit start",
2121
"format": "prettier --write . && eslint . --fix",
22-
"translations": "sh ./download_translations.sh"
22+
"translations": "bash ./download_translations.sh"
2323
},
2424
"dependencies": {
2525
"@felte/core": "^1.4.3",

src/lib/components/mods/ModGrid.svelte

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@
4545
let totalMods: number;
4646
4747
let searchField = search;
48+
$: searchDisabled = searchField.length < 3;
49+
$: searchButtonClass = searchDisabled ? 'variant-filled-surface' : 'variant-filled-primary';
4850
4951
let timer: number;
5052
$: {
5153
clearTimeout(timer);
5254
timer = setTimeout(() => {
53-
if (searchField && searchField.length > 2) {
55+
if (searchField && !searchDisabled) {
5456
if ((search === '' || search === null) && searchField !== '' && searchField !== null) {
5557
orderBy = ModFields.Search;
5658
page = 0;
@@ -70,11 +72,12 @@
7072
$: if (browser) {
7173
const url = new URL(window.location.origin + window.location.pathname);
7274
url.searchParams.append('p', page.toString());
73-
searchField !== '' && searchField !== null && url.searchParams.append('q', searchField);
75+
!searchDisabled && searchField !== '' && searchField !== null && url.searchParams.append('q', searchField);
7476
goto(url.toString(), { keepFocus: true });
7577
}
7678
7779
$: totalMods = $mods?.data?.getMods?.count || 0;
80+
$: showPagination = ($mods && $mods.fetching) || ($mods && !$mods.fetching && totalMods > 0 && !$mods.error);
7881
7982
$: gridClasses =
8083
colCount == 4
@@ -149,7 +152,10 @@
149152
class="border-0 bg-transparent p-1.5 ring-0"
150153
name="search"
151154
placeholder={$t('search.placeholder-text')} />
152-
<button class="material-icons variant-filled-primary">arrow_forward</button>
155+
<button
156+
class="material-icons {searchButtonClass}"
157+
disabled={searchDisabled}
158+
title={searchDisabled ? $t('search.disabled') : ''}>arrow_forward</button>
153159
</div>
154160
</div>
155161
{#if tagsOpen}
@@ -178,16 +184,17 @@
178184
{#if newMod && $user !== null}
179185
<a class="variant-ghost-primary btn self-end" href="{base}/new-mod">{$t('mods.new')}</a>
180186
{/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>
187+
{#if showPagination}
188+
<div class="self-end">
189+
<Paginator
190+
bind:settings={paginationSettings}
191+
showFirstLastButtons={true}
192+
showPreviousNextButtons={true}
193+
on:page={(p) => (page = p.detail)}
194+
on:amount={(p) => (perPage = p.detail)}
195+
controlVariant="variant-filled-surface" />
196+
</div>
197+
{/if}
191198
</div>
192199
</div>
193200

@@ -197,8 +204,12 @@
197204
<FicsitCard fake />
198205
{/each}
199206
</div>
207+
{:else if $mods.error && $mods.error.message.includes("'Search' failed on the 'min' tag")}
208+
{$t('search.failed.query-too-short')}
200209
{:else if $mods.error}
201210
<p>Oh no... {$mods.error.message}</p>
211+
{:else if totalMods == 0}
212+
{$t('search.results.empty')}
202213
{:else}
203214
<div class="grid {gridClasses} gap-4">
204215
{#each $mods.data.getMods.mods as mod}
@@ -207,17 +218,19 @@
207218
</div>
208219
{/if}
209220

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" />
221+
{#if showPagination}
222+
<div class="ml-auto mt-5 flex justify-end">
223+
<div>
224+
<Paginator
225+
bind:settings={paginationSettings}
226+
showFirstLastButtons={true}
227+
showPreviousNextButtons={true}
228+
on:page={(p) => (page = p.detail)}
229+
on:amount={(p) => (perPage = p.detail)}
230+
controlVariant="variant-filled-surface" />
231+
</div>
219232
</div>
220-
</div>
233+
{/if}
221234

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

0 commit comments

Comments
 (0)