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.
ShopNCook/Views/HomePage.xaml.cs

43 lines
1.4 KiB

namespace ShoopNCook.Pages;
using Models;
using ShoopNCook.Views;
using Endpoint;
using LocalEndpoint;
public partial class HomePage : ContentPage
{
public HomePage(Account account, IEndpoint endpoint)
{
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);
if (recipe != null)
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1));
else
{
UserNotifier.Error("Could not find recipe");
}
}));
}
service.PopularRecipes().ForEach(recipe => PushRecipe(PopularsList, recipe));
preferences.GetRecommendedRecipes().ForEach(recipe => PushRecipe(RecommendedList, recipe));
ProfilePictureImage.Source = ImageSource.FromUri(account.User.ProfilePicture);
ProfilePictureName.Text = account.User.Name;
}
private async void OnSyncButtonClicked(object sender, EventArgs e)
{
await Shell.Current.Navigation.PushAsync(new SearchPage());
}
}