Skip to content

Commit

Permalink
85 add loading indicator to search (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjurstrom authored Oct 16, 2024
1 parent cc3e559 commit 50c3df2
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions resources/views/components/search.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@
open: false,
resetOnOpen: true,
closeOnSelection: true,
async performSearch(query) {
try {
const response = await fetch(`/prezet/search?q=${encodeURIComponent(query)}`, {
headers: {
'Content-Type': 'application/json'
loading: false,
async performSearch(query) {
this.loading = true;
try {
const response = await fetch(`/prezet/search?q=${encodeURIComponent(query)}`, {
headers: {
'Content-Type': 'application/json'
}
});
if (!response.ok) throw new Error('Search failed');
return await response.json();
} catch (error) {
console.error('Search error:', error);
this.filterResults = [];
}
},
});
if (!response.ok) throw new Error('Search failed');
return await response.json();
} catch (error) {
console.error('Search error:', error);
this.filterResults = [];
} finally {
this.loading = false;
}
},
// Add your custom functionality or navigation when an option is selected
optionSelected() {
Expand Down Expand Up @@ -285,6 +288,27 @@ class="w-full border-none bg-transparent py-3 text-sm placeholder:text-zinc-500
aria-expanded="true"
aria-autocomplete="list"
/>
<svg
x-show="loading"
class="inline-block size-6 animate-spin opacity-50"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
class="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
stroke-width="4"
></circle>
<path
class="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
</div>
</div>
<!-- EMD Search Input -->
Expand Down

0 comments on commit 50c3df2

Please sign in to comment.