Add search history preference (#193)
This commit is contained in:
1 parent
91be37fd8a
commit
4c32243e6e
13 files changed
+78
-19
No files matched your search
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- An option to disable search history
|
||||
|
||||
## [0.15.0] - 2023-11-05
|
||||
|
||||
### Added
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
<ApplicationInfo id="ApplicationInfo" />
|
||||
<Preferences id="Preferences" />
|
||||
<Bookmarks id="Bookmarks" />
|
||||
<SearchHistory id="SearchHistory" />
|
||||
<Invidious id="Invidious" />
|
||||
<PlayletWebServer id="WebServer" port="8888" />
|
||||
</AppController>
|
||||
|
||||
@@ -53,6 +53,8 @@
|
||||
<ApplicationInfo id="ApplicationInfo" />
|
||||
<Preferences id="Preferences" />
|
||||
<Bookmarks id="Bookmarks" />
|
||||
<SearchHistory id="SearchHistory"
|
||||
preferences="bind:../Preferences" />
|
||||
|
||||
<Invidious id="Invidious"
|
||||
webServer="bind:../WebServer"
|
||||
|
||||
@@ -17,6 +17,9 @@ function InitializeBindings()
|
||||
"notifications": "../Notifications",
|
||||
"preferences": "../Preferences"
|
||||
},
|
||||
"SearchHistory": {
|
||||
"preferences": "../Preferences"
|
||||
},
|
||||
"Invidious": {
|
||||
"webServer": "../WebServer",
|
||||
"applicationInfo": "../ApplicationInfo",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import "pkg:/components/Navigation/Navigation.bs"
|
||||
import "pkg:/components/Screens/SearchScreen/SearchSuggestionsTask.bs"
|
||||
import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
|
||||
import "pkg:/source/asyncTask/asyncTask.bs"
|
||||
import "pkg:/source/services/SearchHistory.bs"
|
||||
import "pkg:/source/utils/ErrorUtils.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
import "pkg:/source/utils/LoadingScreen.bs"
|
||||
@@ -99,7 +99,8 @@ function OnTextChange() as void
|
||||
|
||||
m.searchSuggestionsTask = StartAsyncTask(SearchSuggestionsTask, {
|
||||
q: m.keyboard.text,
|
||||
invidious: m.invidious
|
||||
invidious: m.invidious,
|
||||
preferences: m.preferences
|
||||
}, OnSearchSuggestionsTaskResults)
|
||||
end function
|
||||
|
||||
@@ -155,7 +156,7 @@ end function
|
||||
function OnSearchButtonSelected()
|
||||
selected = m.suggestions.buttonSelected
|
||||
text = m.suggestions.buttons[selected]
|
||||
SearchHistory.Save(text)
|
||||
SearchHistoryUtils.Save(m.preferences, text)
|
||||
Search(text)
|
||||
end function
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<field id="navBar" type="node" bind="/NavBar" />
|
||||
<field id="invidious" type="node" bind="/Invidious" />
|
||||
<field id="appController" type="node" bind="/AppController" />
|
||||
<field id="preferences" type="node" bind="/Preferences" />
|
||||
<field id="filters" type="assocarray" />
|
||||
</interface>
|
||||
<children>
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import "pkg:/components/Services/Invidious/InvidiousService.bs"
|
||||
import "pkg:/source/services/SearchHistory.bs"
|
||||
import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
|
||||
|
||||
@asynctask
|
||||
function SearchSuggestionsTask(input as object) as object
|
||||
q = input.q
|
||||
invidiousNode = input.invidious
|
||||
preferencesNode = input.preferences
|
||||
|
||||
service = new Invidious.InvidiousService(invidiousNode)
|
||||
|
||||
@@ -18,7 +19,7 @@ function SearchSuggestionsTask(input as object) as object
|
||||
return invalid
|
||||
end if
|
||||
|
||||
history = SearchHistory.GetSaved(q)
|
||||
history = SearchHistoryUtils.GetSaved(preferencesNode, q)
|
||||
|
||||
if searchSuggestsions <> invalid
|
||||
history = MergeSearchSuggestions(history, searchSuggestsions.suggestions)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import "pkg:/components/Dialog/DialogUtils.bs"
|
||||
import "pkg:/source/services/SearchHistory.bs"
|
||||
import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
|
||||
import "pkg:/source/utils/FocusManagement.bs"
|
||||
|
||||
function Init()
|
||||
@@ -21,6 +21,6 @@ function BindPreference(preferences as object, key as string)
|
||||
end function
|
||||
|
||||
function OnButtonSelected()
|
||||
SearchHistory.Clear()
|
||||
SearchHistoryUtils.Clear()
|
||||
DialogUtils.ShowDialog("Search history cleared.", "Success")
|
||||
end function
|
||||
@@ -0,0 +1,18 @@
|
||||
import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
function Init()
|
||||
end function
|
||||
|
||||
function OnNodeReady()
|
||||
OnSearchHistoryPreference()
|
||||
m.preferences.observeFieldScoped("search_history.enabled", FuncName(OnSearchHistoryPreference))
|
||||
end function
|
||||
|
||||
function OnSearchHistoryPreference() as void
|
||||
seachHistoryEnabled = m.preferences["search_history.enabled"]
|
||||
if seachHistoryEnabled
|
||||
return
|
||||
end if
|
||||
SearchHistoryUtils.Clear()
|
||||
end function
|
||||
@@ -0,0 +1,5 @@
|
||||
<component name="SearchHistory" extends="Node" includes="AutoBind">
|
||||
<interface>
|
||||
<field id="preferences" type="node" />
|
||||
</interface>
|
||||
</component>
|
||||
+16
-7
@@ -2,9 +2,14 @@ import "pkg:/source/utils/ArrayUtils.bs"
|
||||
import "pkg:/source/utils/RegistryUtils.bs"
|
||||
import "pkg:/source/utils/StringUtils.bs"
|
||||
|
||||
namespace SearchHistory
|
||||
function Save(q as string, maxItems = 10 as integer)
|
||||
history = GetAllSaved()
|
||||
namespace SearchHistoryUtils
|
||||
function Save(preferencesNode as object, q as string, maxItems = 10 as integer) as void
|
||||
seachHistoryEnabled = preferencesNode["search_history.enabled"]
|
||||
if not seachHistoryEnabled
|
||||
return
|
||||
end if
|
||||
|
||||
history = GetAllSaved(preferencesNode)
|
||||
index = ArrayUtils.IndexOfString(history, q)
|
||||
if index <> -1
|
||||
history.Delete(index)
|
||||
@@ -21,8 +26,8 @@ namespace SearchHistory
|
||||
RegistryUtils.Write(RegistryUtils.SEARCH_HISTORY, history)
|
||||
end function
|
||||
|
||||
function GetSaved(q as string) as object
|
||||
history = GetAllSaved()
|
||||
function GetSaved(preferencesNode as object, q as string) as object
|
||||
history = GetAllSaved(preferencesNode)
|
||||
if history.count() = 0
|
||||
return []
|
||||
end if
|
||||
@@ -39,7 +44,12 @@ namespace SearchHistory
|
||||
return result
|
||||
end function
|
||||
|
||||
function GetAllSaved() as object
|
||||
function GetAllSaved(preferencesNode as object) as object
|
||||
seachHistoryEnabled = preferencesNode["search_history.enabled"]
|
||||
if not seachHistoryEnabled
|
||||
return []
|
||||
end if
|
||||
|
||||
history = RegistryUtils.Read(RegistryUtils.SEARCH_HISTORY)
|
||||
if history = invalid
|
||||
return []
|
||||
@@ -47,7 +57,6 @@ namespace SearchHistory
|
||||
return ParseJson(history)
|
||||
end function
|
||||
|
||||
|
||||
function Clear()
|
||||
RegistryUtils.Delete(RegistryUtils.SEARCH_HISTORY)
|
||||
end function
|
||||
@@ -1,4 +1,4 @@
|
||||
import "pkg:/source/services/SearchHistory.bs"
|
||||
import "pkg:/components/Services/SearchHistory/SearchHistoryUtils.bs"
|
||||
|
||||
namespace Http
|
||||
|
||||
@@ -9,13 +9,18 @@ namespace Http
|
||||
|
||||
m.Get("/api/search-history", function(context as object) as boolean
|
||||
response = context.response
|
||||
response.Json(SearchHistory.GetAllSaved())
|
||||
task = context.server.task
|
||||
preferences = task.preferences
|
||||
|
||||
response.Json(SearchHistoryUtils.GetAllSaved(preferences))
|
||||
return true
|
||||
end function)
|
||||
|
||||
m.Put("/api/search-history", function(context as object) as boolean
|
||||
request = context.request
|
||||
response = context.response
|
||||
task = context.server.task
|
||||
preferences = task.preferences
|
||||
|
||||
payload = request.Json()
|
||||
if payload = invalid
|
||||
@@ -29,15 +34,15 @@ namespace Http
|
||||
return true
|
||||
end if
|
||||
|
||||
SearchHistory.Save(query)
|
||||
response.Json(SearchHistory.GetAllSaved())
|
||||
SearchHistoryUtils.Save(preferences, query)
|
||||
response.Json(SearchHistoryUtils.GetAllSaved(preferences))
|
||||
return true
|
||||
end function)
|
||||
|
||||
m.Delete("/api/search-history", function(context as object) as boolean
|
||||
response = context.response
|
||||
|
||||
SearchHistory.Clear()
|
||||
SearchHistoryUtils.Clear()
|
||||
response.Default(204, "OK")
|
||||
return true
|
||||
end function)
|
||||
|
||||
@@ -98,6 +98,13 @@
|
||||
key: "search_history",
|
||||
description: "Search history preferences",
|
||||
children: [
|
||||
{
|
||||
displayText: "Enable search history",
|
||||
key: "search_history.enabled",
|
||||
description: "Enable search history",
|
||||
type: "boolean",
|
||||
defaultValue: true,
|
||||
},
|
||||
{
|
||||
displayText: "Clear Search History",
|
||||
key: "search_history.clear_search_history",
|
||||
|
||||
Reference in new issue
Block a user