Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make history page remember last query string & search limit #5192

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7098373
$ Simplify boolean assignment, rename session storage key
PikachuEXE May 30, 2024
7c0c69d
* Make history page remember last query string & search limit only wh…
PikachuEXE May 30, 2024
65c41b8
! Fix restoring filtered history having unnecessary delay
PikachuEXE Aug 20, 2024
66103ae
* Make subscribed channels page remember last query string only when …
PikachuEXE Aug 20, 2024
39b4079
* Make user playlists page remember last query string only when going…
PikachuEXE Aug 20, 2024
d7ce328
* Make playlist page remember last query string only when going back
PikachuEXE Aug 20, 2024
2f8fa91
* Make channel page remember last query string only when going back
PikachuEXE Aug 20, 2024
47222b9
Merge branch 'development' into feature/history/remember-search-query
PikachuEXE Sep 16, 2024
ce7c712
Merge branch 'development' into feature/history/remember-search-query
PikachuEXE Sep 21, 2024
54f4331
* Save more options
PikachuEXE Oct 1, 2024
5d7cac4
Merge branch 'development' into feature/history/remember-search-query
PikachuEXE Oct 3, 2024
52ad095
! Fix strange outline on nav buttons
PikachuEXE Oct 3, 2024
707f950
Merge branch 'development' into feature/history/remember-search-query
PikachuEXE Oct 7, 2024
1be051e
Merge branch 'development' into feature/history/remember-search-query
PikachuEXE Oct 12, 2024
49cd449
* Put `currentTab` value into proper place params instead of query
PikachuEXE Oct 13, 2024
cdc64d0
Merge branch 'development' into feature/history/remember-search-query
PikachuEXE Oct 16, 2024
03f887e
! Fix search tab showing "0 results" before search done
PikachuEXE Oct 16, 2024
a5f5a66
Merge branch 'development' into feature/history/remember-search-query
PikachuEXE Nov 24, 2024
6041e3a
- Remove useless file after merging dev
PikachuEXE Nov 24, 2024
82c92d3
$ Change code style
PikachuEXE Nov 28, 2024
cee5e9d
Merge branch 'development' into feature/history/remember-search-query
PikachuEXE Nov 29, 2024
ad83ebf
* Put event listener back to mounted
PikachuEXE Nov 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/renderer/components/ChannelDetails/ChannelDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
v-if="showSearchBar"
ref="searchBar"
:placeholder="$t('Channel.Search Channel')"
:value="query"
:show-clear-text-button="true"
class="channelSearch"
:maxlength="255"
Expand Down Expand Up @@ -275,7 +276,11 @@ const props = defineProps({
currentTab: {
type: String,
default: 'videos'
}
},
query: {
type: String,
default: ''
},
})

const emit = defineEmits(['change-tab', 'search', 'subscribed'])
Expand Down
86 changes: 74 additions & 12 deletions src/renderer/views/Channel/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
getLocalPlaylist,
parseLocalPlaylistVideo
} from '../../helpers/api/local'
import { isNavigationFailure, NavigationFailureType } from 'vue-router'

