From 463c96b6f22d78543f25376edd2d7716af1b44a4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 27 Apr 2022 22:33:22 -0500 Subject: load searches from hub --- src/slskd/Search/API/Hubs/SearchHub.cs | 10 ++++++++++ src/web/src/components/Search/List/SearchList.js | 10 ++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src') 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 stateMonitor, IOptionsMonitor optionsMonitor) { + Searches = searchService; StateMonitor = stateMonitor; OptionsMonitor = optionsMonitor; } + private ISearchService Searches { get; } private IStateMonitor StateMonitor { get; } private IOptionsMonitor 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 })) -- cgit v1.2.3