Skip to content

Keyword search history #6414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cb18afd
Add search history DB integration
kommunarr Dec 18, 2024
820932e
Implement search history display logic and UI
kommunarr Dec 19, 2024
679496f
Modify search cache removal setting to remove search history as well
kommunarr Dec 19, 2024
acc5723
Exclude current search route from history suggestions and populate in…
kommunarr Dec 19, 2024
953ab80
Modify new labels for clarity
kommunarr Dec 20, 2024
d6f7542
Fix issues detected during review
kommunarr Dec 20, 2024
10e17ef
Implement fixes from code review
kommunarr Dec 20, 2024
a6375c7
Update logic to allowing storing and searching by name rather than by…
kommunarr Dec 20, 2024
09a4b9b
Merge branch 'development' of github.com:FreeTubeApp/FreeTube into fe…
kommunarr Dec 20, 2024
a618e6c
Add back clear statement
kommunarr Dec 22, 2024
6f8c7b1
Merge branch 'development' of github.com:FreeTubeApp/FreeTube into fe…
kommunarr Dec 27, 2024
3570682
Fix clear text button not working or appearing as active when arrowin…
kommunarr Dec 27, 2024
2caa250
Add 'Remove' option
kommunarr Dec 27, 2024
2dc2326
Merge branch 'development' of github.com:FreeTubeApp/FreeTube into fe…
kommunarr Dec 27, 2024
a69cbbf
Merge branch 'development' of github.com:FreeTubeApp/FreeTube into fe…
kommunarr Dec 28, 2024
24de045
Implement search history entries showing up alongside YT search sugge…
kommunarr Dec 28, 2024
08614b0
Improve code commenting
kommunarr Dec 28, 2024
f27e1d5
Implement code review changes
kommunarr Dec 28, 2024
15aec12
Merge branch 'development' of github.com:FreeTubeApp/FreeTube into fe…
kommunarr Dec 29, 2024
ea73ad1
Fix text overflow issue with long search history entries
kommunarr Dec 29, 2024
5c37335
Remove 'name' field and unused DB methods
kommunarr Jan 1, 2025
613fd44
Implement 'Remember Search History' setting and rename 'Remember Hist…
kommunarr Jan 2, 2025
333ecbb
Apply suggestions from code review
kommunarr Jan 2, 2025
c27b89b
Update to not show search history suggestions if 'Remember Search His…
kommunarr Jan 2, 2025
11098f0
Update logic to make 'Enable Search Suggestions' being false still al…
kommunarr Jan 2, 2025
cd8a1d1
Revert hiding old search history entries if rememberSearchHistory is …
kommunarr Jan 2, 2025
fd5b612
Fix searchOptions not closing in edge case
kommunarr Jan 3, 2025
ebac58b
Update src/renderer/views/Search/Search.js
kommunarr Jan 5, 2025
c8b08fe
Add bolding to selected/focused 'Remove' button
kommunarr Jan 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ const IpcChannels = {
DB_HISTORY: 'db-history',
DB_PROFILES: 'db-profiles',
DB_PLAYLISTS: 'db-playlists',
DB_SEARCH_HISTORY: 'db-search-history',
DB_SUBSCRIPTION_CACHE: 'db-subscription-cache',

SYNC_SETTINGS: 'sync-settings',
SYNC_HISTORY: 'sync-history',
SYNC_SEARCH_HISTORY: 'sync-search-history',
SYNC_PROFILES: 'sync-profiles',
SYNC_PLAYLISTS: 'sync-playlists',
SYNC_SUBSCRIPTION_CACHE: 'sync-subscription-cache',
Expand Down Expand Up @@ -191,6 +193,12 @@ const PLAYLIST_HEIGHT_FORCE_LIST_THRESHOLD = 500
// YouTube search character limit is 100 characters
const SEARCH_CHAR_LIMIT = 100

// max # of results we show for search suggestions
const SEARCH_RESULTS_DISPLAY_LIMIT = 14

// max # of search history results we show when mixed with YT search suggestions
const MIXED_SEARCH_HISTORY_ENTRIES_DISPLAY_LIMIT = 4

// Displayed on the about page and used in the main.js file to only allow bitcoin URLs with this wallet address to be opened
const ABOUT_BITCOIN_ADDRESS = '1Lih7Ho5gnxb1CwPD4o59ss78pwo2T91eS'

Expand All @@ -203,5 +211,7 @@ export {
MOBILE_WIDTH_THRESHOLD,
PLAYLIST_HEIGHT_FORCE_LIST_THRESHOLD,
SEARCH_CHAR_LIMIT,
SEARCH_RESULTS_DISPLAY_LIMIT,
MIXED_SEARCH_HISTORY_ENTRIES_DISPLAY_LIMIT,
ABOUT_BITCOIN_ADDRESS,
}
20 changes: 20 additions & 0 deletions src/datastores/handlers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,24 @@ class Playlists {
}
}

