implement search
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
1b6f6b25bf
commit
feb052e286
@ -1,12 +1,60 @@
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnSearchClicked(object sender, EventArgs e)
|
||||
{
|
||||
MakeSearch(SearchPrompt.Text);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue