Skip to content

Commit a6375c7

Browse files
committed
Update logic to allowing storing and searching by name rather than by route
This is much more efficient for search history particularly. No need for app-specific routes and easier operations & logic due to name being the primary key for search history entries. This still allows for the route to be used as the _id for different kinds of search history (i.e., bookmarks) that could be added in the future.
1 parent 10e17ef commit a6375c7

File tree

6 files changed

+29
-62
lines changed

6 files changed

+29
-62
lines changed

src/renderer/components/ft-input/ft-input.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export default defineComponent({
6363
type: Array,
6464
default: () => { return [] }
6565
},
66+
searchResultIcon: {
67+
type: Array,
68+
default: null
69+
},
6670
showDataWhenEmpty: {
6771
type: Boolean,
6872
default: false
@@ -151,7 +155,7 @@ export default defineComponent({
151155
},
152156
methods: {
153157
getTextForArrayAtIndex: function (array, index) {
154-
return array[index].name ?? array[index]
158+
return array[index]
155159
},
156160
handleClick: function (e) {
157161
// No action if no input text
@@ -244,15 +248,9 @@ export default defineComponent({
244248

245249
handleOptionClick: function (index) {
246250
this.searchState.showOptions = false
247-
const isSearchHistoryClick = this.visibleDataList[index].route
248-
this.inputData = isSearchHistoryClick ? `ft:${this.visibleDataList[index].route}` : this.visibleDataList[index]
251+
this.inputData = this.visibleDataList[index]
249252
this.$emit('input', this.inputData)
250253
this.handleClick()
251-
252-
// update displayed label to match name of the search history entry
253-
if (isSearchHistoryClick) {
254-
this.inputData = this.$refs.input.value = this.visibleDataList[index].name
255-
}
256254
},
257255

258256
/**
@@ -325,10 +323,6 @@ export default defineComponent({
325323
const lowerCaseInputData = this.inputData.toLowerCase()
326324

327325
this.visibleDataList = this.dataList.filter(x => {
328-
if (x.name) {
329-
return x.name.toLowerCase().indexOf(lowerCaseInputData) !== -1
330-
}
331-
332326
return x.toLowerCase().indexOf(lowerCaseInputData) !== -1
333327
})
334328
},

src/renderer/components/ft-input/ft-input.vue

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
showActionButton: showActionButton,
99
showClearTextButton: showClearTextButton,
1010
clearTextButtonVisible: inputDataPresent || showOptions,
11+
inputDataPresent: inputDataPresent,
1112
showOptions: showOptions,
1213
disabled: disabled
1314
}"
@@ -84,16 +85,11 @@
8485
@mouseleave="searchState.selectedOption = -1"
8586
>
8687
<font-awesome-icon
87-
v-if="entry.name"
88-
:icon="['fas', 'clock-rotate-left']"
89-
class="searchResultIcon bookmarkStarIcon"
90-
/>
91-
<font-awesome-icon
92-
v-else-if="isSearch"
93-
:icon="['fas', 'magnifying-glass']"
88+
v-if="searchResultIcon"
89+
:icon="searchResultIcon"
9490
class="searchResultIcon"
9591
/>
96-
{{ entry.name ?? entry }}
92+
{{ entry }}
9793
</li>
9894
<!-- skipped -->
9995
</ul>

src/renderer/components/top-nav/top-nav.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,12 @@ export default defineComponent({
127127
if (!this.enableSearchSuggestions) {
128128
return
129129
}
130-
return this.lastSuggestionQuery === '' ? this.$store.getters.getLatestUniqueSearchHistoryEntries : this.searchSuggestionsDataList
130+
return this.lastSuggestionQuery === '' ? this.$store.getters.getLatestUniqueSearchHistoryNames : this.searchSuggestionsDataList
131131
},
132+
133+
searchResultIcon: function () {
134+
return this.lastSuggestionQuery === '' ? ['fas', 'clock-rotate-left'] : ['fas', 'magnifying-glass']
135+
}
132136
},
133137
watch: {
134138
$route: function () {
@@ -167,32 +171,15 @@ export default defineComponent({
167171
goToSearch: async function (queryText, { event }) {
168172
const doCreateNewWindow = event && event.shiftKey
169173

170-
const isFreeTubeInternalQuery = queryText.startsWith('ft:')
171-
172174
if (window.innerWidth <= MOBILE_WIDTH_THRESHOLD) {
173175
this.$refs.searchContainer.blur()
174176
this.showSearchContainer = false
175-
} else if (!isFreeTubeInternalQuery) {
177+
} else {
176178
this.$refs.searchInput.blur()
177179
}
178180

179181
clearLocalSearchSuggestionsSession()
180182

181-
if (isFreeTubeInternalQuery) {
182-
const adjustedQuery = queryText.substring(3)
183-
if (this.$router.currentRoute.fullPath !== adjustedQuery) {
184-
openInternalPath({
185-
path: adjustedQuery,
186-
adjustedQuery,
187-
doCreateNewWindow
188-
})
189-
}
190-
191-
// update in-use search query to the selected search history entry name
192-
this.lastSuggestionQuery = this.$store.getters.getSearchHistoryEntryWithRoute(adjustedQuery)?.name ?? ''
193-
return
194-
}
195-
196183
this.getYoutubeUrlInfo(queryText).then((result) => {
197184
switch (result.urlType) {
198185
case 'video': {
@@ -315,7 +302,7 @@ export default defineComponent({
315302

316303
getSearchSuggestionsDebounce: function (query) {
317304
const trimmedQuery = query.trim()
318-
if (trimmedQuery === this.lastSuggestionQuery || trimmedQuery.startsWith('ft:')) {
305+
if (trimmedQuery === this.lastSuggestionQuery) {
319306
return
320307
}
321308

src/renderer/components/top-nav/top-nav.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@
9393
class="searchInput"
9494
:is-search="true"
9595
:data-list="activeDataList"
96+
:search-result-icon="searchResultIcon"
9697
:spellcheck="false"
9798
:show-clear-text-button="true"
9899
:show-data-when-empty="true"
99100
@input="getSearchSuggestionsDebounce"
100101
@click="goToSearch"
101-
@clear="lastSuggestionQuery = ''"
102102
/>
103103
<font-awesome-icon
104104
class="navFilterIcon navIcon"

src/renderer/store/modules/search-history.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,30 @@ const getters = {
1212
return state.searchHistoryEntries
1313
},
1414

15-
getLatestUniqueSearchHistoryEntries: (state) => {
16-
const nameSet = new Set()
17-
return state.searchHistoryEntries.filter((entry) => {
18-
if (nameSet.has(entry.name)) {
19-
return false
20-
}
21-
22-
nameSet.add(entry.name)
23-
return true
24-
}).slice(0, SEARCH_HISTORY_ENTRIES_DISPLAY_LIMIT)
15+
getLatestUniqueSearchHistoryNames: (state) => {
16+
return state.searchHistoryEntries.slice(0, SEARCH_HISTORY_ENTRIES_DISPLAY_LIMIT).map((entry) => entry.name)
2517
},
2618

27-
getSearchHistoryEntryWithRoute: (state) => (route) => {
28-
const searchHistoryEntry = state.searchHistoryEntries.find(p => p.route === route)
19+
getSearchHistoryEntryWithId: (state) => (id) => {
20+
const searchHistoryEntry = state.searchHistoryEntries.find(p => p._id === id)
2921
return searchHistoryEntry
3022
},
3123

3224
getSearchHistoryIdsForMatchingUserPlaylistIds: (state) => (playlistIds) => {
3325
const searchHistoryIds = []
3426
const allSearchHistoryEntries = state.searchHistoryEntries
35-
const searchHistoryEntryLimitedRoutesMap = new Map()
27+
const searchHistoryEntryLimitedIdsMap = new Map()
3628
allSearchHistoryEntries.forEach((searchHistoryEntry) => {
37-
searchHistoryEntryLimitedRoutesMap.set(searchHistoryEntry.route, searchHistoryEntry._id)
29+
searchHistoryEntryLimitedIdsMap.set(searchHistoryEntry._id, searchHistoryEntry._id)
3830
})
3931

4032
playlistIds.forEach((playlistId) => {
41-
const route = `/playlist/${playlistId}?playlistType=user&searchQueryText=`
42-
if (!searchHistoryEntryLimitedRoutesMap.has(route)) {
33+
const id = `/playlist/${playlistId}?playlistType=user&searchQueryText=`
34+
if (!searchHistoryEntryLimitedIdsMap.has(id)) {
4335
return
4436
}
4537

46-
searchHistoryIds.push(searchHistoryEntryLimitedRoutesMap.get(route))
38+
searchHistoryIds.push(searchHistoryEntryLimitedIdsMap.get(id))
4739
})
4840

4941
return searchHistoryIds
@@ -125,7 +117,7 @@ const mutations = {
125117

126118
upsertSearchHistoryEntryToList(state, updatedSearchHistoryEntry) {
127119
state.searchHistoryEntries = state.searchHistoryEntries.filter((p) => {
128-
return p.route !== updatedSearchHistoryEntry.route
120+
return p.name !== updatedSearchHistoryEntry._id
129121
})
130122

131123
state.searchHistoryEntries.unshift(updatedSearchHistoryEntry)

src/renderer/views/Search/Search.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,9 @@ export default defineComponent({
107107
},
108108
methods: {
109109
updateSearchHistoryEntry: function () {
110-
const currentRoute = this.$router.currentRoute.fullPath
111110
const persistentSearchHistoryPayload = {
111+
_id: this.query,
112112
name: this.query,
113-
route: currentRoute,
114-
_id: currentRoute,
115113
lastUpdatedAt: new Date()
116114
}
117115

0 commit comments

Comments
 (0)