|
45 | 45 | let totalMods: number; |
46 | 46 |
|
47 | 47 | let searchField = search; |
| 48 | + $: searchDisabled = searchField.length < 3; |
| 49 | + $: searchButtonClass = searchDisabled ? 'variant-filled-surface' : 'variant-filled-primary'; |
48 | 50 |
|
49 | 51 | let timer: number; |
50 | 52 | $: { |
51 | 53 | clearTimeout(timer); |
52 | 54 | timer = setTimeout(() => { |
53 | | - if (searchField && searchField.length > 2) { |
| 55 | + if (searchField && !searchDisabled) { |
54 | 56 | if ((search === '' || search === null) && searchField !== '' && searchField !== null) { |
55 | 57 | orderBy = ModFields.Search; |
56 | 58 | page = 0; |
|
70 | 72 | $: if (browser) { |
71 | 73 | const url = new URL(window.location.origin + window.location.pathname); |
72 | 74 | 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); |
74 | 76 | goto(url.toString(), { keepFocus: true }); |
75 | 77 | } |
76 | 78 |
|
77 | 79 | $: totalMods = $mods?.data?.getMods?.count || 0; |
| 80 | + $: showPagination = ($mods && $mods.fetching) || ($mods && !$mods.fetching && totalMods > 0 && !$mods.error); |
78 | 81 |
|
79 | 82 | $: gridClasses = |
80 | 83 | colCount == 4 |
|
149 | 152 | class="border-0 bg-transparent p-1.5 ring-0" |
150 | 153 | name="search" |
151 | 154 | 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> |
153 | 159 | </div> |
154 | 160 | </div> |
155 | 161 | {#if tagsOpen} |
|
178 | 184 | {#if newMod && $user !== null} |
179 | 185 | <a class="variant-ghost-primary btn self-end" href="{base}/new-mod">{$t('mods.new')}</a> |
180 | 186 | {/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} |
191 | 198 | </div> |
192 | 199 | </div> |
193 | 200 |
|
|
197 | 204 | <FicsitCard fake /> |
198 | 205 | {/each} |
199 | 206 | </div> |
| 207 | +{:else if $mods.error && $mods.error.message.includes("'Search' failed on the 'min' tag")} |
| 208 | + {$t('search.failed.query-too-short')} |
200 | 209 | {:else if $mods.error} |
201 | 210 | <p>Oh no... {$mods.error.message}</p> |
| 211 | +{:else if totalMods == 0} |
| 212 | + {$t('search.results.empty')} |
202 | 213 | {:else} |
203 | 214 | <div class="grid {gridClasses} gap-4"> |
204 | 215 | {#each $mods.data.getMods.mods as mod} |
|
207 | 218 | </div> |
208 | 219 | {/if} |
209 | 220 |
|
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> |
219 | 232 | </div> |
220 | | -</div> |
| 233 | +{/if} |
221 | 234 |
|
222 | 235 | <style lang="postcss"> |
223 | 236 | * :global(.search-paper) { |
|
0 commit comments