class SearchHistory {
static find() {
return db.searchHistory.findAsync({}).sort({ lastUpdatedAt: -1 })
}

static upsert(searchHistoryEntry) {
return db.searchHistory.updateAsync({ _id: searchHistoryEntry._id }, searchHistoryEntry, { upsert: true })
}

static delete(_id) {
return db.searchHistory.removeAsync({ _id: _id })
}

static deleteAll() {
return db.searchHistory.removeAsync({}, { multi: true })
}
}

class SubscriptionCache {
static find() {
return db.subscriptionCache.findAsync({})
Expand Down Expand Up @@ -311,6 +329,7 @@ function compactAllDatastores() {
db.history.compactDatafileAsync(),
db.profiles.compactDatafileAsync(),
db.playlists.compactDatafileAsync(),
db.searchHistory.compactDatafileAsync(),
db.subscriptionCache.compactDatafileAsync(),
])
}
Expand All @@ -320,6 +339,7 @@ export {
History as history,
Profiles as profiles,
Playlists as playlists,
SearchHistory as searchHistory,
SubscriptionCache as subscriptionCache,

compactAllDatastores,
Expand Down
31 changes: 31 additions & 0 deletions src/datastores/handlers/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,36 @@ class Playlists {
}
}

class SearchHistory {
static find() {
return ipcRenderer.invoke(
IpcChannels.DB_SEARCH_HISTORY,
{ action: DBActions.GENERAL.FIND }
)
}

static upsert(searchHistoryEntry) {
return ipcRenderer.invoke(
IpcChannels.DB_SEARCH_HISTORY,
{ action: DBActions.GENERAL.UPSERT, data: searchHistoryEntry }
)
}

static delete(_id) {
return ipcRenderer.invoke(
IpcChannels.DB_SEARCH_HISTORY,
{ action: DBActions.GENERAL.DELETE, data: _id }
)
}

static deleteAll() {
return ipcRenderer.invoke(
IpcChannels.DB_SEARCH_HISTORY,
{ action: DBActions.GENERAL.DELETE_ALL }
)
}
}

