mirror of
https://github.com/FreeTubeApp/FreeTube
synced 2024-11-29 13:40:40 +01:00
* Make history page remember last query string & search limit only when going back
This commit is contained in:
parent
70983739f6
commit
7c0c69dc42
@ -1,4 +1,5 @@
|
|||||||
import { defineComponent } from 'vue'
|
import { defineComponent } from 'vue'
|
||||||
|
import { isNavigationFailure, NavigationFailureType } from 'vue-router'
|
||||||
import debounce from 'lodash.debounce'
|
import debounce from 'lodash.debounce'
|
||||||
import FtLoader from '../../components/ft-loader/ft-loader.vue'
|
import FtLoader from '../../components/ft-loader/ft-loader.vue'
|
||||||
import FtCard from '../../components/ft-card/ft-card.vue'
|
import FtCard from '../../components/ft-card/ft-card.vue'
|
||||||
@ -63,10 +64,6 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
query() {
|
|
||||||
this.searchDataLimit = 100
|
|
||||||
this.filterHistoryAsync()
|
|
||||||
},
|
|
||||||
fullData() {
|
fullData() {
|
||||||
this.filterHistory()
|
this.filterHistory()
|
||||||
},
|
},
|
||||||
@ -76,25 +73,42 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
created: function () {
|
created: function () {
|
||||||
document.addEventListener('keydown', this.keyboardShortcutHandler)
|
document.addEventListener('keydown', this.keyboardShortcutHandler)
|
||||||
const limit = sessionStorage.getItem('History/dataLimit')
|
|
||||||
|
|
||||||
if (limit !== null) {
|
const oldDataLimit = sessionStorage.getItem('History/dataLimit')
|
||||||
this.dataLimit = limit
|
if (oldDataLimit !== null) {
|
||||||
|
this.dataLimit = oldDataLimit
|
||||||
}
|
}
|
||||||
|
|
||||||
this.activeData = this.fullData
|
|
||||||
|
|
||||||
this.showLoadMoreButton = this.activeData.length < this.historyCacheSorted.length
|
|
||||||
|
|
||||||
this.filterHistoryDebounce = debounce(this.filterHistory, 500)
|
this.filterHistoryDebounce = debounce(this.filterHistory, 500)
|
||||||
|
|
||||||
|
const oldQuery = this.$route.query.searchQueryText ?? ''
|
||||||
|
if (oldQuery !== null && oldQuery !== '') {
|
||||||
|
// `handleQueryChange` must be called after `filterHistoryDebounce` assigned
|
||||||
|
this.handleQueryChange(oldQuery, this.$route.query.searchDataLimit)
|
||||||
|
} else {
|
||||||
|
// Only display unfiltered data when no query used last time
|
||||||
|
this.filterHistory()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy: function () {
|
beforeDestroy: function () {
|
||||||
document.removeEventListener('keydown', this.keyboardShortcutHandler)
|
document.removeEventListener('keydown', this.keyboardShortcutHandler)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
handleQueryChange(val, customLimit = null) {
|
||||||
|
this.query = val
|
||||||
|
|
||||||
|
const newLimit = customLimit ?? 100
|
||||||
|
this.searchDataLimit = newLimit
|
||||||
|
|
||||||
|
this.saveStateInRouter(val, newLimit)
|
||||||
|
|
||||||
|
this.filterHistoryAsync()
|
||||||
|
},
|
||||||
|
|
||||||
increaseLimit: function () {
|
increaseLimit: function () {
|
||||||
if (this.query !== '') {
|
if (this.query !== '') {
|
||||||
this.searchDataLimit += 100
|
this.searchDataLimit += 100
|
||||||
|
this.saveStateInRouter(this.query, this.searchDataLimit)
|
||||||
this.filterHistory()
|
this.filterHistory()
|
||||||
} else {
|
} else {
|
||||||
this.dataLimit += 100
|
this.dataLimit += 100
|
||||||
@ -122,6 +136,31 @@ export default defineComponent({
|
|||||||
this.activeData = filteredQuery.length < this.searchDataLimit ? filteredQuery : filteredQuery.slice(0, this.searchDataLimit)
|
this.activeData = filteredQuery.length < this.searchDataLimit ? filteredQuery : filteredQuery.slice(0, this.searchDataLimit)
|
||||||
this.showLoadMoreButton = this.activeData.length > this.searchDataLimit
|
this.showLoadMoreButton = this.activeData.length > this.searchDataLimit
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async saveStateInRouter(query, searchDataLimit) {
|
||||||
|
if (this.query === '') {
|
||||||
|
await this.$router.replace({ name: 'history' }).catch(failure => {
|
||||||
|
if (isNavigationFailure(failure, NavigationFailureType.duplicated)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
throw failure
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.$router.replace({
|
||||||
|
name: 'history',
|
||||||
|
query: { searchQueryText: query, searchDataLimit: searchDataLimit },
|
||||||
|
}).catch(failure => {
|
||||||
|
if (isNavigationFailure(failure, NavigationFailureType.duplicated)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
throw failure
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
keyboardShortcutHandler: function (event) {
|
keyboardShortcutHandler: function (event) {
|
||||||
ctrlFHandler(event, this.$refs.searchBar)
|
ctrlFHandler(event, this.$refs.searchBar)
|
||||||
},
|
},
|
||||||
|
@ -15,8 +15,9 @@
|
|||||||
:placeholder="$t('History.Search bar placeholder')"
|
:placeholder="$t('History.Search bar placeholder')"
|
||||||
:show-clear-text-button="true"
|
:show-clear-text-button="true"
|
||||||
:show-action-button="false"
|
:show-action-button="false"
|
||||||
@input="(input) => query = input"
|
:value="query"
|
||||||
@clear="query = ''"
|
@input="(input) => handleQueryChange(input)"
|
||||||
|
@clear="() => handleQueryChange('')"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="optionsRow"
|
class="optionsRow"
|
||||||
|
Loading…
Reference in New Issue
Block a user