Skip to content

Commit 23a9138

Browse files
committed
Prevent empty search placeholder
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent 301006a commit 23a9138

9 files changed

Lines changed: 43 additions & 34 deletions

apps/settings/js/vue-settings-apps-7d82ca79b672ef6a7e07.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

apps/settings/js/vue-settings-apps-7d82ca79b672ef6a7e07.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

apps/settings/js/vue-settings-users-c5e2ef8b045ac76fa60c.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

apps/settings/js/vue-settings-users-c5e2ef8b045ac76fa60c.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

core/js/dist/recommendedapps.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/js/dist/recommendedapps.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/js/dist/unified-search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/js/dist/unified-search.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/views/UnifiedSearch.vue

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ import HeaderMenu from '../components/HeaderMenu'
133133
import SearchResult from '../components/UnifiedSearch/SearchResult'
134134
import SearchResultPlaceholders from '../components/UnifiedSearch/SearchResultPlaceholders'
135135
136+
const REQUEST_FAILED = 0
137+
const REQUEST_OK = 1
138+
const REQUEST_CANCELED = 2
139+
136140
export default {
137141
name: 'UnifiedSearch',
138142
@@ -325,22 +329,25 @@ export default {
325329
this.resetState()
326330
this.focusInput()
327331
},
328-
resetState() {
332+
async resetState() {
329333
this.cursors = {}
330334
this.limits = {}
331-
this.loading = {}
332335
this.reached = {}
333336
this.results = {}
334337
this.focused = null
335-
this.cancelPendingRequests()
338+
await this.cancelPendingRequests()
336339
},
337340
338341
/**
339342
* Cancel any ongoing searches
340343
*/
341-
cancelPendingRequests() {
344+
async cancelPendingRequests() {
345+
// Cloning so we can keep processing other requests
346+
const requests = this.requests.slice(0)
347+
this.requests = []
348+
342349
// Cancel all pending requests
343-
this.requests.forEach(cancel => cancel())
350+
await Promise.all(requests.map(cancel => cancel()))
344351
},
345352
346353
/**
@@ -394,19 +401,18 @@ export default {
394401
// Remove any filters from the query
395402
query = query.replace(regexFilterIn, '').replace(regexFilterNot, '')
396403
397-
this.logger.debug(`Searching ${query} in`, types)
398-
399404
// Reset search if the query changed
400-
this.resetState()
405+
await this.resetState()
406+
this.$set(this.loading, 'all', true)
407+
this.logger.debug(`Searching ${query} in`, types)
401408
402409
Promise.all(types.map(async type => {
403410
try {
404411
// Init cancellable request
405412
const { request, cancel } = search({ type, query })
406413
this.requests.push(cancel)
407414
408-
// Mark this type as loading and fetch results
409-
this.$set(this.loading, type, true)
415+
// Fetch results
410416
const { data } = await request()
411417
412418
// Process results
@@ -434,18 +440,24 @@ export default {
434440
if (this.focused === null) {
435441
this.focused = 0
436442
}
443+
return REQUEST_OK
437444
} catch (error) {
445+
this.$delete(this.results, type)
446+
438447
// If this is not a cancelled throw
439448
if (error.response && error.response.status) {
440449
this.logger.error(`Error searching for ${this.typesMap[type]}`, error)
441450
showError(this.t('core', 'An error occurred while searching for {type}', { type: this.typesMap[type] }))
451+
return REQUEST_FAILED
442452
}
443-
444-
this.$delete(this.results, type)
445-
} finally {
446-
this.$set(this.loading, type, false)
453+
return REQUEST_CANCELED
454+
}
455+
})).then(results => {
456+
// Do not declare loading finished if the request have been cancelled
457+
// This means another search was triggered and we're therefore still loading
458+
if (results.some(result => result === REQUEST_CANCELED)) {
459+
return
447460
}
448-
})).then(() => {
449461
// We finished all searches
450462
this.loading = {}
451463
})
@@ -463,22 +475,27 @@ export default {
463475
if (this.loading[type]) {
464476
return
465477
}
466-
this.$set(this.loading, type, true)
467478
468479
if (this.cursors[type]) {
469-
const request = await search({ type, query: this.query, cursor: this.cursors[type] })
480+
// Init cancellable request
481+
const { request, cancel } = search({ type, query: this.query, cursor: this.cursors[type] })
482+
this.requests.push(cancel)
483+
484+
// Fetch results
485+
const { data } = await request()
470486
471487
// Save cursor if any
472-
if (request.data.ocs.data.cursor) {
473-
this.$set(this.cursors, type, request.data.ocs.data.cursor)
488+
if (data.ocs.data.cursor) {
489+
this.$set(this.cursors, type, data.ocs.data.cursor)
474490
}
475491
476-
if (request.data.ocs.data.entries.length > 0) {
477-
this.results[type].push(...request.data.ocs.data.entries)
492+
// Process results
493+
if (data.ocs.data.entries.length > 0) {
494+
this.results[type].push(...data.ocs.data.entries)
478495
}
479496
480497
// Check if we reached end of pagination
481-
if (request.data.ocs.data.entries.length < this.defaultLimit) {
498+
if (data.ocs.data.entries.length < this.defaultLimit) {
482499
this.$set(this.reached, type, true)
483500
}
484501
} else
@@ -500,8 +517,6 @@ export default {
500517
this.focusIndex(this.focused)
501518
})
502519
}
503-
504-
this.$set(this.loading, type, false)
505520
},
506521
507522
/**

0 commit comments

Comments
 (0)