class SubscriptionCache {
static find() {
return ipcRenderer.invoke(
Expand Down Expand Up @@ -296,5 +326,6 @@ export {
History as history,
Profiles as profiles,
Playlists as playlists,
SearchHistory as searchHistory,
SubscriptionCache as subscriptionCache,
}
1 change: 1 addition & 0 deletions src/datastores/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export {
history as DBHistoryHandlers,
profiles as DBProfileHandlers,
playlists as DBPlaylistHandlers,
searchHistory as DBSearchHistoryHandlers,
subscriptionCache as DBSubscriptionCacheHandlers,
} from 'DB_HANDLERS_ELECTRON_RENDERER_OR_WEB'
2 changes: 1 addition & 1 deletion src/datastores/handlers/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class Settings {
export { Settings as settings }

// These classes don't require any changes from the base classes, so can be exported as-is.
export { history, profiles, playlists, subscriptionCache } from './base'
export { history, profiles, playlists, searchHistory, subscriptionCache } from './base'
1 change: 1 addition & 0 deletions src/datastores/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export const settings = new Datastore({ filename: dbPath('settings'), autoload:
export const profiles = new Datastore({ filename: dbPath('profiles'), autoload: true })
export const playlists = new Datastore({ filename: dbPath('playlists'), autoload: true })
export const history = new Datastore({ filename: dbPath('history'), autoload: true })
export const searchHistory = new Datastore({ filename: dbPath('search-history'), autoload: true })
export const subscriptionCache = new Datastore({ filename: dbPath('subscription-cache'), autoload: true })
45 changes: 45 additions & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,51 @@ function runApp() {

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

// ************** //
// Search History
ipcMain.handle(IpcChannels.DB_SEARCH_HISTORY, async (event, { action, data }) => {
try {
switch (action) {
case DBActions.GENERAL.FIND:
return await baseHandlers.searchHistory.find()

case DBActions.GENERAL.UPSERT:
await baseHandlers.searchHistory.upsert(data)
syncOtherWindows(
IpcChannels.SYNC_SEARCH_HISTORY,
event,
{ event: SyncEvents.GENERAL.UPSERT, data }
)
return null

case DBActions.GENERAL.DELETE:
await baseHandlers.searchHistory.delete(data)
syncOtherWindows(
IpcChannels.SYNC_SEARCH_HISTORY,
event,
{ event: SyncEvents.GENERAL.DELETE, data }
)
return null

case DBActions.GENERAL.DELETE_ALL:
await baseHandlers.searchHistory.deleteAll()
syncOtherWindows(
IpcChannels.SYNC_SEARCH_HISTORY,
event,
{ event: SyncEvents.GENERAL.DELETE_ALL }
)
return null

default:
// eslint-disable-next-line no-throw-literal
throw 'invalid search history db action'
}
} catch (err) {
if (typeof err === 'string') throw err
else throw err.toString()
}
})

// *********** //
// Profiles
ipcMain.handle(IpcChannels.DB_SUBSCRIPTION_CACHE, async (event, { action, data }) => {
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export default defineComponent({
this.grabHistory()
this.grabAllPlaylists()
this.grabAllSubscriptions()
this.grabSearchHistoryEntries()

if (process.env.IS_ELECTRON) {
ipcRenderer = require('electron').ipcRenderer
Expand Down Expand Up @@ -579,6 +580,7 @@ export default defineComponent({
'grabHistory',
'grabAllPlaylists',
'grabAllSubscriptions',
'grabSearchHistoryEntries',
'getYoutubeUrlInfo',
'getExternalPlayerCmdArgumentsData',
'fetchInvidiousInstances',
Expand Down
33 changes: 28 additions & 5 deletions src/renderer/components/ft-input/ft-input.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ body[dir='rtl'] .ft-input-component.search.showClearTextButton:focus-within .inp
padding-inline-start: 46px;
}

.ft-input-component:focus-within .clearInputTextButton {
.ft-input-component:focus-within .clearInputTextButton,
.ft-input-component.showOptions .clearInputTextButton {
opacity: 0.5;
}

.clearTextButtonVisible .clearInputTextButton.visible,
.ft-input-component:focus-within .clearInputTextButton.visible {

.ft-input-component.inputDataPresent .clearInputTextButton.visible,
.clearTextButtonVisible:not(.showOptions) .clearInputTextButton.visible,
.ft-input-component:focus-within:not(.showOptions) .clearInputTextButton.visible {
cursor: pointer;
opacity: 1;
}
Expand Down Expand Up @@ -200,10 +203,30 @@ body[dir='rtl'] .ft-input-component.search.showClearTextButton:focus-within .inp
}

.list li {
display: block;
display: flex;
justify-content: space-between;
padding-block: 0;
padding-inline: 15px;
line-height: 2rem;
padding-inline: 15px;
}

.searchResultIcon {
opacity: 0.6;
padding-inline-end: 10px;
inline-size: 16px;
block-size: 16px;
}

.removeButton {
text-decoration: none;
float: var(--float-right-ltr-rtl-value);
font-size: 13px;
}

.removeButton:hover,
.removeButtonSelected {
text-decoration: underline;
font-weight: bold;
}

.hover {
Expand Down
Loading
Loading