From 73dbd82dfbeb5d0355278c0688e7bf21a8510ba3 Mon Sep 17 00:00:00 2001 From: Maxime BATISTA Date: Fri, 2 Jun 2023 15:18:18 +0200 Subject: [PATCH] fixes --- .../Data/CatastrophicPerformancesDatabase.cs | 3 ++ LocalServices/Data/StubDatabase.cs | 2 +- LocalServices/LocalEndpoint.cs | 12 +++--- Models/Ingredient.cs | 2 +- ShoopNCook.csproj | 3 -- UserNotifier.cs | 24 +++++------- Views/Components/IngredientEntry.xaml | 4 +- Views/Components/IngredientEntry.xaml.cs | 15 ++++--- Views/Components/IngredientView.xaml.cs | 2 +- Views/Components/NoticePopup.xaml | 10 ----- Views/Components/NoticePopup.xaml.cs | 39 ------------------- Views/CreateRecipePage.xaml.cs | 8 +++- 12 files changed, 39 insertions(+), 85 deletions(-) delete mode 100644 Views/Components/NoticePopup.xaml delete mode 100644 Views/Components/NoticePopup.xaml.cs diff --git a/LocalServices/Data/CatastrophicPerformancesDatabase.cs b/LocalServices/Data/CatastrophicPerformancesDatabase.cs index 462417b..56bb1fa 100644 --- a/LocalServices/Data/CatastrophicPerformancesDatabase.cs +++ b/LocalServices/Data/CatastrophicPerformancesDatabase.cs @@ -1,5 +1,6 @@ using Models; using System.Collections.Immutable; +using System.Diagnostics; using System.Text; using System.Text.Json; @@ -52,6 +53,7 @@ namespace LocalServices.Data { accountsData[account.Email] = new AccountData(account.User.Id, account.Email, passwordHash); Save(ACCOUNTS_FILENAME, accountsData); + InsertUser(account.User); } public Recipe? GetRecipe(Guid id) @@ -170,6 +172,7 @@ namespace LocalServices.Data } catch (IOException e) { + Debug.WriteLine(e + " in thread " + Thread.CurrentThread); if (fs != null) fs.Dispose(); diff --git a/LocalServices/Data/StubDatabase.cs b/LocalServices/Data/StubDatabase.cs index 61b759a..156f3ba 100644 --- a/LocalServices/Data/StubDatabase.cs +++ b/LocalServices/Data/StubDatabase.cs @@ -17,7 +17,7 @@ namespace LocalServices.Data public Recipe? GetRecipe(Guid id) { - return new Recipe(new RecipeInfo("Foo", 4, 5, new Uri("https://th.bing.com/th/id/R.e57009c4044bef3e86f8a7b18a7cf36a?rik=K3dSu3KoTgeRSw&pid=ImgRaw&r=0"), 4.5F, id), User, new List { new Ingredient("Chocolate", 4) }.ToImmutableList(), new List { new PreparationStep("Eat Chocolate", "Eat the chocolate") }.ToImmutableList()); + return new Recipe(new RecipeInfo("Foo", 4, 5, new Uri("https://th.bing.com/th/id/R.e57009c4044bef3e86f8a7b18a7cf36a?rik=K3dSu3KoTgeRSw&pid=ImgRaw&r=0"), 4.5F, id), User, new List { new Ingredient("Chocolate", 4, "g") }.ToImmutableList(), new List { new PreparationStep("Eat Chocolate", "Eat the chocolate") }.ToImmutableList()); } public ImmutableDictionary GetRecipeListOf(Guid user) diff --git a/LocalServices/LocalEndpoint.cs b/LocalServices/LocalEndpoint.cs index 467aca3..3e524e2 100644 --- a/LocalServices/LocalEndpoint.cs +++ b/LocalServices/LocalEndpoint.cs @@ -51,12 +51,12 @@ namespace LocalServices db.InsertAccount(new Account(USER2, "yanis@google.com"), "123456"); db.InsertAccount(new Account(USER3, "leo@google.com"), "123456"); - db.InsertRecipe(new Recipe(new RecipeInfo("Chicken Salad", 500, 20, new Uri("https://healthyfitnessmeals.com/wp-content/uploads/2021/04/Southwest-chicken-salad-7-500x500.jpg"), 4, Guid.NewGuid()), USER1, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); - db.InsertRecipe(new Recipe(new RecipeInfo("Chocolate Cake", 2500, 10, new Uri("https://bakewithshivesh.com/wp-content/uploads/2022/08/IMG_0248-scaled.jpg"), 3, Guid.NewGuid()), USER2, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); - db.InsertRecipe(new Recipe(new RecipeInfo("Salmon", 20, 10, new Uri("https://www.wholesomeyum.com/wp-content/uploads/2021/06/wholesomeyum-Pan-Seared-Salmon-Recipe-13.jpg"), 4, Guid.NewGuid()), USER1, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); - db.InsertRecipe(new Recipe(new RecipeInfo("Fish", 50, 30, new Uri("https://www.ciaanet.org/wp-content/uploads/2022/07/Atlantic-and-Pacific-whole-salmon-1024x683.jpg"), 4.5F, Guid.NewGuid()), USER3, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); - db.InsertRecipe(new Recipe(new RecipeInfo("Space Cake", 800, 5, new Uri("https://static.youmiam.com/images/recipe/1500x1000/space-cake-22706?placeholder=web_recipe&sig=f14a7a86da837c6b8cc678cde424d6d5902f99ec&v3"), 5, Guid.NewGuid()), USER3, new List { new Ingredient("Ingredient 1", 6) }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); - db.InsertRecipe(new Recipe(new RecipeInfo("Cupcake", 500, 12, new Uri("https://www.mycake.fr/wp-content/uploads/2015/12/rs_cupcake_4x3.jpg"), 4.2F, Guid.NewGuid()), USER1, new List { new Ingredient("Chocolate", 4) }.ToImmutableList(), new List { new PreparationStep("Eat Chocolate", "Eat the chocolate") }.ToImmutableList())); + db.InsertRecipe(new Recipe(new RecipeInfo("Chicken Salad", 500, 20, new Uri("https://healthyfitnessmeals.com/wp-content/uploads/2021/04/Southwest-chicken-salad-7-500x500.jpg"), 4, Guid.NewGuid()), USER1, new List { new Ingredient("Ingredient 1", 6, "g") }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); + db.InsertRecipe(new Recipe(new RecipeInfo("Chocolate Cake", 2500, 10, new Uri("https://bakewithshivesh.com/wp-content/uploads/2022/08/IMG_0248-scaled.jpg"), 3, Guid.NewGuid()), USER2, new List { new Ingredient("Ingredient 1", 6, "g") }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); + db.InsertRecipe(new Recipe(new RecipeInfo("Salmon", 20, 10, new Uri("https://www.wholesomeyum.com/wp-content/uploads/2021/06/wholesomeyum-Pan-Seared-Salmon-Recipe-13.jpg"), 4, Guid.NewGuid()), USER1, new List { new Ingredient("Ingredient 1", 6, "g") }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); + db.InsertRecipe(new Recipe(new RecipeInfo("Fish", 50, 30, new Uri("https://www.ciaanet.org/wp-content/uploads/2022/07/Atlantic-and-Pacific-whole-salmon-1024x683.jpg"), 4.5F, Guid.NewGuid()), USER3, new List { new Ingredient("Ingredient 1", 6, "g") }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); + db.InsertRecipe(new Recipe(new RecipeInfo("Space Cake", 800, 5, new Uri("https://static.youmiam.com/images/recipe/1500x1000/space-cake-22706?placeholder=web_recipe&sig=f14a7a86da837c6b8cc678cde424d6d5902f99ec&v3"), 5, Guid.NewGuid()), USER3, new List { new Ingredient("Ingredient 1", 6, "g") }.ToImmutableList(), new List { new PreparationStep("Step 1", "Bake the eggs") }.ToImmutableList())); + db.InsertRecipe(new Recipe(new RecipeInfo("Cupcake", 500, 12, new Uri("https://www.mycake.fr/wp-content/uploads/2015/12/rs_cupcake_4x3.jpg"), 4.2F, Guid.NewGuid()), USER1, new List { new Ingredient("Chocolate", 4, "g") }.ToImmutableList(), new List { new PreparationStep("Eat Chocolate", "Eat the chocolate") }.ToImmutableList())); } /// diff --git a/Models/Ingredient.cs b/Models/Ingredient.cs index 6cacc4a..f0e14ee 100644 --- a/Models/Ingredient.cs +++ b/Models/Ingredient.cs @@ -9,5 +9,5 @@ namespace Models /// The ingredient's name /// The ingredient's amount (in kilograms or liters) [DataContract] - public record Ingredient([property: DataMember] string Name, [property: DataMember] float Amount); + public record Ingredient([property: DataMember] string Name, [property: DataMember] float Amount, [property: DataMember] string Unit); } diff --git a/ShoopNCook.csproj b/ShoopNCook.csproj index 704771c..1310c37 100644 --- a/ShoopNCook.csproj +++ b/ShoopNCook.csproj @@ -149,9 +149,6 @@ MSBuild:Compile - - MSBuild:Compile - MSBuild:Compile diff --git a/UserNotifier.cs b/UserNotifier.cs index 6846a0d..8432fc8 100644 --- a/UserNotifier.cs +++ b/UserNotifier.cs @@ -1,15 +1,9 @@ using CommunityToolkit.Maui.Alerts; using CommunityToolkit.Maui.Core; -using CommunityToolkit.Maui.Views; -using ShoopNCook.Views.Components; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ShoopNCook -{ + + +namespace ShoopNCook +{ internal class UserNotifier { private static async Task Show(string message, string messageType) @@ -23,8 +17,8 @@ namespace ShoopNCook var toast = Toast.Make(message, duration, fontSize); await toast.Show(cancellationTokenSource.Token); - } - + } + public static void Error(string message) @@ -43,6 +37,6 @@ namespace ShoopNCook { Show(message, "Success"); } - } - -} + } + +} diff --git a/Views/Components/IngredientEntry.xaml b/Views/Components/IngredientEntry.xaml index 0a39bdc..769bd12 100644 --- a/Views/Components/IngredientEntry.xaml +++ b/Views/Components/IngredientEntry.xaml @@ -22,7 +22,7 @@ Style="{StaticResource UserInput}" Placeholder="Ingredient Name" HeightRequest="40" - x:Name="NameEntry"/> + Text="{Binding NameText, Mode=OneWayToSource}"/> + Text="{Binding QuantityText, Mode=OneWayToSource}"/> - - - diff --git a/Views/Components/NoticePopup.xaml.cs b/Views/Components/NoticePopup.xaml.cs deleted file mode 100644 index 700634a..0000000 --- a/Views/Components/NoticePopup.xaml.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ShoopNCook.Views.Components; -using Microsoft.Maui.Graphics; - -public partial class NoticePopup : ContentView -{ - public NoticePopup(string message, string messageType) - { - - InitializeComponent(); - MessageLabel.Text = message; - - switch (messageType) - { - case "Error": - this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Red; - break; - case "Warning": - this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Yellow; - break; - case "Notice": - this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Blue; - break; - case "Success": - this.BackgroundColor = Microsoft.Maui.Graphics.Colors.Green; - break; - } - - // Display the toast for 3 seconds - - Device.StartTimer(TimeSpan.FromSeconds(3), () => - { - // Close the toast - // You need to replace this with your actual code to close the toast - this.IsVisible = false; - return false; - }); - - } -} diff --git a/Views/CreateRecipePage.xaml.cs b/Views/CreateRecipePage.xaml.cs index d5bf8ec..91f5b8a 100644 --- a/Views/CreateRecipePage.xaml.cs +++ b/Views/CreateRecipePage.xaml.cs @@ -61,8 +61,12 @@ public partial class CreateRecipePage : ContentPage //TODO .SetImage(RecipeImage) ; - foreach (IngredientEntry entry in IngredientList.Children) - builder.AddIngredient(entry.MakeValue()); + foreach (IngredientEntry entry in IngredientList.Children) + { + var ingredient = entry.MakeValue(); + if (ingredient == null) return; + builder.AddIngredient(ingredient); + } foreach (StepEntry entry in StepList.Children) builder.AddStep(entry.MakeStep());