Skip to content

Commit

Permalink
Exclude current search route from history suggestions and populate in…
Browse files Browse the repository at this point in the history
…put with matching query
  • Loading branch information
kommunarr committed Dec 19, 2024
1 parent 679496f commit acc5723
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 28 deletions.
40 changes: 21 additions & 19 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,16 @@ function runApp() {

app.on('second-instance', (_, commandLine, __) => {
// Someone tried to run a second instance, we should focus our window
if (mainWindow && typeof commandLine !== 'undefined') {
if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus()

if (typeof commandLine !== 'undefined') {
const url = getLinkUrl(commandLine)
if (url) {
mainWindow.webContents.send(IpcChannels.OPEN_URL, url)
if (mainWindow && mainWindow.webContents) {
if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus()

if (url) mainWindow.webContents.send(IpcChannels.OPEN_URL, url)
} else {
if (url) startupUrl = url
createWindow()
}
}
})
Expand Down Expand Up @@ -829,10 +832,11 @@ function runApp() {
})
}

ipcMain.once(IpcChannels.APP_READY, () => {
ipcMain.on(IpcChannels.APP_READY, () => {
if (startupUrl) {
mainWindow.webContents.send(IpcChannels.OPEN_URL, startupUrl, { isLaunchLink: true })
}
startupUrl = null
})

function relaunch() {
Expand Down Expand Up @@ -1294,11 +1298,7 @@ function runApp() {
return null

case DBActions.PLAYLISTS.DELETE_VIDEO_ID:
await baseHandlers.playlists.deleteVideoIdByPlaylistId({
_id: data._id,
videoId: data.videoId,
playlistItemId: data.playlistItemId,
})
await baseHandlers.playlists.deleteVideoIdByPlaylistId(data._id, data.videoId, data.playlistItemId)
syncOtherWindows(
IpcChannels.SYNC_PLAYLISTS,
event,
Expand Down Expand Up @@ -1340,6 +1340,8 @@ function runApp() {
}
})

// *********** //

// ************** //
// Search History
ipcMain.handle(IpcChannels.DB_SEARCH_HISTORY, async (event, { action, data }) => {
Expand Down Expand Up @@ -1398,8 +1400,6 @@ function runApp() {
}
})

// *********** //

// *********** //
// Profiles
ipcMain.handle(IpcChannels.DB_SUBSCRIPTION_CACHE, async (event, { action, data }) => {
Expand All @@ -1409,7 +1409,7 @@ function runApp() {
return await baseHandlers.subscriptionCache.find()

case DBActions.SUBSCRIPTION_CACHE.UPDATE_VIDEOS_BY_CHANNEL:
await baseHandlers.subscriptionCache.updateVideosByChannelId(data)
await baseHandlers.subscriptionCache.updateVideosByChannelId(data.channelId, data.entries, data.timestamp)
syncOtherWindows(
IpcChannels.SYNC_SUBSCRIPTION_CACHE,
event,
Expand All @@ -1418,7 +1418,7 @@ function runApp() {
return null

case DBActions.SUBSCRIPTION_CACHE.UPDATE_LIVE_STREAMS_BY_CHANNEL:
await baseHandlers.subscriptionCache.updateLiveStreamsByChannelId(data)
await baseHandlers.subscriptionCache.updateLiveStreamsByChannelId(data.channelId, data.entries, data.timestamp)
syncOtherWindows(
IpcChannels.SYNC_SUBSCRIPTION_CACHE,
event,
Expand All @@ -1427,7 +1427,7 @@ function runApp() {
return null

case DBActions.SUBSCRIPTION_CACHE.UPDATE_SHORTS_BY_CHANNEL:
await baseHandlers.subscriptionCache.updateShortsByChannelId(data)
await baseHandlers.subscriptionCache.updateShortsByChannelId(data.channelId, data.entries, data.timestamp)
syncOtherWindows(
IpcChannels.SYNC_SUBSCRIPTION_CACHE,
event,
Expand All @@ -1436,7 +1436,7 @@ function runApp() {
return null

case DBActions.SUBSCRIPTION_CACHE.UPDATE_SHORTS_WITH_CHANNEL_PAGE_SHORTS_BY_CHANNEL:
await baseHandlers.subscriptionCache.updateShortsWithChannelPageShortsByChannelId(data)
await baseHandlers.subscriptionCache.updateShortsWithChannelPageShortsByChannelId(data.channelId, data.entries)
syncOtherWindows(
IpcChannels.SYNC_SUBSCRIPTION_CACHE,
event,
Expand All @@ -1445,7 +1445,7 @@ function runApp() {
return null

case DBActions.SUBSCRIPTION_CACHE.UPDATE_COMMUNITY_POSTS_BY_CHANNEL:
await baseHandlers.subscriptionCache.updateCommunityPostsByChannelId(data)
await baseHandlers.subscriptionCache.updateCommunityPostsByChannelId(data.channelId, data.entries, data.timestamp)
syncOtherWindows(
IpcChannels.SYNC_SUBSCRIPTION_CACHE,
event,
Expand Down Expand Up @@ -1500,6 +1500,7 @@ function runApp() {
app.on('window-all-closed', () => {
// Clean up resources (datastores' compaction + Electron cache and storage data clearing)
cleanUpResources().finally(() => {
mainWindow = null
if (process.platform !== 'darwin') {
app.quit()
}
Expand Down Expand Up @@ -1569,6 +1570,7 @@ function runApp() {
mainWindow.webContents.send(IpcChannels.OPEN_URL, baseUrl(url))
} else {
startupUrl = baseUrl(url)
if (app.isReady()) createWindow()
}
})

Expand Down
10 changes: 5 additions & 5 deletions src/renderer/components/ft-input/ft-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default defineComponent({
this.$emit('input', val)
},

handleClearTextClick: function ({ programmaticallyTriggered = false }) {
handleClearTextClick: function () {
// No action if no input text
if (!this.inputDataPresent) { return }

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

// Focus on input element after text is clear for better UX
if (!programmaticallyTriggered) {
this.$refs.input.focus()
}
this.$refs.input.focus()

this.$emit('clear')
},
Expand Down Expand Up @@ -244,10 +242,12 @@ export default defineComponent({
this.searchState.showOptions = false
if (this.visibleDataList[index].route) {
this.inputData = `ft:${this.visibleDataList[index].route}`
this.$emit('input', this.inputData)
this.inputData = this.$refs.input.value = this.visibleDataList[index].name
} else {
this.inputData = this.visibleDataList[index]
this.$emit('input', this.inputData)
}
this.$emit('input', this.inputData)
this.handleClick()
},

Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/top-nav/top-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default defineComponent({
if (!this.enableSearchSuggestions) {
return
}
return this.lastSuggestionQuery === '' ? this.$store.getters.getLatestUniqueSearchHistoryEntries : this.searchSuggestionsDataList
return this.lastSuggestionQuery === '' ? this.$store.getters.getLatestUniqueSearchHistoryEntries(this.$router.currentRoute.fullPath) : this.searchSuggestionsDataList
},
},
watch: {
Expand Down Expand Up @@ -177,7 +177,6 @@ export default defineComponent({
clearLocalSearchSuggestionsSession()

if (queryText.startsWith('ft:')) {
this.$refs.searchInput.handleClearTextClick({ programmaticallyTriggered: true })
const adjustedQuery = queryText.substring(3)
openInternalPath({
path: adjustedQuery,
Expand Down
33 changes: 31 additions & 2 deletions src/renderer/store/modules/search-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const getters = {
return state.searchHistoryEntries
},

getLatestUniqueSearchHistoryEntries: (state) => {
getLatestUniqueSearchHistoryEntries: (state) => (routeToExclude) => {
const nameSet = new Set()
return state.searchHistoryEntries.filter((entry) => {
if (nameSet.has(entry.name)) {
if (nameSet.has(entry.name) || routeToExclude === entry.route) {
return false
}

Expand All @@ -28,6 +28,26 @@ const getters = {
const searchHistoryEntry = state.searchHistoryEntries.find(p => p.route === route)
return searchHistoryEntry
},

getSearchHistoryIdsForMatchingUserPlaylistIds: (state) => (playlistIds) => {
const searchHistoryIds = []
const allSearchHistoryEntries = state.searchHistoryEntries
const searchHistoryEntryLimitedRoutesMap = new Map()
allSearchHistoryEntries.forEach((searchHistoryEntry) => {
searchHistoryEntryLimitedRoutesMap.set(searchHistoryEntry.route, searchHistoryEntry._id)
})

playlistIds.forEach((playlistId) => {
const route = `/playlist/${playlistId}?playlistType=user&searchQueryText=`
if (!searchHistoryEntryLimitedRoutesMap.has(route)) {
return
}

searchHistoryIds.push(searchHistoryEntryLimitedRoutesMap.get(route))
})

return searchHistoryIds
}
}
const actions = {
async grabSearchHistoryEntries({ commit }) {
Expand Down Expand Up @@ -75,6 +95,15 @@ const actions = {
}
},

async removeUserPlaylistSearchHistoryEntries({ dispatch, getters }, userPlaylistIds) {
const searchHistoryIds = getters.getSearchHistoryIdsForMatchingUserPlaylistIds(userPlaylistIds)
if (searchHistoryIds.length === 0) {
return
}

dispatch('removeSearchHistoryEntries', searchHistoryIds)
},

async removeAllSearchHistoryEntries({ commit }) {
try {
await DBSearchHistoryHandlers.deleteAll()
Expand Down

0 comments on commit acc5723

Please sign in to comment.