diff --git a/src/constants.js b/src/constants.js index 71febf58..ba55e79b 100644 --- a/src/constants.js +++ b/src/constants.js @@ -36,8 +36,7 @@ const DBActions = { }, HISTORY: { - UPDATE_WATCH_PROGRESS: 'db-action-history-update-watch-progress', - SEARCH: 'db-action-history-search' + UPDATE_WATCH_PROGRESS: 'db-action-history-update-watch-progress' }, PLAYLISTS: { diff --git a/src/datastores/handlers/base.js b/src/datastores/handlers/base.js index a968bebe..90b9d183 100644 --- a/src/datastores/handlers/base.js +++ b/src/datastores/handlers/base.js @@ -38,11 +38,6 @@ class History { return db.history.find({}).sort({ timeWatched: -1 }) } - static search(query) { - const re = new RegExp(query, 'i') - return db.history.find({ $or: [{ author: { $regex: re } }, { title: { $regex: re } }] }).sort({ timeWatched: -1 }) - } - static upsert(record) { return db.history.update({ videoId: record.videoId }, record, { upsert: true }) } diff --git a/src/datastores/handlers/electron.js b/src/datastores/handlers/electron.js index 96abc990..a054d7b5 100644 --- a/src/datastores/handlers/electron.js +++ b/src/datastores/handlers/electron.js @@ -25,13 +25,6 @@ class History { ) } - static search(query) { - return ipcRenderer.invoke( - IpcChannels.DB_HISTORY, - { action: DBActions.HISTORY.SEARCH, data: query } - ) - } - static upsert(record) { return ipcRenderer.invoke( IpcChannels.DB_HISTORY, diff --git a/src/datastores/handlers/web.js b/src/datastores/handlers/web.js index 3ec50213..bf7ee41f 100644 --- a/src/datastores/handlers/web.js +++ b/src/datastores/handlers/web.js @@ -25,10 +25,6 @@ class History { return baseHandlers.history.find() } - static search(query) { - return baseHandlers.history.search(query) - } - static upsert(record) { return baseHandlers.history.upsert(record) } diff --git a/src/datastores/index.js b/src/datastores/index.js index 11e1c5a2..713a0ea3 100644 --- a/src/datastores/index.js +++ b/src/datastores/index.js @@ -18,7 +18,4 @@ db.profiles = Datastore.create({ filename: dbPath('profiles'), autoload: true }) db.playlists = Datastore.create({ filename: dbPath('playlists'), autoload: true }) db.history = Datastore.create({ filename: dbPath('history'), autoload: true }) -db.history.ensureIndex({ fieldName: 'author' }) -db.history.ensureIndex({ fieldName: 'title' }) - export default db diff --git a/src/main/index.js b/src/main/index.js index d27f8947..dfc5efaa 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -456,9 +456,6 @@ function runApp() { ) return null - case DBActions.HISTORY.SEARCH: - return await baseHandlers.history.search(data) - case DBActions.GENERAL.DELETE: await baseHandlers.history.delete(data) syncOtherWindows( diff --git a/src/renderer/components/ft-list-video/ft-list-video.js b/src/renderer/components/ft-list-video/ft-list-video.js index b6f47767..b114947d 100644 --- a/src/renderer/components/ft-list-video/ft-list-video.js +++ b/src/renderer/components/ft-list-video/ft-list-video.js @@ -208,12 +208,6 @@ export default Vue.extend({ return this.$store.getters.getSaveWatchedProgress } }, - watch: { - data: function () { - this.parseVideoData() - this.checkIfWatched() - } - }, mounted: function () { this.parseVideoData() this.checkIfWatched() diff --git a/src/renderer/components/ft-video-player/ft-video-player.js b/src/renderer/components/ft-video-player/ft-video-player.js index 7616f5a8..95ff4cae 100644 --- a/src/renderer/components/ft-video-player/ft-video-player.js +++ b/src/renderer/components/ft-video-player/ft-video-player.js @@ -1414,7 +1414,7 @@ export default Vue.extend({ console.log(this.format) if (this.format !== 'dash') { this.showToast({ - message: 'Video statistics are not available for legacy videos' + message: this.$t('Video.Stats.Video statistics are not available for legacy videos') }) } else { this.showStatsModal = !this.showStatsModal diff --git a/src/renderer/store/modules/history.js b/src/renderer/store/modules/history.js index e6184dd4..cb36636c 100644 --- a/src/renderer/store/modules/history.js +++ b/src/renderer/store/modules/history.js @@ -1,16 +1,12 @@ import { DBHistoryHandlers } from '../../../datastores/handlers/index' const state = { - historyCache: [], - searchHistoryCache: [] + historyCache: [] } const getters = { getHistoryCache: () => { return state.historyCache - }, - getSearchHistoryCache: () => { - return state.searchHistoryCache } } @@ -51,15 +47,6 @@ const actions = { } }, - async searchHistory({ commit }, query) { - try { - const results = await DBHistoryHandlers.search(query) - commit('setSearchHistoryCache', results) - } catch (errMessage) { - console.error(errMessage) - } - }, - async updateWatchProgress({ commit }, { videoId, watchProgress }) { try { await DBHistoryHandlers.updateWatchProgress(videoId, watchProgress) @@ -79,10 +66,6 @@ const mutations = { state.historyCache = historyCache }, - setSearchHistoryCache(state, result) { - state.searchHistoryCache = result - }, - hoistEntryToTopOfHistoryCache(state, { currentIndex, updatedEntry }) { state.historyCache.splice(currentIndex, 1) state.historyCache.unshift(updatedEntry) diff --git a/src/renderer/store/modules/playlists.js b/src/renderer/store/modules/playlists.js index 984f352c..8bd9de51 100644 --- a/src/renderer/store/modules/playlists.js +++ b/src/renderer/store/modules/playlists.js @@ -13,20 +13,14 @@ const state = { removeOnWatched: true, videos: [] } - ], - searchPlaylistCache: { - videos: [] - } + ] } const getters = { getAllPlaylists: () => state.playlists, getFavorites: () => state.playlists[0], getPlaylist: (playlistId) => state.playlists.find(playlist => playlist._id === playlistId), - getWatchLater: () => state.playlists[1], - getSearchPlaylistCache: () => { - return state.searchPlaylistCache - } + getWatchLater: () => state.playlists[1] } const actions = { @@ -136,25 +130,10 @@ const actions = { } catch (errMessage) { console.error(errMessage) } - }, - async searchFavoritePlaylist({ commit }, query) { - const re = new RegExp(query, 'i') - // filtering in the frontend because the documents are the playlists and not the videos - const results = state.playlists[0].videos.slice() - .filter((video) => { - return video.author.match(re) || - video.title.match(re) - }) - commit('setPlaylistCache', results) } } const mutations = { - setPlaylistCache(state, result) { - state.searchPlaylistCache = { - videos: result - } - }, addPlaylist(state, payload) { state.playlists.push(payload) }, diff --git a/src/renderer/views/History/History.js b/src/renderer/views/History/History.js index a7e6834a..bf6569be 100644 --- a/src/renderer/views/History/History.js +++ b/src/renderer/views/History/History.js @@ -20,19 +20,19 @@ export default Vue.extend({ return { isLoading: false, dataLimit: 100, - hasQuery: false + searchDataLimit: 100, + showLoadMoreButton: false, + hasQuery: false, + query: '', + activeData: [] } }, computed: { historyCache: function () { - if (!this.hasQuery) { - return this.$store.getters.getHistoryCache - } else { - return this.$store.getters.getSearchHistoryCache - } + return this.$store.getters.getHistoryCache }, - activeData: function () { + fullData: function () { if (this.historyCache.length < this.dataLimit) { return this.historyCache } else { @@ -40,30 +40,79 @@ export default Vue.extend({ } } }, - + watch: { + query() { + this.searchDataLimit = 100 + this.filterHistory() + }, + activeData() { + this.refreshPage() + }, + fullData() { + this.activeData = this.fullData + this.filterHistory() + } + }, mounted: function () { - console.log(this.historyCache) - const limit = sessionStorage.getItem('historyLimit') if (limit !== null) { this.dataLimit = limit } + + this.activeData = this.fullData + + if (this.activeData.length < this.historyCache.length) { + this.showLoadMoreButton = true + } else { + this.showLoadMoreButton = false + } }, methods: { increaseLimit: function () { - this.dataLimit += 100 - sessionStorage.setItem('historyLimit', this.dataLimit) + if (this.query !== '') { + this.searchDataLimit += 100 + this.filterHistory() + } else { + this.dataLimit += 100 + sessionStorage.setItem('historyLimit', this.dataLimit) + } }, filterHistory: function(query) { - this.hasQuery = query !== '' - this.$store.dispatch('searchHistory', query) + if (this.query === '') { + this.activeData = this.fullData + if (this.activeData.length < this.historyCache.length) { + this.showLoadMoreButton = true + } else { + this.showLoadMoreButton = false + } + } else { + const filteredQuery = this.historyCache.filter((video) => { + if (typeof (video.title) !== 'string' || typeof (video.author) !== 'string') { + return false + } else { + return video.title.toLowerCase().includes(this.query.toLowerCase()) || video.author.toLowerCase().includes(this.query.toLowerCase()) + } + }).sort((a, b) => { + return b.timeWatched - a.timeWatched + }) + if (filteredQuery.length <= this.searchDataLimit) { + this.showLoadMoreButton = false + } else { + this.showLoadMoreButton = true + } + this.activeData = filteredQuery.length < this.searchDataLimit ? filteredQuery : filteredQuery.slice(0, this.searchDataLimit) + } }, - load: function() { + refreshPage: function() { + const scrollPos = window.scrollY || window.scrollTop || document.getElementsByTagName('html')[0].scrollTop this.isLoading = true - setTimeout(() => { + Vue.nextTick(() => { this.isLoading = false - }, 100) + Vue.nextTick(() => { + window.scrollTo(0, scrollPos) + }) + }) } } }) diff --git a/src/renderer/views/History/History.vue b/src/renderer/views/History/History.vue index 8cd99ad7..51beb48f 100644 --- a/src/renderer/views/History/History.vue +++ b/src/renderer/views/History/History.vue @@ -1,11 +1,11 @@