namespace ShoopNCook.Pages; using Models; using ShoopNCook.Views; using Services; using Services; public partial class HomePage : ContentPage { public HomePage(Account account, IEndpoint endpoint) { InitializeComponent(); IRecipesService service = endpoint.RecipesService; IAccountRecipesPreferencesService 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()); } }