Skip to content

Commit 2e3161b

Browse files
committed
🦆
1 parent accf7f8 commit 2e3161b

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

‎client/src/components/SearchResult.vue

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@
2424
class="px-3 py-1 bg-primary-100 text-primary-600 rounded-full text-xs font-medium">
2525
{{ tag }}
2626
</span>
27-
<span class="px-3 py-1 bg-primary-100 text-primary-600 rounded-full text-xs font-medium" v-if="result.score">
27+
<!-- <span class="px-3 py-1 bg-primary-100 text-primary-600 rounded-full text-xs font-medium" v-if="result.score">
2828
{{ Math.round((result.score ?? 0) * 100) / 100 }}%
29-
</span>
29+
</span> -->
3030
</div>
3131
<div class="mt-4">
32-
<button @click="toggleSummary"
32+
<button @click="toggleSummary" :disabled="loadingSummary"
3333
class="text-sm text-primary-600 hover:text-primary-700 font-medium focus:outline-none">
3434
{{ showSummary ? 'Hide' : 'Show' }} Summary
3535
</button>
36+
<div v-if="loadingSummary"
37+
class="animate-spin rounded-full h-4 w-4 border-t-2 border-b-2 border-primary-500 mx-2">
38+
</div>
3639
</div>
3740
<transition
3841
enter-active-class="transition ease-out duration-200"
@@ -74,12 +77,9 @@ interface SearchResultProps {
7477
7578
const { result } = defineProps<SearchResultProps>()
7679
77-
const showSummary = ref(false)
78-
const summary = ref('')
7980
8081
const showPreview = ref(false)
8182
const preview = ref('')
82-
8383
const togglePreview = async () => {
8484
showPreview.value = !showPreview.value
8585
if (preview.value) {
@@ -90,14 +90,23 @@ const togglePreview = async () => {
9090
preview.value = URL.createObjectURL(await response.blob())
9191
}
9292
93+
const loadingSummary = ref(false)
94+
const showSummary = ref(false)
95+
const summary = ref('')
9396
const toggleSummary = async () => {
97+
loadingSummary.value = true
9498
showSummary.value = !showSummary.value
95-
if (result.summary) {
99+
if (summary.value) {
100+
loadingSummary.value = false
96101
return
97102
}
98103
99-
const response = await fetch(`${ENGINE_ENDPOINT}/summary/${result.id}`)
100-
summary.value = await response.text()
104+
summary.value = await fetch(`${ENGINE_ENDPOINT}/summary/${result.id}`)
105+
.then((res) => res.json())
106+
.then((data) => {
107+
loadingSummary.value = false
108+
return data.summary
109+
})
101110
}
102111
103112
//watch(() => result.url, downloadPreview, { immediate: true })

‎client/src/stores/search.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const dummyResults: SearchResult[] = [
2424
export const useSearchStore = defineStore('search', () => {
2525
const localStore = useLocal()
2626

27+
const lastQuery = ref('')
2728
const internalResults = ref<SearchResult[]>([])
2829
const results = computed(() => {
2930
const results = internalResults.value
@@ -35,10 +36,12 @@ export const useSearchStore = defineStore('search', () => {
3536

3637
function search(query: string) {
3738
if (query === '') {
38-
internalResults.value = dummyResults
39+
internalResults.value = []
3940
return
4041
}
4142

43+
lastQuery.value = query
44+
4245
return fetch(`${ENGINE_ENDPOINT}/search?query=${query}`)
4346
.then((response) => response.json())
4447
.then((data: ApiSearchResultsResponse) => {
@@ -51,6 +54,7 @@ export const useSearchStore = defineStore('search', () => {
5154
return {
5255
results,
5356
lastSearches,
57+
lastQuery,
5458
search
5559
}
5660
})

‎client/src/views/SearchView.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
{{ lastSearch }}
3939
</span>
4040
</div>
41+
<div v-if="searched && results.length > 0" class="text-gray-600 mt-8">
42+
Found {{ results.length }} {{ results.length === 0 ? 'door' : 'doors' }} for "{{ lastQuery }}"
43+
</div>
4144
<div v-if="loading" class="text-center text-gray-600 mt-8">
4245
<div class="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-tertiary-500 mx-auto"></div>
4346
<p class="mt-4">{{ TITLE }}</p>
@@ -56,7 +59,7 @@
5659
</li>
5760
</transition-group>
5861
<p v-else-if="searched && results.length === 0" class="text-center text-gray-600 mt-8">
59-
No results found. Try another search term.
62+
No doors found for "{{ lastQuery }}". Try another search term.
6063
</p>
6164
</div>
6265
</div>
@@ -73,7 +76,7 @@ import { gsap } from 'gsap'
7376
import SearchResult from '@/components/SearchResult.vue'
7477
7578
const searchStore = useSearchStore()
76-
const { results, lastSearches } = storeToRefs(searchStore)
79+
const { results, lastSearches, lastQuery } = storeToRefs(searchStore)
7780
7881
const loading = false
7982

0 commit comments

Comments
 (0)