implement search page
continuous-integration/drone/push Build is passing Details

master
maxime.BATISTA@etu.uca.fr 2 years ago
parent 060618d89f
commit 073fae6442

@ -1,15 +1,60 @@
namespace ShoopNCook.Pages;
using Microsoft.Maui.Storage;
using Models;
using Services;
using ShoopNCook.Views;
using System.Collections.ObjectModel;
namespace ShoopNCook.Pages;
public partial class SearchPage : ContentPage
{
public SearchPage()
private readonly IRecipesService recipesService;
private readonly IAccountRecipesPreferencesService preferences;
public ObservableCollection<RecipeView> FoundRecipes { get; private init; } = new ObservableCollection<RecipeView>();
public SearchPage(IRecipesService recipes, IAccountRecipesPreferencesService preferences)
{
InitializeComponent();
//TODO
BindingContext = this;
this.recipesService = recipes;
this.preferences = preferences;
InitializeComponent();
}
public void MakeSearch(string prompt)
{
if (string.IsNullOrEmpty(prompt))
{
return;
}
FoundRecipes.Clear();
foreach (RecipeInfo info in recipesService.SearchRecipes(prompt))
{
FoundRecipes.Add(new RecipeView(info, () =>
{
Recipe recipe = recipesService.GetRecipe(info);
if (recipe != null)
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1));
else
UserNotifier.Error("Could not find recipe");
}));
}
}
private async void OnBackButtonClicked(object sender, EventArgs e)
{
await Navigation.PopAsync();
}
private void OnSortByRateClicked(object sender, EventArgs e)
{
FoundRecipes.OrderBy(view => view.Info)
}
private void OnSearchClicked(object sender, EventArgs e)
{
MakeSearch(SearchPrompt.Text);
}
}
Loading…
Cancel
Save