Skip to content
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

feat: search places bus event #2844

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Explorer/Assets/DCL/Navmap/INavmapBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using DCL.EventsApi;
using DCL.PlacesAPIService;
using System;
using System.Collections.Generic;
using System.Threading;

namespace DCL.Navmap
Expand All @@ -10,6 +11,7 @@ public interface INavmapBus
{
event Action<PlacesData.PlaceInfo> OnJumpIn;
event Action<PlacesData.PlaceInfo>? OnDestinationSelected;
event Action<IReadOnlyList<PlacesData.PlaceInfo>>? OnPlaceSearched;
event Action<string?>? OnFilterByCategory;

UniTask SelectPlaceAsync(PlacesData.PlaceInfo place, CancellationToken ct);
Expand Down
9 changes: 7 additions & 2 deletions Explorer/Assets/DCL/Navmap/NavmapCommandBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IReadOnlyList<PlacesData.PlaceInfo>> callback);
public delegate INavmapCommand ShowPlaceInfoFactory(PlacesData.PlaceInfo placeInfo);
public delegate INavmapCommand ShowEventInfoFactory(EventDTO @event, PlacesData.PlaceInfo? place = null);

Expand All @@ -20,6 +21,7 @@ public class NavmapCommandBus : INavmapBus

public event Action<PlacesData.PlaceInfo>? OnJumpIn;
public event Action<PlacesData.PlaceInfo>? OnDestinationSelected;
public event Action<IReadOnlyList<PlacesData.PlaceInfo>>? OnPlaceSearched;
public event Action<string?>? OnFilterByCategory;

public NavmapCommandBus(SearchPlaceFactory searchPlaceFactory,
Expand Down Expand Up @@ -55,7 +57,7 @@ public async UniTask SearchForPlaceAsync(NavmapSearchPlaceFilter filter, NavmapS
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);

Expand Down Expand Up @@ -89,5 +91,8 @@ public void JumpIn(PlacesData.PlaceInfo place) =>

public void FilterByCategory(string? category) =>
OnFilterByCategory?.Invoke(category);

private void OnSearchPlacePerformed(IReadOnlyList<PlacesData.PlaceInfo> places) =>
OnPlaceSearched?.Invoke(places);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class SearchForPlaceAndShowResultsCommand : INavmapCommand
private readonly string searchText;
private readonly NavmapSearchPlaceFilter filter;
private readonly NavmapSearchPlaceSorting sorting;
private readonly Action<IReadOnlyList<PlacesData.PlaceInfo>> callback;
private readonly int pageNumber;
private readonly int pageSize;
private List<PlacesData.PlaceInfo>? places;
Expand All @@ -33,6 +34,7 @@ public SearchForPlaceAndShowResultsCommand(
string searchText,
NavmapSearchPlaceFilter filter,
NavmapSearchPlaceSorting sorting,
Action<IReadOnlyList<PlacesData.PlaceInfo>> callback,
int pageNumber = 0,
int pageSize = 8)
{
Expand All @@ -44,6 +46,7 @@ public SearchForPlaceAndShowResultsCommand(
this.searchText = searchText;
this.filter = filter;
this.sorting = sorting;
this.callback = callback;
this.pageNumber = pageNumber;
this.pageSize = pageSize;
}
Expand All @@ -55,6 +58,8 @@ public async UniTask ExecuteAsync(CancellationToken ct)

await ProcessPlacesAsync(ct);
await ProcessLiveEventsAsync(ct);

callback.Invoke(places!);
}

public void Undo()
Expand Down Expand Up @@ -128,7 +133,8 @@ private async UniTask ProcessPlacesAsync(CancellationToken ct)
}
else if (filter == NavmapSearchPlaceFilter.Visited)
{
// TODO: implement visited places in local storage
// TODO: implement visited places
places = new List<PlacesData.PlaceInfo>(0);
}
}

Expand Down
5 changes: 3 additions & 2 deletions Explorer/Assets/DCL/PluginSystem/Global/ExplorePanelPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,10 @@ EventScheduleElementView CreatePoolElements(EventScheduleElementView asset)
}
}

private INavmapCommand CreateSearchPlaceCommand(string search, NavmapSearchPlaceFilter filter, NavmapSearchPlaceSorting sorting) =>
private INavmapCommand CreateSearchPlaceCommand(string search, NavmapSearchPlaceFilter filter, NavmapSearchPlaceSorting sorting,
Action<IReadOnlyList<PlacesData.PlaceInfo>> 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,
Expand Down
Loading