export default defineComponent({
name: 'Channel',
Expand All @@ -60,8 +61,10 @@ export default defineComponent({
},
data: function () {
return {
skipRouteChangeWatcherOnce: false,
isLoading: true,
isElementListLoading: false,
isSearchTabLoading: false,
currentTab: 'videos',
id: '',
/** @type {import('youtubei.js').YT.Channel|null} */
Expand Down Expand Up @@ -294,10 +297,22 @@ export default defineComponent({

return values
},

isCurrentTabLoading() {
if (this.currentTab === 'search') {
return this.isSearchTabLoading
}

return this.isElementListLoading
},
},
watch: {
$route() {
// react to route changes...
if (this.skipRouteChangeWatcherOnce) {
this.skipRouteChangeWatcherOnce = false
return
}
this.isLoading = true

if (this.$route.query.url) {
Expand Down Expand Up @@ -354,8 +369,9 @@ export default defineComponent({

// Re-enable auto refresh on sort value change AFTER update done
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
this.getChannelInfoInvidious()
this.autoRefreshOnSortByChangeEnabled = true
this.getChannelInfoInvidious().finally(() => {
this.autoRefreshOnSortByChangeEnabled = true
})
} else {
this.getChannelLocal().finally(() => {
this.autoRefreshOnSortByChangeEnabled = true
Expand Down Expand Up @@ -432,9 +448,9 @@ export default defineComponent({
}
}
},
mounted: function () {
mounted: async function () {
if (this.$route.query.url) {
this.resolveChannelUrl(this.$route.query.url, this.$route.params.currentTab)
await this.resolveChannelUrl(this.$route.query.url, this.$route.params.currentTab)
return
}

Expand All @@ -450,13 +466,19 @@ export default defineComponent({

// Enable auto refresh on sort value change AFTER initial update done
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
this.getChannelInfoInvidious()
this.autoRefreshOnSortByChangeEnabled = true
await this.getChannelInfoInvidious().finally(() => {
this.autoRefreshOnSortByChangeEnabled = true
})
} else {
this.getChannelLocal().finally(() => {
await this.getChannelLocal().finally(() => {
this.autoRefreshOnSortByChangeEnabled = true
})
}

const oldQuery = this.$route.query.searchQueryText ?? ''
if (oldQuery !== null && oldQuery !== '') {
this.newSearch(oldQuery)
}
Comment on lines +478 to +481
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you figure out what's messing with the query result sort order let me know
I read the rest of the code I don't think FT even tries to mess with the result sort order

},
methods: {
resolveChannelUrl: async function (url, tab = undefined) {
Expand Down Expand Up @@ -1010,7 +1032,7 @@ export default defineComponent({
this.channelInstance = null

const expectedId = this.id
invidiousGetChannelInfo(this.id).then((response) => {
return invidiousGetChannelInfo(this.id).then((response) => {
if (expectedId !== this.id) {
return
}
Expand Down Expand Up @@ -1872,13 +1894,14 @@ export default defineComponent({
const newTabNode = document.getElementById(`${tab}Tab`)
this.currentTab = tab
newTabNode?.focus()
this.showOutlines()
// Prevents outline shown in strange places
if (newTabNode != null) { this.showOutlines() }
},

newSearch: function (query) {
this.lastSearchQuery = query
this.searchContinuationData = null
this.isElementListLoading = true
this.isSearchTabLoading = true
this.searchPage = 1
this.searchResults = []
this.changeTab('search')
Expand All @@ -1891,6 +1914,10 @@ export default defineComponent({
break
}
},
newSearchWithStatePersist(query) {
this.saveStateInRouter(query)
this.newSearch(query)
},

searchChannelLocal: async function () {
const isNewSearch = this.searchContinuationData === null
Expand Down Expand Up @@ -1929,7 +1956,7 @@ export default defineComponent({
}

this.searchContinuationData = result.has_continuation ? result : null
this.isElementListLoading = false
this.isSearchTabLoading = false
} catch (err) {
console.error(err)
const errorMessage = this.$t('Local API Error (Click to copy)')
Expand Down Expand Up @@ -1965,7 +1992,7 @@ export default defineComponent({
} else {
this.searchResults = this.searchResults.concat(response)
}
this.isElementListLoading = false
this.isSearchTabLoading = false
this.searchPage++
}).catch((err) => {
console.error(err)
Expand Down Expand Up @@ -2009,6 +2036,41 @@ export default defineComponent({
})
},

async saveStateInRouter(query) {
this.skipRouteChangeWatcherOnce = true
if (query === '') {
try {
await this.$router.replace({ path: `/channel/${this.id}` })
} catch (failure) {
if (isNavigationFailure(failure, NavigationFailureType.duplicated)) {
return
}

throw failure
}
return
}

try {
await this.$router.replace({
path: `/channel/${this.id}`,
params: {
currentTab: 'search',
},
query: {
searchQueryText: query,
},
})
} catch (failure) {
if (isNavigationFailure(failure, NavigationFailureType.duplicated)) {
return
}

throw failure
}
this.skipRouteChangeWatcherOnce = false
},

getIconForSortPreference: (s) => getIconForSortPreference(s),

...mapActions([
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/views/Channel/Channel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
:is-subscribed="isSubscribed"
:visible-tabs="tabInfoValues"
:current-tab="currentTab"
:query="lastSearchQuery"
class="card channelDetails"
@change-tab="changeTab"
@search="newSearch"
@search="newSearchWithStatePersist"
@subscribed="handleSubscription"
/>
<ft-card
Expand Down Expand Up @@ -80,7 +81,7 @@
/>
</div>
<ft-loader
v-if="isElementListLoading"
v-if="isCurrentTabLoading"
/>
<div
v-if="currentTab !== 'about' && !isElementListLoading"
Expand Down Expand Up @@ -200,7 +201,7 @@
:use-channels-hidden-preference="false"
/>
<ft-flex-box
v-if="currentTab === 'search' && searchResults.length === 0"
v-if="currentTab === 'search' && !isSearchTabLoading && searchResults.length === 0"
>
<p class="message">
{{ $t("Channel.Your search results have returned 0 results") }}
Expand Down
87 changes: 74 additions & 13 deletions src/renderer/views/History/History.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineComponent } from 'vue'
import { isNavigationFailure, NavigationFailureType } from 'vue-router'
import debounce from 'lodash.debounce'
import FtLoader from '../../components/ft-loader/ft-loader.vue'
import FtCard from '../../components/ft-card/ft-card.vue'
Expand Down Expand Up @@ -63,42 +64,68 @@ export default defineComponent({
},
},
watch: {
query() {
this.searchDataLimit = 100
this.filterHistoryAsync()
},
fullData() {
this.filterHistory()
},
doCaseSensitiveSearch() {
this.filterHistory()
this.saveStateInRouter()
},
},
mounted: function () {
created: function () {
document.addEventListener('keydown', this.keyboardShortcutHandler)
const limit = sessionStorage.getItem('historyLimit')

if (limit !== null) {
this.dataLimit = limit
const oldDataLimit = sessionStorage.getItem('History/dataLimit')
if (oldDataLimit !== null) {
this.dataLimit = oldDataLimit
}

this.activeData = this.fullData

this.showLoadMoreButton = this.activeData.length < this.historyCacheSorted.length

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,
{
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()
}
},
beforeDestroy: function () {
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: {
handleQueryChange(query, { limit = null, doCaseSensitiveSearch = null, filterNow = false } = {}) {
this.query = query

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

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

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

increaseLimit: function () {
if (this.query !== '') {
this.searchDataLimit += 100
this.filterHistory()
} else {
this.dataLimit += 100
sessionStorage.setItem('historyLimit', this.dataLimit)
sessionStorage.setItem('History/dataLimit', this.dataLimit)
}
},
filterHistoryAsync: function() {
Expand All @@ -122,6 +149,40 @@ export default defineComponent({
this.activeData = filteredQuery.length < this.searchDataLimit ? filteredQuery : filteredQuery.slice(0, this.searchDataLimit)
this.showLoadMoreButton = this.activeData.length > this.searchDataLimit
},

async saveStateInRouter({ query = this.query, searchDataLimit = this.searchDataLimit, doCaseSensitiveSearch = this.doCaseSensitiveSearch } = {}) {
if (query === '') {
try {
await this.$router.replace({ name: 'history' })
} catch (failure) {
if (isNavigationFailure(failure, NavigationFailureType.duplicated)) {
return
}

throw failure
}
return
}

const routerQuery = {
searchQueryText: query,
searchDataLimit: searchDataLimit,
}
if (doCaseSensitiveSearch) { routerQuery.doCaseSensitiveSearch = 'true' }
try {
await this.$router.replace({
name: 'history',
query: routerQuery,
})
} catch (failure) {
if (isNavigationFailure(failure, NavigationFailureType.duplicated)) {
return
}

throw failure
}
},

keyboardShortcutHandler: function (event) {
ctrlFHandler(event, this.$refs.searchBar)
},
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/views/History/History.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
:placeholder="$t('History.Search bar placeholder')"
:show-clear-text-button="true"
:show-action-button="false"
@input="(input) => query = input"
@clear="query = ''"
:value="query"
@input="(input) => handleQueryChange(input)"
@clear="() => handleQueryChange('')"
/>
<div
class="optionsRow"
Expand Down
Loading
Loading