Skip to content

Commit

Permalink
* Save more options
Browse files Browse the repository at this point in the history
  • Loading branch information
PikachuEXE committed Oct 1, 2024
1 parent ce7c712 commit 54f4331
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
36 changes: 27 additions & 9 deletions src/renderer/views/History/History.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default defineComponent({
},
doCaseSensitiveSearch() {
this.filterHistory()
this.saveStateInRouter()
},
},
created: function () {
Expand All @@ -84,7 +85,14 @@ export default defineComponent({
const oldQuery = this.$route.query.searchQueryText ?? ''
if (oldQuery !== null && oldQuery !== '') {
// `handleQueryChange` must be called after `filterHistoryDebounce` assigned
this.handleQueryChange(oldQuery, this.$route.query.searchDataLimit, true)
this.handleQueryChange(
oldQuery,
{
limit: this.$route.query.searchDataLimit,
doCaseSensitiveSearch: this.$route.query.doCaseSensitiveSearch === 'true',
filterNow: true,
},
)
} else {
// Only display unfiltered data when no query used last time
this.filterHistory()
Expand All @@ -94,21 +102,26 @@ export default defineComponent({
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: {
handleQueryChange(val, customLimit = null, filterNow = false) {
this.query = val
handleQueryChange(query, { limit = null, doCaseSensitiveSearch = null, filterNow = false } = {}) {
this.query = query

const newLimit = customLimit ?? 100
const newLimit = limit ?? 100
this.searchDataLimit = newLimit
const newDoCaseSensitiveSearch = doCaseSensitiveSearch ?? this.doCaseSensitiveSearch
this.doCaseSensitiveSearch = newDoCaseSensitiveSearch

this.saveStateInRouter(val, newLimit)
this.saveStateInRouter({
query: query,
searchDataLimit: newLimit,
doCaseSensitiveSearch: newDoCaseSensitiveSearch,
})

filterNow ? this.filterHistory() : this.filterHistoryAsync()
},

increaseLimit: function () {
if (this.query !== '') {
this.searchDataLimit += 100
this.saveStateInRouter(this.query, this.searchDataLimit)
this.filterHistory()
} else {
this.dataLimit += 100
Expand Down Expand Up @@ -137,8 +150,8 @@ export default defineComponent({
this.showLoadMoreButton = this.activeData.length > this.searchDataLimit
},

async saveStateInRouter(query, searchDataLimit) {
if (this.query === '') {
async saveStateInRouter({ query = this.query, searchDataLimit = this.searchDataLimit, doCaseSensitiveSearch = this.doCaseSensitiveSearch } = {}) {
if (query === '') {
await this.$router.replace({ name: 'history' }).catch(failure => {
if (isNavigationFailure(failure, NavigationFailureType.duplicated)) {
return
Expand All @@ -149,9 +162,14 @@ export default defineComponent({
return
}

const routerQuery = {
searchQueryText: query,
searchDataLimit: searchDataLimit,
}
if (doCaseSensitiveSearch) { routerQuery.doCaseSensitiveSearch = 'true' }
await this.$router.replace({
name: 'history',
query: { searchQueryText: query, searchDataLimit: searchDataLimit },
query: routerQuery,
}).catch(failure => {
if (isNavigationFailure(failure, NavigationFailureType.duplicated)) {
return
Expand Down
34 changes: 27 additions & 7 deletions src/renderer/views/UserPlaylists/UserPlaylists.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export default defineComponent({
doSearchPlaylistsWithMatchingVideos() {
this.searchDataLimit = 100
this.filterPlaylistAsync()
this.saveStateInRouter()
},
fullData() {
this.activeData = this.fullData
Expand All @@ -201,7 +202,14 @@ export default defineComponent({
const oldQuery = this.$route.query.searchQueryText ?? ''
if (oldQuery !== null && oldQuery !== '') {
// `handleQueryChange` must be called after `filterHistoryDebounce` assigned
this.handleQueryChange(oldQuery, this.$route.query.searchDataLimit, true)
this.handleQueryChange(
oldQuery,
{
limit: this.$route.query.searchDataLimit,
doSearchPlaylistsWithMatchingVideos: this.$route.query.doSearchPlaylistsWithMatchingVideos === 'true',
filterNow: true,
},
)
} else {
// Only display unfiltered data when no query used last time
this.filterPlaylist()
Expand All @@ -211,20 +219,27 @@ export default defineComponent({
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: {
handleQueryChange(val, customLimit = null, filterNow = false) {
this.query = val
handleQueryChange(query, { limit = null, doSearchPlaylistsWithMatchingVideos = null, filterNow = false } = {}) {
this.query = query

const newLimit = customLimit ?? 100
const newLimit = limit ?? 100
this.searchDataLimit = newLimit
const newDoSearchPlaylistsWithMatchingVideos = doSearchPlaylistsWithMatchingVideos ?? this.doSearchPlaylistsWithMatchingVideos
this.doSearchPlaylistsWithMatchingVideos = newDoSearchPlaylistsWithMatchingVideos

this.saveStateInRouter(val, newLimit)
this.saveStateInRouter({
query: query,
searchDataLimit: newLimit,
doSearchPlaylistsWithMatchingVideos: newDoSearchPlaylistsWithMatchingVideos,
})

filterNow ? this.filterPlaylist() : this.filterPlaylistAsync()
},

increaseLimit: function () {
if (this.query !== '') {
this.searchDataLimit += 100
this.saveStateInRouter()
this.filterPlaylist()
} else {
this.dataLimit += 100
Expand Down Expand Up @@ -264,7 +279,7 @@ export default defineComponent({
})
},

async saveStateInRouter(query, searchDataLimit) {
async saveStateInRouter({ query = this.query, searchDataLimit = this.searchDataLimit, doSearchPlaylistsWithMatchingVideos = this.doSearchPlaylistsWithMatchingVideos } = {}) {
if (this.query === '') {
await this.$router.replace({ name: 'userPlaylists' }).catch(failure => {
if (isNavigationFailure(failure, NavigationFailureType.duplicated)) {
Expand All @@ -276,9 +291,14 @@ export default defineComponent({
return
}

const routerQuery = {
searchQueryText: query,
searchDataLimit: searchDataLimit,
}
if (doSearchPlaylistsWithMatchingVideos) { routerQuery.doSearchPlaylistsWithMatchingVideos = 'true' }
await this.$router.replace({
name: 'userPlaylists',
query: { searchQueryText: query, searchDataLimit: searchDataLimit },
query: routerQuery,
}).catch(failure => {
if (isNavigationFailure(failure, NavigationFailureType.duplicated)) {
return
Expand Down

0 comments on commit 54f4331

Please sign in to comment.