diff --git a/src/constants.js b/src/constants.js index 282443998..5c7f9ed46 100644 --- a/src/constants.js +++ b/src/constants.js @@ -17,9 +17,9 @@ const IpcChannels = { DB_SETTINGS: 'db-settings', DB_HISTORY: 'db-history', - DB_SEARCH_HISTORY: 'db-search-history', DB_PROFILES: 'db-profiles', DB_PLAYLISTS: 'db-playlists', + DB_SEARCH_HISTORY: 'db-search-history', SYNC_SETTINGS: 'sync-settings', SYNC_HISTORY: 'sync-history', diff --git a/src/datastores/handlers/base.js b/src/datastores/handlers/base.js index 302a567f6..d715669cb 100644 --- a/src/datastores/handlers/base.js +++ b/src/datastores/handlers/base.js @@ -193,11 +193,11 @@ class SearchHistory { } static upsert(pageBookmark) { - return db.searchHistory.updateAsync({ _id: pageBookmark.route }, pageBookmark, { upsert: true }) + return db.searchHistory.updateAsync({ _id: pageBookmark._id }, pageBookmark, { upsert: true }) } static delete(route) { - return db.searchHistory.removeAsync({ _id: route }) + return db.searchHistory.removeAsync({ route: route }) } static deleteAll() { diff --git a/src/main/index.js b/src/main/index.js index d364a5454..72ba55690 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1071,15 +1071,15 @@ function runApp() { ipcMain.handle(IpcChannels.DB_SEARCH_HISTORY, async (event, { action, data }) => { try { switch (action) { - case DBActions.GENERAL.CREATE: - await baseHandlers.searchHistory.create(data) + case DBActions.GENERAL.CREATE: { + const pageBookmark = await baseHandlers.searchHistory.create(data) syncOtherWindows( IpcChannels.SYNC_SEARCH_HISTORY, event, { event: SyncEvents.GENERAL.CREATE, data } ) - return null - + return pageBookmark + } case DBActions.GENERAL.FIND: return await baseHandlers.searchHistory.find() diff --git a/src/renderer/App.js b/src/renderer/App.js index ffef75879..2abf4fd65 100644 --- a/src/renderer/App.js +++ b/src/renderer/App.js @@ -171,6 +171,7 @@ export default defineComponent({ this.grabAllProfiles(this.$t('Profile.All Channels')).then(async () => { this.grabHistory() + this.grabPageBookmarks() this.grabAllPlaylists() if (process.env.IS_ELECTRON) { @@ -539,6 +540,7 @@ export default defineComponent({ 'grabUserSettings', 'grabAllProfiles', 'grabHistory', + 'grabPageBookmarks', 'grabAllPlaylists', 'getYoutubeUrlInfo', 'getExternalPlayerCmdArgumentsData', diff --git a/src/renderer/components/ft-input/ft-input.css b/src/renderer/components/ft-input/ft-input.css index e5f9a1704..ba2d3dab5 100644 --- a/src/renderer/components/ft-input/ft-input.css +++ b/src/renderer/components/ft-input/ft-input.css @@ -205,6 +205,10 @@ line-height: 2rem; } +/* .list .li.bookmarked { + color: green; +} */ + .hover { background-color: var(--scrollbar-color-hover); color: var(--scrollbar-text-color-hover); diff --git a/src/renderer/components/ft-input/ft-input.js b/src/renderer/components/ft-input/ft-input.js index 9c3bfc197..0e23e1809 100644 --- a/src/renderer/components/ft-input/ft-input.js +++ b/src/renderer/components/ft-input/ft-input.js @@ -231,9 +231,13 @@ export default defineComponent({ } }, - handleOptionClick: function (index) { + handleOptionClick: function (index, isBookmark) { this.searchState.showOptions = false - this.inputData = this.visibleDataList[index] + if (isBookmark) { + this.inputData = `ft:${this.visibleDataList[index].route}` + } else { + this.inputData = this.visibleDataList[index] + } this.$emit('input', this.inputData) this.handleClick() }, @@ -307,6 +311,10 @@ export default defineComponent({ const lowerCaseInputData = this.inputData.toLowerCase() this.visibleDataList = this.dataList.filter(x => { + if (x.bookmarkName) { + return x.bookmarkName.toLowerCase().indexOf(lowerCaseInputData) !== -1 + } + return x.toLowerCase().indexOf(lowerCaseInputData) !== -1 }) }, diff --git a/src/renderer/components/ft-input/ft-input.vue b/src/renderer/components/ft-input/ft-input.vue index c9a7c8523..a4e20f873 100644 --- a/src/renderer/components/ft-input/ft-input.vue +++ b/src/renderer/components/ft-input/ft-input.vue @@ -76,14 +76,18 @@ >
  • - {{ list }} + + {{ entry.bookmarkName ?? entry }}
  • diff --git a/src/renderer/components/top-nav/top-nav.js b/src/renderer/components/top-nav/top-nav.js index 2164401d0..998b93e20 100644 --- a/src/renderer/components/top-nav/top-nav.js +++ b/src/renderer/components/top-nav/top-nav.js @@ -97,14 +97,14 @@ export default defineComponent({ return this.$t('Open New Window') }, - // currentRouteFullPath: function () { - // return this.$router.currentRoute.fullPath - // }, - isPageBookmarked: function () { return this.$store.getters.getPageBookmarkWithRoute(this.currentRouteFullPath) != null }, + matchingBookmarksDataList: function () { + return this.$store.getters.getPageBookmarksWithRouteSubstring(this.lastSuggestionQuery, this.currentRouteFullPath) + }, + pageBookmarkIconTitle: function () { return this.isPageBookmarked ? this.$t('Edit bookmark for this page') : this.$t('Bookmark this page') }, @@ -124,6 +124,7 @@ export default defineComponent({ this.showSearchContainer = false } + this.currentRouteFullPath = this.$router.currentRoute.fullPath // Store is not up-to-date when the component mounts, so we use timeout. setTimeout(() => { if (this.expandSideBar) { diff --git a/src/renderer/components/top-nav/top-nav.vue b/src/renderer/components/top-nav/top-nav.vue index ca18e9700..3f7f00af8 100644 --- a/src/renderer/components/top-nav/top-nav.vue +++ b/src/renderer/components/top-nav/top-nav.vue @@ -84,7 +84,7 @@ :placeholder="$t('Search / Go to URL')" class="searchInput" :is-search="true" - :data-list="searchSuggestionsDataList" + :data-list="[...matchingBookmarksDataList, ...searchSuggestionsDataList]" :spellcheck="false" :show-clear-text-button="true" @input="getSearchSuggestionsDebounce" diff --git a/src/renderer/store/modules/search-history.js b/src/renderer/store/modules/search-history.js index 9ecf15bd0..cb38fefce 100644 --- a/src/renderer/store/modules/search-history.js +++ b/src/renderer/store/modules/search-history.js @@ -12,12 +12,36 @@ const getters = { getPageBookmarkWithRoute: (state) => (route) => { const pageBookmark = state.pageBookmarks.find(p => p.route === route) return pageBookmark + }, + + getPageBookmarksWithRouteSubstring: (state) => (routeSubstring, routeToExclude) => { + if (routeSubstring === '') { + return [] + } + const routeSubstringToLower = routeSubstring.toLowerCase() + const pageBookmarks = state.pageBookmarks.filter((pageBookmark) => + pageBookmark && pageBookmark.route.toLowerCase().includes(routeSubstringToLower) && pageBookmark.route !== routeToExclude + ) + return pageBookmarks } } - const actions = { + async grabPageBookmarks({ commit }) { + try { + const results = await DBSearchHistoryHandlers.find() + commit('setPageBookmarks', results) + } catch (errMessage) { + console.error(errMessage) + } + }, + async createPageBookmark({ commit }, pageBookmark) { - state.pageBookmarks.push(pageBookmark) + try { + const newPageBookmark = await DBSearchHistoryHandlers.create(pageBookmark) + commit('addPageBookmarkToList', newPageBookmark) + } catch (errMessage) { + console.error(errMessage) + } }, async updatePageBookmark({ commit }, pageBookmark) { @@ -49,6 +73,10 @@ const actions = { } const mutations = { + addPageBookmarkToList(state, pageBookmark) { + state.pageBookmarks.push(pageBookmark) + }, + setPageBookmarks(state, pageBookmarks) { state.pageBookmarks = pageBookmarks }, @@ -65,9 +93,9 @@ const mutations = { } }, - removePageBookmarkFromList(state, pageBookmarkId) { + removePageBookmarkFromList(state, route) { const i = state.pageBookmarks.findIndex((pageBookmark) => { - return pageBookmark.route === pageBookmarkId + return pageBookmark.route === route }) state.pageBookmarks.splice(i, 1)