From 85b2aa88aa102a98529e9d9d4ee3dc30aaef468f Mon Sep 17 00:00:00 2001 From: Nicolas Lorusso Date: Wed, 20 Nov 2024 11:14:17 -0300 Subject: [PATCH] implement place search event in the navmap bus --- Explorer/Assets/DCL/Navmap/INavmapBus.cs | 2 ++ Explorer/Assets/DCL/Navmap/NavmapCommandBus.cs | 9 +++++++-- .../DCL/Navmap/SearchForPlaceAndShowResultsCommand.cs | 8 +++++++- .../Assets/DCL/PluginSystem/Global/ExplorePanelPlugin.cs | 5 +++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Explorer/Assets/DCL/Navmap/INavmapBus.cs b/Explorer/Assets/DCL/Navmap/INavmapBus.cs index f442787c6e..e579fffdd8 100644 --- a/Explorer/Assets/DCL/Navmap/INavmapBus.cs +++ b/Explorer/Assets/DCL/Navmap/INavmapBus.cs @@ -2,6 +2,7 @@ using DCL.EventsApi; using DCL.PlacesAPIService; using System; +using System.Collections.Generic; using System.Threading; namespace DCL.Navmap @@ -10,6 +11,7 @@ public interface INavmapBus { event Action OnJumpIn; event Action? OnDestinationSelected; + event Action>? OnPlaceSearched; event Action? OnFilterByCategory; UniTask SelectPlaceAsync(PlacesData.PlaceInfo place, CancellationToken ct); diff --git a/Explorer/Assets/DCL/Navmap/NavmapCommandBus.cs b/Explorer/Assets/DCL/Navmap/NavmapCommandBus.cs index 962640a7dd..8656f72178 100644 --- a/Explorer/Assets/DCL/Navmap/NavmapCommandBus.cs +++ b/Explorer/Assets/DCL/Navmap/NavmapCommandBus.cs @@ -9,7 +9,8 @@ namespace DCL.Navmap { public class NavmapCommandBus : INavmapBus { - public delegate INavmapCommand SearchPlaceFactory(string search, NavmapSearchPlaceFilter filter, NavmapSearchPlaceSorting sorting); + public delegate INavmapCommand SearchPlaceFactory(string search, NavmapSearchPlaceFilter filter, NavmapSearchPlaceSorting sorting, + Action> callback); public delegate INavmapCommand ShowPlaceInfoFactory(PlacesData.PlaceInfo placeInfo); public delegate INavmapCommand ShowEventInfoFactory(EventDTO @event, PlacesData.PlaceInfo? place = null); @@ -20,6 +21,7 @@ public class NavmapCommandBus : INavmapBus public event Action? OnJumpIn; public event Action? OnDestinationSelected; + public event Action>? OnPlaceSearched; public event Action? OnFilterByCategory; public NavmapCommandBus(SearchPlaceFactory searchPlaceFactory, @@ -52,7 +54,7 @@ public async UniTask SelectEventAsync(EventDTO @event, CancellationToken ct, Pla public async UniTask SearchForPlaceAsync(string place, NavmapSearchPlaceFilter filter, NavmapSearchPlaceSorting sorting, CancellationToken ct) { - INavmapCommand command = searchPlaceFactory.Invoke(place, filter, sorting); + INavmapCommand command = searchPlaceFactory.Invoke(place, filter, sorting, OnSearchPlacePerformed); await command.ExecuteAsync(ct); @@ -86,5 +88,8 @@ public void JumpIn(PlacesData.PlaceInfo place) => public void FilterByCategory(string? category) => OnFilterByCategory?.Invoke(category); + + private void OnSearchPlacePerformed(IReadOnlyList places) => + OnPlaceSearched?.Invoke(places); } } diff --git a/Explorer/Assets/DCL/Navmap/SearchForPlaceAndShowResultsCommand.cs b/Explorer/Assets/DCL/Navmap/SearchForPlaceAndShowResultsCommand.cs index b5823aafe9..dcb605ca8c 100644 --- a/Explorer/Assets/DCL/Navmap/SearchForPlaceAndShowResultsCommand.cs +++ b/Explorer/Assets/DCL/Navmap/SearchForPlaceAndShowResultsCommand.cs @@ -19,6 +19,7 @@ public class SearchForPlaceAndShowResultsCommand : INavmapCommand private readonly string searchText; private readonly NavmapSearchPlaceFilter filter; private readonly NavmapSearchPlaceSorting sorting; + private readonly Action> callback; private readonly int pageNumber; private readonly int pageSize; private List? places; @@ -33,6 +34,7 @@ public SearchForPlaceAndShowResultsCommand( string searchText, NavmapSearchPlaceFilter filter, NavmapSearchPlaceSorting sorting, + Action> callback, int pageNumber = 0, int pageSize = 8) { @@ -44,6 +46,7 @@ public SearchForPlaceAndShowResultsCommand( this.searchText = searchText; this.filter = filter; this.sorting = sorting; + this.callback = callback; this.pageNumber = pageNumber; this.pageSize = pageSize; } @@ -55,6 +58,8 @@ public async UniTask ExecuteAsync(CancellationToken ct) await ProcessPlaces(ct); await ProcessLiveEvents(ct); + + callback.Invoke(places!); } public void Undo() @@ -128,7 +133,8 @@ private async UniTask ProcessPlaces(CancellationToken ct) } else if (filter == NavmapSearchPlaceFilter.Visited) { - // TODO: implement visited places in local storage + // TODO: implement visited places + places = new List(0); } } diff --git a/Explorer/Assets/DCL/PluginSystem/Global/ExplorePanelPlugin.cs b/Explorer/Assets/DCL/PluginSystem/Global/ExplorePanelPlugin.cs index 69e645eb65..31ae32a84f 100644 --- a/Explorer/Assets/DCL/PluginSystem/Global/ExplorePanelPlugin.cs +++ b/Explorer/Assets/DCL/PluginSystem/Global/ExplorePanelPlugin.cs @@ -363,9 +363,10 @@ EventScheduleElementView CreatePoolElements(EventScheduleElementView asset) } } - private INavmapCommand CreateSearchPlaceCommand(string search, NavmapSearchPlaceFilter filter, NavmapSearchPlaceSorting sorting) => + private INavmapCommand CreateSearchPlaceCommand(string search, NavmapSearchPlaceFilter filter, NavmapSearchPlaceSorting sorting, + Action> callback) => new SearchForPlaceAndShowResultsCommand(placesAPIService, eventsApiService, placesAndEventsPanelController!, - searchResultPanelController!, searchBarController!, search, filter, sorting); + searchResultPanelController!, searchBarController!, search, filter, sorting, callback); private INavmapCommand CreateShowPlaceCommand(PlacesData.PlaceInfo placeInfo) => new ShowPlaceInfoCommand(placeInfo, navmapView!, placeInfoPanelController!, placesAndEventsPanelController!, eventsApiService,