Skip to content

Commit

Permalink
Merge pull request #41792 from nextcloud/avoid-mutating-prop
Browse files Browse the repository at this point in the history
Handle close GlobalSearchModal gracefully
  • Loading branch information
susnux authored and Fenn-CS committed Nov 29, 2023
2 parents 1d825f3 + 2887956 commit ab654cb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
7 changes: 6 additions & 1 deletion core/src/components/GlobalSearch/SearchResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<NcListItem class="result-items__item"
:name="title"
:bold="false"
@click="openResult(result)">
@click="openResult(resourceUrl)">
<template #icon>
<div aria-hidden="true"
class="result-items__item-icon"
Expand Down Expand Up @@ -91,6 +91,11 @@ export default {
thumbnailErrorHandler() {
this.thumbnailHasError = true
},
openResult(url) {
if (url) {
window.location = url
}
},
},
}
</script>
Expand Down
5 changes: 4 additions & 1 deletion core/src/views/GlobalSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<Magnify class="global-search__trigger" :size="22" />
</template>
</NcButton>
<GlobalSearchModal :is-visible="showGlobalSearch" :class="'global-search-modal'" />
<GlobalSearchModal :class="'global-search-modal'" :is-visible="showGlobalSearch" @update:isVisible="handleModalVisibilityChange" />
</div>
</template>

Expand Down Expand Up @@ -54,6 +54,9 @@ export default {
toggleGlobalSearch() {
this.showGlobalSearch = !this.showGlobalSearch
},
handleModalVisibilityChange(newVisibilityVal) {
this.showGlobalSearch = newVisibilityVal
},
},
}
</script>
Expand Down
15 changes: 8 additions & 7 deletions core/src/views/GlobalSearchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<NcModal id="global-search"
ref="globalSearchModal"
:name="t('core', 'Global search')"
:show.sync="isVisible"
:show.sync="internalIsVisible"
:clear-view-delay="0"
:title="t('Global search')"
@close="closeModal">
Expand Down Expand Up @@ -200,6 +200,7 @@ export default {
contacts: [],
debouncedFind: debounce(this.find, 300),
showDateRangeModal: false,
internalIsVisible: false,
}
},
Expand All @@ -224,12 +225,17 @@ export default {
},
watch: {
isVisible(value) {
this.internalIsVisible = value
},
internalIsVisible(value) {
this.$emit('update:isVisible', value)
this.$nextTick(() => {
if (value) {
this.focusInput()
}
})
},
},
mounted() {
getProviders().then((providers) => {
Expand Down Expand Up @@ -343,11 +349,6 @@ export default {
})
this.results = sortedResults
},
openResult(result) {
if (result.resourceUrl) {
window.location = result.resourceUrl
}
},
mapContacts(contacts) {
return contacts.map(contact => {
return {
Expand Down Expand Up @@ -519,7 +520,7 @@ export default {
this.$refs.searchInput.$el.children[0].children[0].focus()
},
closeModal() {
this.$refs.globalSearchModal.close()
this.internalIsVisible = false
this.searchQuery = ''
},
supportFiltering() {
Expand Down
4 changes: 2 additions & 2 deletions dist/core-global-search.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-global-search.js.map

Large diffs are not rendered by default.

0 comments on commit ab654cb

Please sign in to comment.