You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.2 KiB
78 lines
2.2 KiB
using Endpoint;
|
|
using LocalEndpoint;
|
|
using Models;
|
|
using ShoopNCook.Views;
|
|
|
|
namespace ShoopNCook.Pages;
|
|
|
|
public partial class MyRecipesPage : ContentPage
|
|
{
|
|
|
|
private IUserNotifier notifier;
|
|
private IRecipesService service;
|
|
private IAccountRecipes recipes;
|
|
|
|
public MyRecipesPage(
|
|
Account account,
|
|
IRecipesService service,
|
|
IUserNotifier notifier)
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.notifier = notifier;
|
|
this.service = service;
|
|
this.recipes = service.GetRecipesOf(account);
|
|
|
|
recipes.GetAccountRecipes().ForEach(AddRecipeView);
|
|
}
|
|
|
|
private void AddRecipeView(RecipeInfo info)
|
|
{
|
|
RecipesLayout.Children.Add(new OwnedRecipeView(info, () =>
|
|
{
|
|
Recipe recipe = service.GetRecipe(info);
|
|
AccountRecipeRate? rate = recipes.FindRate(info);
|
|
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, rate, 1));
|
|
},
|
|
() => RemoveRecipe(info)
|
|
));
|
|
}
|
|
|
|
private void RemoveRecipe(RecipeInfo info)
|
|
{
|
|
if (!recipes.RemoveRecipe(info))
|
|
{
|
|
notifier.Error("Could not remove recipe");
|
|
return;
|
|
}
|
|
foreach (OwnedRecipeView view in RecipesLayout.Children)
|
|
{
|
|
if (view.IsViewing(info))
|
|
{
|
|
RecipesLayout.Remove(view);
|
|
break;
|
|
}
|
|
}
|
|
notifier.Success("Recipe successfully removed");
|
|
}
|
|
|
|
private void OnBackButtonClicked(object sender, EventArgs e)
|
|
{
|
|
Navigation.PopAsync();
|
|
}
|
|
private void OnAddRecipeButtonClicked(object sender, EventArgs e)
|
|
{
|
|
var page = new CreateRecipePage(recipes.Account.User, notifier, recipe =>
|
|
{
|
|
if (!recipes.UploadRecipe(recipe))
|
|
{
|
|
notifier.Error("Could not upload recipe.");
|
|
return;
|
|
}
|
|
notifier.Success("Recipe Successfuly uploaded !");
|
|
AddRecipeView(recipe.Info);
|
|
Shell.Current.Navigation.PopAsync(); //go back to current recipe page.
|
|
});
|
|
Shell.Current.Navigation.PushAsync(page); //display RecipePage editor
|
|
}
|
|
} |