Skip to content

Commit

Permalink
Items list: Fix searchbar broken after Items list update & Fix search…
Browse files Browse the repository at this point in the history
… query not stored (#2184)

Fixes #1334.
Fixes #1702.

After editing or removing an Item, the searchbar of the Items list was
sometimes not working anymore. Console then showed this error:
```
TypeError: undefined is not an object (evaluating
'n.virtualList.params')
```
  
It seems that this was caused because the replaceAllItems operation was
applied on the virtual list without re-rendering the searchbar
afterward.

The search query was forgotten when the Items list reloaded or the 
Items list page was re-entered from an Item detail page.
This is also fixed by using `$f7.data` to store the query.

---------

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
  • Loading branch information
florian-h05 authored Dec 7, 2023
1 parent 10da2fe commit 93a3e18
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
:text="(!$theme.md) ? ((showCheckboxes) ? 'Done' : 'Select') : ''" />
</f7-nav-right>
<f7-subnavbar :inner="false" v-show="ready">
<!-- Only render searchbar, if page is ready. Otherwise searchbar is broken after changes to the Items list. -->
<f7-searchbar
v-if="ready"
ref="searchbar"
class="searchbar-items"
search-container=".virtual-list"
Expand Down Expand Up @@ -64,7 +66,7 @@
ref="itemsList"
media-list
virtual-list
:virtual-list-params="{ items, searchAll, renderExternal, height }">
:virtual-list-params="vlParams">
<ul>
<f7-list-item
v-for="(item, index) in vlData.items"
Expand Down Expand Up @@ -144,10 +146,15 @@ export default {
return {
ready: false,
items: [], // [{ label: 'Staircase', name: 'Staircase'}],
indexedItems: {},
vlData: {
items: []
},
vlParams: {
items: [],
searchAll: this.searchAll,
renderExternal: this.renderExternal,
height: this.height
},
selectedItems: [],
showCheckboxes: false,
eventSource: null
Expand All @@ -159,9 +166,12 @@ export default {
},
onPageBeforeOut (event) {
this.stopEventSource()
this.$f7.data.lastItemSearchQuery = this.$refs.searchbar?.f7Searchbar.query
},
load () {
if (this.ready) this.$f7.data.lastItemSearchQuery = this.$refs.searchbar?.f7Searchbar.query
this.ready = false
this.$oh.api.get('/rest/items?metadata=semantics').then(data => {
this.items = data.sort((a, b) => {
const labelA = a.label || a.name
Expand All @@ -171,15 +181,11 @@ export default {
this.$refs.itemsList.f7VirtualList.replaceAllItems(this.items)
if (!this.eventSource) this.startEventSource()
// replaceAllItems() overrides search, run again
let searchbarQuery = this.$refs.searchbar.f7Searchbar.query
this.$refs.searchbar.clear() // same search doesn't get re-executed, reset first
this.$refs.searchbar.search(searchbarQuery)
this.$nextTick(() => {
if (this.$device.desktop) {
this.$refs.searchbar.f7Searchbar.$inputEl[0].focus()
this.$refs.searchbar?.f7Searchbar.$inputEl[0].focus()
}
this.$refs.searchbar?.f7Searchbar.search(this.$f7.data.lastItemSearchQuery || '')
})
this.ready = true
Expand Down

0 comments on commit 93a3e18

Please sign in to comment.