Skip to content

Commit acc5723

Browse files
committed
Exclude current search route from history suggestions and populate input with matching query
1 parent 679496f commit acc5723

File tree

4 files changed

+58
-28
lines changed

4 files changed

+58
-28
lines changed

src/main/index.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,16 @@ function runApp() {
254254

255255
app.on('second-instance', (_, commandLine, __) => {
256256
// Someone tried to run a second instance, we should focus our window
257-
if (mainWindow && typeof commandLine !== 'undefined') {
258-
if (mainWindow.isMinimized()) mainWindow.restore()
259-
mainWindow.focus()
260-
257+
if (typeof commandLine !== 'undefined') {
261258
const url = getLinkUrl(commandLine)
262-
if (url) {
263-
mainWindow.webContents.send(IpcChannels.OPEN_URL, url)
259+
if (mainWindow && mainWindow.webContents) {
260+
if (mainWindow.isMinimized()) mainWindow.restore()
261+
mainWindow.focus()
262+
263+
if (url) mainWindow.webContents.send(IpcChannels.OPEN_URL, url)
264+
} else {
265+
if (url) startupUrl = url
266+
createWindow()
264267
}
265268
}
266269
})
@@ -829,10 +832,11 @@ function runApp() {
829832
})
830833
}
831834

832-
ipcMain.once(IpcChannels.APP_READY, () => {
835+
ipcMain.on(IpcChannels.APP_READY, () => {
833836
if (startupUrl) {
834837
mainWindow.webContents.send(IpcChannels.OPEN_URL, startupUrl, { isLaunchLink: true })
835838
}
839+
startupUrl = null
836840
})
837841

838842
function relaunch() {
@@ -1294,11 +1298,7 @@ function runApp() {
12941298
return null
12951299

12961300
case DBActions.PLAYLISTS.DELETE_VIDEO_ID:
1297-
await baseHandlers.playlists.deleteVideoIdByPlaylistId({
1298-
_id: data._id,
1299-
videoId: data.videoId,
1300-
playlistItemId: data.playlistItemId,
1301-
})
1301+
await baseHandlers.playlists.deleteVideoIdByPlaylistId(data._id, data.videoId, data.playlistItemId)
13021302
syncOtherWindows(
13031303
IpcChannels.SYNC_PLAYLISTS,
13041304
event,
@@ -1340,6 +1340,8 @@ function runApp() {
13401340
}
13411341
})
13421342

1343+
// *********** //
1344+
13431345
// ************** //
13441346
// Search History
13451347
ipcMain.handle(IpcChannels.DB_SEARCH_HISTORY, async (event, { action, data }) => {
@@ -1398,8 +1400,6 @@ function runApp() {
13981400
}
13991401
})
14001402

1401-
// *********** //
1402-
14031403
// *********** //
14041404
// Profiles
14051405
ipcMain.handle(IpcChannels.DB_SUBSCRIPTION_CACHE, async (event, { action, data }) => {
@@ -1409,7 +1409,7 @@ function runApp() {
14091409
return await baseHandlers.subscriptionCache.find()
14101410

14111411
case DBActions.SUBSCRIPTION_CACHE.UPDATE_VIDEOS_BY_CHANNEL:
1412-
await baseHandlers.subscriptionCache.updateVideosByChannelId(data)
1412+
await baseHandlers.subscriptionCache.updateVideosByChannelId(data.channelId, data.entries, data.timestamp)
14131413
syncOtherWindows(
14141414
IpcChannels.SYNC_SUBSCRIPTION_CACHE,
14151415
event,
@@ -1418,7 +1418,7 @@ function runApp() {
14181418
return null
14191419

14201420
case DBActions.SUBSCRIPTION_CACHE.UPDATE_LIVE_STREAMS_BY_CHANNEL:
1421-
await baseHandlers.subscriptionCache.updateLiveStreamsByChannelId(data)
1421+
await baseHandlers.subscriptionCache.updateLiveStreamsByChannelId(data.channelId, data.entries, data.timestamp)
14221422
syncOtherWindows(
14231423
IpcChannels.SYNC_SUBSCRIPTION_CACHE,
14241424
event,
@@ -1427,7 +1427,7 @@ function runApp() {
14271427
return null
14281428

14291429
case DBActions.SUBSCRIPTION_CACHE.UPDATE_SHORTS_BY_CHANNEL:
1430-
await baseHandlers.subscriptionCache.updateShortsByChannelId(data)
1430+
await baseHandlers.subscriptionCache.updateShortsByChannelId(data.channelId, data.entries, data.timestamp)
14311431
syncOtherWindows(
14321432
IpcChannels.SYNC_SUBSCRIPTION_CACHE,
14331433
event,
@@ -1436,7 +1436,7 @@ function runApp() {
14361436
return null
14371437

14381438
case DBActions.SUBSCRIPTION_CACHE.UPDATE_SHORTS_WITH_CHANNEL_PAGE_SHORTS_BY_CHANNEL:
1439-
await baseHandlers.subscriptionCache.updateShortsWithChannelPageShortsByChannelId(data)
1439+
await baseHandlers.subscriptionCache.updateShortsWithChannelPageShortsByChannelId(data.channelId, data.entries)
14401440
syncOtherWindows(
14411441
IpcChannels.SYNC_SUBSCRIPTION_CACHE,
14421442
event,
@@ -1445,7 +1445,7 @@ function runApp() {
14451445
return null
14461446

14471447
case DBActions.SUBSCRIPTION_CACHE.UPDATE_COMMUNITY_POSTS_BY_CHANNEL:
1448-
await baseHandlers.subscriptionCache.updateCommunityPostsByChannelId(data)
1448+
await baseHandlers.subscriptionCache.updateCommunityPostsByChannelId(data.channelId, data.entries, data.timestamp)
14491449
syncOtherWindows(
14501450
IpcChannels.SYNC_SUBSCRIPTION_CACHE,
14511451
event,
@@ -1500,6 +1500,7 @@ function runApp() {
15001500
app.on('window-all-closed', () => {
15011501
// Clean up resources (datastores' compaction + Electron cache and storage data clearing)
15021502
cleanUpResources().finally(() => {
1503+
mainWindow = null
15031504
if (process.platform !== 'darwin') {
15041505
app.quit()
15051506
}
@@ -1569,6 +1570,7 @@ function runApp() {
15691570
mainWindow.webContents.send(IpcChannels.OPEN_URL, baseUrl(url))
15701571
} else {
15711572
startupUrl = baseUrl(url)
1573+
if (app.isReady()) createWindow()
15721574
}
15731575
})
15741576

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export default defineComponent({
172172
this.$emit('input', val)
173173
},
174174

175-
handleClearTextClick: function ({ programmaticallyTriggered = false }) {
175+
handleClearTextClick: function () {
176176
// No action if no input text
177177
if (!this.inputDataPresent) { return }
178178

@@ -183,9 +183,7 @@ export default defineComponent({
183183
this.$refs.input.value = ''
184184

185185
// Focus on input element after text is clear for better UX
186-
if (!programmaticallyTriggered) {
187-
this.$refs.input.focus()
188-
}
186+
this.$refs.input.focus()
189187

190188
this.$emit('clear')
191189
},
@@ -244,10 +242,12 @@ export default defineComponent({
244242
this.searchState.showOptions = false
245243
if (this.visibleDataList[index].route) {
246244
this.inputData = `ft:${this.visibleDataList[index].route}`
245+
this.$emit('input', this.inputData)
246+
this.inputData = this.$refs.input.value = this.visibleDataList[index].name
247247
} else {
248248
this.inputData = this.visibleDataList[index]
249+
this.$emit('input', this.inputData)
249250
}
250-
this.$emit('input', this.inputData)
251251
this.handleClick()
252252
},
253253

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ 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.getLatestUniqueSearchHistoryEntries(this.$router.currentRoute.fullPath) : this.searchSuggestionsDataList
131131
},
132132
},
133133
watch: {
@@ -177,7 +177,6 @@ export default defineComponent({
177177
clearLocalSearchSuggestionsSession()
178178

179179
if (queryText.startsWith('ft:')) {
180-
this.$refs.searchInput.handleClearTextClick({ programmaticallyTriggered: true })
181180
const adjustedQuery = queryText.substring(3)
182181
openInternalPath({
183182
path: adjustedQuery,

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

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

15-
getLatestUniqueSearchHistoryEntries: (state) => {
15+
getLatestUniqueSearchHistoryEntries: (state) => (routeToExclude) => {
1616
const nameSet = new Set()
1717
return state.searchHistoryEntries.filter((entry) => {
18-
if (nameSet.has(entry.name)) {
18+
if (nameSet.has(entry.name) || routeToExclude === entry.route) {
1919
return false
2020
}
2121

@@ -28,6 +28,26 @@ const getters = {
2828
const searchHistoryEntry = state.searchHistoryEntries.find(p => p.route === route)
2929
return searchHistoryEntry
3030
},
31+
32+
getSearchHistoryIdsForMatchingUserPlaylistIds: (state) => (playlistIds) => {
33+
const searchHistoryIds = []
34+
const allSearchHistoryEntries = state.searchHistoryEntries
35+
const searchHistoryEntryLimitedRoutesMap = new Map()
36+
allSearchHistoryEntries.forEach((searchHistoryEntry) => {
37+
searchHistoryEntryLimitedRoutesMap.set(searchHistoryEntry.route, searchHistoryEntry._id)
38+
})
39+
40+
playlistIds.forEach((playlistId) => {
41+
const route = `/playlist/${playlistId}?playlistType=user&searchQueryText=`
42+
if (!searchHistoryEntryLimitedRoutesMap.has(route)) {
43+
return
44+
}
45+
46+
searchHistoryIds.push(searchHistoryEntryLimitedRoutesMap.get(route))
47+
})
48+
49+
return searchHistoryIds
50+
}
3151
}
3252
const actions = {
3353
async grabSearchHistoryEntries({ commit }) {
@@ -75,6 +95,15 @@ const actions = {
7595
}
7696
},
7797

98+
async removeUserPlaylistSearchHistoryEntries({ dispatch, getters }, userPlaylistIds) {
99+
const searchHistoryIds = getters.getSearchHistoryIdsForMatchingUserPlaylistIds(userPlaylistIds)
100+
if (searchHistoryIds.length === 0) {
101+
return
102+
}
103+
104+
dispatch('removeSearchHistoryEntries', searchHistoryIds)
105+
},
106+
78107
async removeAllSearchHistoryEntries({ commit }) {
79108
try {
80109
await DBSearchHistoryHandlers.deleteAll()

0 commit comments

Comments
 (0)