aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-04-27 22:33:22 -0500
committerJP Dillingham <jpdillingham@gmail.com>2022-04-27 22:33:22 -0500
commit463c96b6f22d78543f25376edd2d7716af1b44a4 (patch)
tree554a3196bb6ee2e65f8d426df1074533b9e8286f /src
parent80833506bbfc9f85c6d41a06afe53337b3a6011e (diff)
downloadslskd-463c96b6f22d78543f25376edd2d7716af1b44a4.tar.gz
load searches from hub
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Search/API/Hubs/SearchHub.cs10
-rw-r--r--src/web/src/components/Search/List/SearchList.js10
2 files changed, 18 insertions, 2 deletions
diff --git a/src/slskd/Search/API/Hubs/SearchHub.cs b/src/slskd/Search/API/Hubs/SearchHub.cs
index 4417f8c9..881cd7c2 100644
--- a/src/slskd/Search/API/Hubs/SearchHub.cs
+++ b/src/slskd/Search/API/Hubs/SearchHub.cs
@@ -26,6 +26,7 @@ namespace slskd.Search.API
public static class SearchHubMethods
{
+ public static readonly string Load = "LOAD";
public static readonly string Create = "CREATE";
public static readonly string Response = "RESPONSE";
public static readonly string Update = "UPDATE";
@@ -78,14 +79,23 @@ namespace slskd.Search.API
public class SearchHub : Hub
{
public SearchHub(
+ ISearchService searchService,
IStateMonitor<State> stateMonitor,
IOptionsMonitor<Options> optionsMonitor)
{
+ Searches = searchService;
StateMonitor = stateMonitor;
OptionsMonitor = optionsMonitor;
}
+ private ISearchService Searches { get; }
private IStateMonitor<State> StateMonitor { get; }
private IOptionsMonitor<Options> OptionsMonitor { get; }
+
+ public override async Task OnConnectedAsync()
+ {
+ var searches = await Searches.ListAsync();
+ await Clients.Caller.SendAsync(SearchHubMethods.Load, searches);
+ }
}
} \ No newline at end of file
diff --git a/src/web/src/components/Search/List/SearchList.js b/src/web/src/components/Search/List/SearchList.js
index 6450672a..a774fb05 100644
--- a/src/web/src/components/Search/List/SearchList.js
+++ b/src/web/src/components/Search/List/SearchList.js
@@ -22,10 +22,16 @@ const SearchList = () => {
const inputRef = useRef();
useEffect(() => {
- get();
-
const searchHub = createSearchLogHubConnection();
+ searchHub.on('load', searches => {
+ setConnected(true);
+ setSearches(searches.reduce((acc, search) => {
+ acc[search.id] = search;
+ return acc;
+ }, {}));
+ })
+
searchHub.on('update', search => {
setConnected(true);
setSearches(old => ({ ...old, [search.id]: search }))