Merge pull request 'Integrate Endpoint/API/models for main functionallities' (#50) from models/integration into master
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: ShopNCook/ShopNCook#50pull/51/head
commit
e2df22c858
@ -1,17 +1,42 @@
|
|||||||
using Models;
|
|
||||||
|
|
||||||
namespace ShoopNCook.Pages;
|
namespace ShoopNCook.Pages;
|
||||||
|
using Models;
|
||||||
|
using ShoopNCook.Views;
|
||||||
|
using Endpoint;
|
||||||
|
using LocalEndpoint;
|
||||||
|
|
||||||
public partial class HomePage : ContentPage
|
public partial class HomePage : ContentPage
|
||||||
{
|
{
|
||||||
public HomePage(Account account, IApp app)
|
public HomePage(Account account, IUserNotifier notifier, IEndpoint endpoint)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
IRecipesService service = endpoint.RecipesService;
|
||||||
|
IAccountRecipesPreferences preferences = service.GetPreferencesOf(account);
|
||||||
|
|
||||||
|
|
||||||
|
//TODO this code can be factorised
|
||||||
|
void PushRecipe(Layout layout, RecipeInfo info)
|
||||||
|
{
|
||||||
|
layout.Children.Add(new RecipeView(info, () =>
|
||||||
|
{
|
||||||
|
Recipe recipe = service.GetRecipe(info);
|
||||||
|
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1));
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
service.PopularRecipes().ForEach(recipe => PushRecipe(PopularsList, recipe));
|
||||||
|
preferences.GetRecommendedRecipes().ForEach(recipe => PushRecipe(RecommendedList, recipe));
|
||||||
|
|
||||||
ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
|
ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
|
||||||
ProfilePictureName.Text = account.User.Name;
|
ProfilePictureName.Text = account.User.Name;
|
||||||
}
|
}
|
||||||
private async void OnSyncButtonClicked(object sender, EventArgs e)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void OnSyncButtonClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await Shell.Current.Navigation.PushAsync(new SearchPage());
|
Shell.Current.Navigation.PushAsync(new SearchPage());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,11 +1,44 @@
|
|||||||
|
using Endpoint;
|
||||||
|
using LocalEndpoint;
|
||||||
using Models;
|
using Models;
|
||||||
|
using ShoopNCook.Views;
|
||||||
|
|
||||||
namespace ShoopNCook.Pages;
|
namespace ShoopNCook.Pages;
|
||||||
|
|
||||||
public partial class MyListPage : ContentPage
|
public partial class MyListPage : ContentPage
|
||||||
{
|
{
|
||||||
public MyListPage(Account account, IApp app)
|
|
||||||
|
private readonly IAccountRecipesPreferences preferences;
|
||||||
|
private readonly IUserNotifier notifier;
|
||||||
|
private readonly IRecipesService service;
|
||||||
|
|
||||||
|
public MyListPage(Account account, IUserNotifier notifier, IRecipesService service)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
this.preferences = service.GetPreferencesOf(account);
|
||||||
|
this.notifier = notifier;
|
||||||
|
this.service = service;
|
||||||
|
|
||||||
|
UpdateMyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateMyList()
|
||||||
|
{
|
||||||
|
RecipesLayout.Children.Clear();
|
||||||
|
preferences.GetWeeklyList().ForEach(tuple =>
|
||||||
|
{
|
||||||
|
RecipeInfo info = tuple.Item1;
|
||||||
|
RecipesLayout.Children.Add(new StoredRecipeView(info, tuple.Item2, amount =>
|
||||||
|
{
|
||||||
|
Recipe recipe = service.GetRecipe(info);
|
||||||
|
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, amount));
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
|
||||||
|
{
|
||||||
|
UpdateMyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,19 +1,85 @@
|
|||||||
|
using Endpoint;
|
||||||
|
using LocalEndpoint;
|
||||||
|
using Models;
|
||||||
|
using ShoopNCook.Views;
|
||||||
|
|
||||||
namespace ShoopNCook.Pages;
|
namespace ShoopNCook.Pages;
|
||||||
|
|
||||||
public partial class MyRecipesPage : ContentPage
|
public partial class MyRecipesPage : ContentPage
|
||||||
{
|
{
|
||||||
public MyRecipesPage()
|
|
||||||
|
private IUserNotifier notifier;
|
||||||
|
private IRecipesService service;
|
||||||
|
private Account account;
|
||||||
|
|
||||||
|
public MyRecipesPage(
|
||||||
|
Account account,
|
||||||
|
IRecipesService service,
|
||||||
|
IUserNotifier notifier)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
this.notifier = notifier;
|
||||||
|
this.service = service;
|
||||||
|
this.account = account;
|
||||||
|
|
||||||
|
service
|
||||||
|
.GetRecipesOf(account)
|
||||||
|
.GetAccountRecipes()
|
||||||
|
.ForEach(AddRecipeView);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddRecipeView(RecipeInfo info)
|
||||||
|
{
|
||||||
|
RecipesLayout.Children.Add(new OwnedRecipeView(info, () =>
|
||||||
|
{
|
||||||
|
Recipe recipe = service.GetRecipe(info);
|
||||||
|
IAccountRecipesPreferences preferences = service.GetPreferencesOf(account);
|
||||||
|
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1));
|
||||||
|
},
|
||||||
|
() => RemoveRecipe(info)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RemoveRecipe(RecipeInfo info)
|
||||||
|
{
|
||||||
|
IAccountOwnedRecipes recipes = service.GetRecipesOf(account);
|
||||||
|
|
||||||
|
if (!recipes.RemoveRecipe(info))
|
||||||
|
{
|
||||||
|
notifier.Error("Could not remove recipe");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
private async void OnBackButtonClicked(object sender, EventArgs e)
|
foreach (OwnedRecipeView view in RecipesLayout.Children)
|
||||||
|
{
|
||||||
|
if (view.IsViewing(info))
|
||||||
{
|
{
|
||||||
await Navigation.PopAsync();
|
RecipesLayout.Remove(view);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
private async void AddRecipeButtonClicked(object sender, EventArgs e)
|
}
|
||||||
|
notifier.Success("Recipe successfully removed");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBackButtonClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await Shell.Current.Navigation.PushAsync(new CreateRecipePage());
|
Navigation.PopAsync();
|
||||||
|
}
|
||||||
|
private void OnAddRecipeButtonClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
IAccountOwnedRecipes recipes = service.GetRecipesOf(account);
|
||||||
|
|
||||||
|
var page = new CreateRecipePage(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
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue