|
45 | 45 | let totalMods: number; |
46 | 46 |
|
47 | 47 | let searchField = search; |
| 48 | + let searchDisabled = true; |
| 49 | + let searchButtonClass = 'variant-filled-primary'; |
| 50 | + const showPagination: boolean = !$mods.error && !$mods.fetching; |
48 | 51 |
|
49 | 52 | let timer: number; |
50 | 53 | $: { |
| 54 | + if (searchField.length > 2) { |
| 55 | + searchDisabled = false; |
| 56 | + searchButtonClass = 'variant-filled-primary'; |
| 57 | + } else { |
| 58 | + searchDisabled = true; |
| 59 | + searchButtonClass = 'variant-filled-surface'; |
| 60 | + } |
51 | 61 | clearTimeout(timer); |
52 | 62 | timer = setTimeout(() => { |
53 | 63 | if (searchField && searchField.length > 2) { |
|
70 | 80 | $: if (browser) { |
71 | 81 | const url = new URL(window.location.origin + window.location.pathname); |
72 | 82 | 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); |
74 | 84 | goto(url.toString(), { keepFocus: true }); |
75 | 85 | } |
76 | 86 |
|
|
149 | 159 | class="border-0 bg-transparent p-1.5 ring-0" |
150 | 160 | name="search" |
151 | 161 | 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> |
153 | 163 | </div> |
154 | 164 | </div> |
155 | 165 | {#if tagsOpen} |
|
178 | 188 | {#if newMod && $user !== null} |
179 | 189 | <a class="variant-ghost-primary btn self-end" href="{base}/new-mod">{$t('mods.new')}</a> |
180 | 190 | {/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} |
191 | 202 | </div> |
192 | 203 | </div> |
193 | 204 |
|
|
197 | 208 | <FicsitCard fake /> |
198 | 209 | {/each} |
199 | 210 | </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> |
200 | 213 | {:else if $mods.error} |
201 | 214 | <p>Oh no... {$mods.error.message}</p> |
202 | 215 | {:else} |
|
207 | 220 | </div> |
208 | 221 | {/if} |
209 | 222 |
|
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> |
219 | 234 | </div> |
220 | | -</div> |
| 235 | +{/if} |
221 | 236 |
|
222 | 237 | <style lang="postcss"> |
223 | 238 | * :global(.search-paper) { |
|
0 commit comments