From d269e2708cfd1976bf3755b6749cc7d5e9f6ce16 Mon Sep 17 00:00:00 2001 From: "maxime.BATISTA@etu.uca.fr" Date: Sun, 14 May 2023 12:12:10 +0200 Subject: [PATCH 01/27] add toolkit --- App.xaml.cs | 4 +-- ConnectAppShell.xaml.cs | 4 +-- ConsoleUserNotifier.cs | 31 --------------------- Controllers/ConnectionController.cs | 8 +++--- Controllers/MorePageController.cs | 4 +-- IApp.cs | 2 -- IUserNotifier.cs | 19 ------------- MainAppShell.xaml.cs | 6 ++--- MauiProgram.cs | 4 ++- ShoopNCook.csproj | 4 +++ UserNotifier.cs | 40 ++++++++++++++++++++++++++++ Views/Components/NoticePopup.xaml | 11 ++++++++ Views/Components/NoticePopup.xaml.cs | 9 +++++++ Views/CreateRecipePage.xaml.cs | 6 ++--- Views/FavoritesPage.xaml.cs | 6 ++--- Views/HomePage.xaml.cs | 4 +-- Views/MyListPage.xaml.cs | 6 ++--- Views/MyRecipesPage.xaml.cs | 17 +++++------- Views/RecipePage.xaml.cs | 10 +++---- 19 files changed, 97 insertions(+), 98 deletions(-) delete mode 100644 ConsoleUserNotifier.cs delete mode 100644 IUserNotifier.cs create mode 100644 UserNotifier.cs create mode 100644 Views/Components/NoticePopup.xaml create mode 100644 Views/Components/NoticePopup.xaml.cs diff --git a/App.xaml.cs b/App.xaml.cs index c873ce2..b769638 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -8,8 +8,6 @@ public partial class App : Application, ConnectionObserver, IApp private IEndpoint Endpoint = new LocalEndpoint(); - public IUserNotifier Notifier => new ConsoleUserNotifier(); - public App() { InitializeComponent(); @@ -25,7 +23,7 @@ public partial class App : Application, ConnectionObserver, IApp public void ForceLogin() { - Shell shell = new ConnectAppShell(this, Endpoint.AuthService, Notifier); + Shell shell = new ConnectAppShell(this, Endpoint.AuthService); shell.GoToAsync("//Splash"); MainPage = shell; } diff --git a/ConnectAppShell.xaml.cs b/ConnectAppShell.xaml.cs index dd44352..8e831eb 100644 --- a/ConnectAppShell.xaml.cs +++ b/ConnectAppShell.xaml.cs @@ -7,9 +7,9 @@ using ShoopNCook.Pages; public partial class ConnectAppShell : Shell { - public ConnectAppShell(ConnectionObserver observer, IAuthService accounts, IUserNotifier notifier) + public ConnectAppShell(ConnectionObserver observer, IAuthService accounts) { - ConnectionController controller = new ConnectionController(observer, accounts, notifier); + ConnectionController controller = new ConnectionController(observer, accounts); InitializeComponent(); LoginPage.ContentTemplate = new DataTemplate(() => new LoginPage(controller)); RegisterPage.ContentTemplate = new DataTemplate(() => new RegisterPage(controller)); diff --git a/ConsoleUserNotifier.cs b/ConsoleUserNotifier.cs deleted file mode 100644 index 1a06c28..0000000 --- a/ConsoleUserNotifier.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace ShoopNCook -{ - /// - /// A notice reporter implementation that prints in console the applications's user notices. - /// - public class ConsoleUserNotifier : - IUserNotifier - { - - public void Success(string message) - { - Console.WriteLine(" Success: " + message); - } - - - public void Error(string message) - { - Console.WriteLine(" Error: " + message); - } - - public void Notice(string message) - { - Console.WriteLine(" Notice: " + message); - } - - public void Warn(string message) - { - Console.WriteLine(" Warn: " + message); - } - } -} diff --git a/Controllers/ConnectionController.cs b/Controllers/ConnectionController.cs index 0e59bb7..5958a6a 100644 --- a/Controllers/ConnectionController.cs +++ b/Controllers/ConnectionController.cs @@ -7,11 +7,9 @@ namespace ShoopNCook.Controllers { private readonly ConnectionObserver observer; private readonly IAuthService accounts; - private readonly IUserNotifier notifier; - public ConnectionController(ConnectionObserver observer, IAuthService accounts, IUserNotifier notifier) { + public ConnectionController(ConnectionObserver observer, IAuthService accounts) { this.observer = observer; this.accounts = accounts; - this.notifier = notifier; } public void Login(string email, string password) @@ -19,7 +17,7 @@ namespace ShoopNCook.Controllers Account? acc = accounts.Login(email, password); if (acc == null) { - notifier.Error("Email or password invalid."); + UserNotifier.Error("Email or password invalid."); return; } observer.OnAccountConnected(acc); @@ -30,7 +28,7 @@ namespace ShoopNCook.Controllers Account? acc = accounts.Register(username, email, password); if (acc == null) { - notifier.Error("Invalid credentials."); + UserNotifier.Error("Invalid credentials."); return; } observer.OnAccountConnected(acc); diff --git a/Controllers/MorePageController.cs b/Controllers/MorePageController.cs index c8ecee8..5b5fd56 100644 --- a/Controllers/MorePageController.cs +++ b/Controllers/MorePageController.cs @@ -20,13 +20,13 @@ namespace ShoopNCook.Controllers public void Logout() { - app.Notifier.Notice("You have been loged out."); + UserNotifier.Notice("You have been loged out."); app.ForceLogin(); } public void GoToMyRecipesPage() { - Shell.Current.Navigation.PushAsync(new MyRecipesPage(account, endpoint.RecipesService, app.Notifier)); + Shell.Current.Navigation.PushAsync(new MyRecipesPage(account, endpoint.RecipesService)); } public void GoToProfilePage() diff --git a/IApp.cs b/IApp.cs index dad1336..bfc7b8f 100644 --- a/IApp.cs +++ b/IApp.cs @@ -9,8 +9,6 @@ namespace ShoopNCook { public interface IApp { - public IUserNotifier Notifier { get; } - public void ForceLogin(); } } diff --git a/IUserNotifier.cs b/IUserNotifier.cs deleted file mode 100644 index 4576a70..0000000 --- a/IUserNotifier.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ShoopNCook -{ - public interface IUserNotifier - { - public void Success(string message); - - public void Notice(string message); - - public void Error(string message); - - public void Warn(string message); - } -} diff --git a/MainAppShell.xaml.cs b/MainAppShell.xaml.cs index d3f6bc1..decb72a 100644 --- a/MainAppShell.xaml.cs +++ b/MainAppShell.xaml.cs @@ -9,9 +9,9 @@ public partial class MainAppShell : Shell public MainAppShell(Account account, IEndpoint endpoint, IApp app) { InitializeComponent(); - HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, app.Notifier, endpoint)); - FavoritesTab.ContentTemplate = new DataTemplate(() => new FavoritesPage(account, app.Notifier, endpoint.RecipesService)); - MyListTab.ContentTemplate = new DataTemplate(() => new MyListPage(account, app.Notifier, endpoint.RecipesService)); + HomeTab.ContentTemplate = new DataTemplate(() => new HomePage(account, endpoint)); + FavoritesTab.ContentTemplate = new DataTemplate(() => new FavoritesPage(account, endpoint.RecipesService)); + MyListTab.ContentTemplate = new DataTemplate(() => new MyListPage(account, endpoint.RecipesService)); MoreTab.ContentTemplate = new DataTemplate(() => new MorePage(account, new MorePageController(account, endpoint, app))); } } diff --git a/MauiProgram.cs b/MauiProgram.cs index 7dc9f23..420e008 100644 --- a/MauiProgram.cs +++ b/MauiProgram.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using CommunityToolkit.Maui; +using Microsoft.Extensions.Logging; namespace ShoopNCook; @@ -9,6 +10,7 @@ public static class MauiProgram var builder = MauiApp.CreateBuilder(); builder .UseMauiApp() + .UseMauiCommunityToolkit() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); diff --git a/ShoopNCook.csproj b/ShoopNCook.csproj index 8a80861..f6b7dbe 100644 --- a/ShoopNCook.csproj +++ b/ShoopNCook.csproj @@ -113,6 +113,7 @@ + @@ -142,6 +143,9 @@ MSBuild:Compile + + MSBuild:Compile + MSBuild:Compile diff --git a/UserNotifier.cs b/UserNotifier.cs new file mode 100644 index 0000000..aa97bf2 --- /dev/null +++ b/UserNotifier.cs @@ -0,0 +1,40 @@ +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 +{ + internal class UserNotifier + { + + private static void Show(NoticePopup popup) + { + var page = Shell.Current.CurrentPage; + page.ShowPopup(new Popup + { + Content = popup + }); + } + + public static void Error(string message) + { + Show(new NoticePopup()); + } + public static void Warn(string message) + { + Show(new NoticePopup()); + } + public static void Notice(string message) + { + Show(new NoticePopup()); + } + public static void Success(string message) + { + Show(new NoticePopup()); + } + } +} diff --git a/Views/Components/NoticePopup.xaml b/Views/Components/NoticePopup.xaml new file mode 100644 index 0000000..ab69bae --- /dev/null +++ b/Views/Components/NoticePopup.xaml @@ -0,0 +1,11 @@ + + + + + diff --git a/Views/Components/NoticePopup.xaml.cs b/Views/Components/NoticePopup.xaml.cs new file mode 100644 index 0000000..1957bc7 --- /dev/null +++ b/Views/Components/NoticePopup.xaml.cs @@ -0,0 +1,9 @@ +namespace ShoopNCook.Views.Components; + +public partial class NoticePopup : ContentView +{ + public NoticePopup() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/Views/CreateRecipePage.xaml.cs b/Views/CreateRecipePage.xaml.cs index 8c5bea0..f6f468d 100644 --- a/Views/CreateRecipePage.xaml.cs +++ b/Views/CreateRecipePage.xaml.cs @@ -8,14 +8,12 @@ public partial class CreateRecipePage : ContentPage private User owner; private Action onRecipeCreated; - private IUserNotifier notifier; - public CreateRecipePage(User owner, IUserNotifier notifier, Action onRecipeCreated) + public CreateRecipePage(User owner, Action onRecipeCreated) { InitializeComponent(); this.owner = owner; this.onRecipeCreated = onRecipeCreated; - this.notifier = notifier; } private void OnAddIngredientTapped(object sender, TappedEventArgs e) @@ -53,7 +51,7 @@ public partial class CreateRecipePage : ContentPage if (hadErrors) { - notifier.Error("You need to fix input errors before upload."); + UserNotifier.Error("You need to fix input errors before upload."); return; } diff --git a/Views/FavoritesPage.xaml.cs b/Views/FavoritesPage.xaml.cs index 20b9ef2..a02523e 100644 --- a/Views/FavoritesPage.xaml.cs +++ b/Views/FavoritesPage.xaml.cs @@ -10,14 +10,12 @@ public partial class FavoritesPage : ContentPage { private readonly Account account; - private readonly IUserNotifier notifier; private IRecipesService service; - public FavoritesPage(Account account, IUserNotifier notifier, IRecipesService service) + public FavoritesPage(Account account, IRecipesService service) { InitializeComponent(); this.account = account; - this.notifier = notifier; this.service = service; UpdateFavorites(); @@ -32,7 +30,7 @@ public partial class FavoritesPage : ContentPage RecipeViewLayout.Children.Add(new RecipeView(info, () => { Recipe recipe = service.GetRecipe(info); - Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1)); + Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1)); })); }); } diff --git a/Views/HomePage.xaml.cs b/Views/HomePage.xaml.cs index b74cfd2..333b718 100644 --- a/Views/HomePage.xaml.cs +++ b/Views/HomePage.xaml.cs @@ -7,7 +7,7 @@ using LocalEndpoint; public partial class HomePage : ContentPage { - public HomePage(Account account, IUserNotifier notifier, IEndpoint endpoint) + public HomePage(Account account, IEndpoint endpoint) { InitializeComponent(); @@ -21,7 +21,7 @@ public partial class HomePage : ContentPage layout.Children.Add(new RecipeView(info, () => { Recipe recipe = service.GetRecipe(info); - Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1)); + Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1)); })); } diff --git a/Views/MyListPage.xaml.cs b/Views/MyListPage.xaml.cs index 87cddb5..f6f8f08 100644 --- a/Views/MyListPage.xaml.cs +++ b/Views/MyListPage.xaml.cs @@ -9,15 +9,13 @@ public partial class MyListPage : ContentPage { private readonly IAccountRecipesPreferences preferences; - private readonly IUserNotifier notifier; private readonly IRecipesService service; - public MyListPage(Account account, IUserNotifier notifier, IRecipesService service) + public MyListPage(Account account, IRecipesService service) { InitializeComponent(); this.preferences = service.GetPreferencesOf(account); - this.notifier = notifier; this.service = service; UpdateMyList(); @@ -32,7 +30,7 @@ public partial class MyListPage : ContentPage RecipesLayout.Children.Add(new StoredRecipeView(info, tuple.Item2, amount => { Recipe recipe = service.GetRecipe(info); - Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, amount)); + Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, amount)); })); }); } diff --git a/Views/MyRecipesPage.xaml.cs b/Views/MyRecipesPage.xaml.cs index 952d786..78bcc85 100644 --- a/Views/MyRecipesPage.xaml.cs +++ b/Views/MyRecipesPage.xaml.cs @@ -8,18 +8,15 @@ namespace ShoopNCook.Pages; public partial class MyRecipesPage : ContentPage { - private IUserNotifier notifier; private IRecipesService service; private Account account; public MyRecipesPage( Account account, - IRecipesService service, - IUserNotifier notifier) + IRecipesService service) { InitializeComponent(); - this.notifier = notifier; this.service = service; this.account = account; @@ -35,7 +32,7 @@ public partial class MyRecipesPage : ContentPage { Recipe recipe = service.GetRecipe(info); IAccountRecipesPreferences preferences = service.GetPreferencesOf(account); - Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1)); + Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1)); }, () => RemoveRecipe(info) )); @@ -47,7 +44,7 @@ public partial class MyRecipesPage : ContentPage if (!recipes.RemoveRecipe(info)) { - notifier.Error("Could not remove recipe"); + UserNotifier.Error("Could not remove recipe"); return; } foreach (OwnedRecipeView view in RecipesLayout.Children) @@ -58,7 +55,7 @@ public partial class MyRecipesPage : ContentPage break; } } - notifier.Success("Recipe successfully removed"); + UserNotifier.Success("Recipe successfully removed"); } private void OnBackButtonClicked(object sender, EventArgs e) @@ -69,14 +66,14 @@ public partial class MyRecipesPage : ContentPage { IAccountOwnedRecipes recipes = service.GetRecipesOf(account); - var page = new CreateRecipePage(account.User, notifier, recipe => + var page = new CreateRecipePage(account.User, recipe => { if (!recipes.UploadRecipe(recipe)) { - notifier.Error("Could not upload recipe."); + UserNotifier.Error("Could not upload recipe."); return; } - notifier.Success("Recipe Successfuly uploaded !"); + UserNotifier.Success("Recipe Successfuly uploaded !"); AddRecipeView(recipe.Info); Shell.Current.Navigation.PopAsync(); //go back to current recipe page. }); diff --git a/Views/RecipePage.xaml.cs b/Views/RecipePage.xaml.cs index 33531f3..583fa33 100644 --- a/Views/RecipePage.xaml.cs +++ b/Views/RecipePage.xaml.cs @@ -14,17 +14,15 @@ public partial class RecipePage : ContentPage private IAccountRecipesPreferences preferences; - private IUserNotifier notifier; private RecipeInfo info; public ICommand StarCommand => new Command(count => SetNote(uint.Parse(count))); - public RecipePage(Recipe recipe, IUserNotifier notifier, IAccountRecipesPreferences preferences, uint amount) + public RecipePage(Recipe recipe, IAccountRecipesPreferences preferences, uint amount) { InitializeComponent(); this.preferences = preferences; - this.notifier = notifier; this.info = recipe.Info; RecipeRate rate = preferences.GetRate(recipe.Info); @@ -89,15 +87,15 @@ public partial class RecipePage : ContentPage private void OnSubmitReviewClicked(object o, EventArgs e) { preferences.SetReviewScore(info, note); - notifier.Success("Your review has been successfuly submited"); + UserNotifier.Success("Your review has been successfuly submited"); } private void OnAddToMyListClicked(object o, EventArgs e) { if (!preferences.AddToWeeklyList(info, Counter.Count)) - notifier.Notice("You already added this recipe to you weekly list!"); + UserNotifier.Notice("You already added this recipe to you weekly list!"); else - notifier.Success("Recipe added to your weekly list."); + UserNotifier.Success("Recipe added to your weekly list."); } private void SetFavorite(bool isFavorite) From 563dd0000c6589ae38e6d99cf578058514a0e284 Mon Sep 17 00:00:00 2001 From: Maxime BATISTA Date: Mon, 15 May 2023 11:35:45 +0200 Subject: [PATCH 02/27] pass database from xaml to json --- .../Data/CatastrophicPerformancesDatabase.cs | 21 ++++++++++--------- LocalServices/Data/Database.cs | 2 +- LocalServices/RecipesService.cs | 2 +- Services/IRecipesService.cs | 2 +- Views/FavoritesPage.xaml.cs | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/LocalServices/Data/CatastrophicPerformancesDatabase.cs b/LocalServices/Data/CatastrophicPerformancesDatabase.cs index 32c48c1..0d490a0 100644 --- a/LocalServices/Data/CatastrophicPerformancesDatabase.cs +++ b/LocalServices/Data/CatastrophicPerformancesDatabase.cs @@ -5,6 +5,8 @@ using System.Collections.Immutable; using System.Linq; using System.Runtime.Serialization; using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; namespace LocalEndpoint.Data @@ -62,9 +64,11 @@ namespace LocalEndpoint.Data Save(ACCOUNTS_FILENAME, ACCOUNTS_SERIALIZER, accountsData); } - public Recipe GetRecipe(Guid id) + public Recipe? GetRecipe(Guid id) { - return ConvertRecipeDataToRecipe(recipesData[id]); + if (recipesData.TryGetValue(id, out RecipeData? data)) + return ConvertRecipeDataToRecipe(data); + return null; } public RecipeRate GetRecipeRate(Guid user, Guid recipe) @@ -141,19 +145,16 @@ namespace LocalEndpoint.Data if (fileInfo.Length == 0) return new Dictionary(); //file is empty thus there is nothing to deserialize - Console.WriteLine(File.ReadAllText(file)); - using (var stream = File.OpenRead(file)) - return deserializer.ReadObject(stream) as Dictionary ?? throw new Exception("object read from " + file + " is not a dictionnary"); + string text = File.ReadAllText(file); + + return JsonSerializer.Deserialize>(text); } private void Save(string fileName, DataContractSerializer serializer, Dictionary dict) { - using (var stream = File.OpenWrite(dbPath + "/" + fileName)) - { - serializer.WriteObject(stream, dict); - stream.Flush(); - } + string json = JsonSerializer.Serialize(dict); + File.WriteAllText(dbPath + "/" + fileName, json); } } diff --git a/LocalServices/Data/Database.cs b/LocalServices/Data/Database.cs index 130093a..03f3975 100644 --- a/LocalServices/Data/Database.cs +++ b/LocalServices/Data/Database.cs @@ -9,7 +9,7 @@ namespace LocalEndpoint.Data public interface Database { - public Recipe GetRecipe(Guid id); + public Recipe? GetRecipe(Guid id); public RecipeRate GetRecipeRate(Guid user, Guid recipe); diff --git a/LocalServices/RecipesService.cs b/LocalServices/RecipesService.cs index 8969e9e..f47b19e 100644 --- a/LocalServices/RecipesService.cs +++ b/LocalServices/RecipesService.cs @@ -21,7 +21,7 @@ namespace LocalEndpoint return db.ListAllRecipes().Take(4).ToImmutableList().ConvertAll(v => v.Info); } - public Recipe GetRecipe(RecipeInfo info) + public Recipe? GetRecipe(RecipeInfo info) { return db.GetRecipe(info.Id); } diff --git a/Services/IRecipesService.cs b/Services/IRecipesService.cs index 88e8b65..232da18 100644 --- a/Services/IRecipesService.cs +++ b/Services/IRecipesService.cs @@ -8,7 +8,7 @@ namespace Endpoint { public ImmutableList PopularRecipes(); - public Recipe GetRecipe(RecipeInfo info); + public Recipe? GetRecipe(RecipeInfo info); public IAccountOwnedRecipes GetRecipesOf(Account account); public IAccountRecipesPreferences GetPreferencesOf(Account account); diff --git a/Views/FavoritesPage.xaml.cs b/Views/FavoritesPage.xaml.cs index 20b9ef2..fa9bf2a 100644 --- a/Views/FavoritesPage.xaml.cs +++ b/Views/FavoritesPage.xaml.cs @@ -31,7 +31,7 @@ public partial class FavoritesPage : ContentPage { RecipeViewLayout.Children.Add(new RecipeView(info, () => { - Recipe recipe = service.GetRecipe(info); + Recipe? recipe = service.GetRecipe(info); Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1)); })); }); From 6c61fbe1a46030fc874767a4d9041e0de9dddb06 Mon Sep 17 00:00:00 2001 From: Leo TUAILLON Date: Mon, 15 May 2023 11:46:29 +0200 Subject: [PATCH 03/27] user-notifier --- .editorconfig | 4 ++ ShoopNCook.sln | 7 +++- UserNotifier.cs | 62 ++++++++++++++++------------ Views/Components/NoticePopup.xaml | 3 +- Views/Components/NoticePopup.xaml.cs | 40 +++++++++++++++--- 5 files changed, 81 insertions(+), 35 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a0c05f8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# CS0618: Le type ou le membre est obsolète +dotnet_diagnostic.CS0618.severity = silent diff --git a/ShoopNCook.sln b/ShoopNCook.sln index 3b6c720..17d11be 100644 --- a/ShoopNCook.sln +++ b/ShoopNCook.sln @@ -10,7 +10,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LocalServices", "LocalServices\LocalServices.csproj", "{57732316-93B9-4DA0-A212-F8892D3D968B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Services", "Services\Services.csproj", "{C976BDD8-710D-4162-8A42-973B634491F9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "Services\Services.csproj", "{C976BDD8-710D-4162-8A42-973B634491F9}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6DEA92EF-71CD-4A21-9CC0-67F228E1155D}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/UserNotifier.cs b/UserNotifier.cs index aa97bf2..6846a0d 100644 --- a/UserNotifier.cs +++ b/UserNotifier.cs @@ -1,4 +1,6 @@ -using CommunityToolkit.Maui.Views; +using CommunityToolkit.Maui.Alerts; +using CommunityToolkit.Maui.Core; +using CommunityToolkit.Maui.Views; using ShoopNCook.Views.Components; using System; using System.Collections.Generic; @@ -8,33 +10,39 @@ using System.Threading.Tasks; namespace ShoopNCook { - internal class UserNotifier - { - - private static void Show(NoticePopup popup) - { - var page = Shell.Current.CurrentPage; - page.ShowPopup(new Popup - { - Content = popup - }); + internal class UserNotifier + { + private static async Task Show(string message, string messageType) + { + CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); + + // Vous pouvez configurer la durée et la taille de police ici. + ToastDuration duration = ToastDuration.Short; + double fontSize = 14; + + var toast = Toast.Make(message, duration, fontSize); + + await toast.Show(cancellationTokenSource.Token); } - public static void Error(string message) - { - Show(new NoticePopup()); - } - public static void Warn(string message) - { - Show(new NoticePopup()); - } - public static void Notice(string message) - { - Show(new NoticePopup()); - } - public static void Success(string message) - { - Show(new NoticePopup()); - } + + + public static void Error(string message) + { + Show(message, "Error"); + } + public static void Warn(string message) + { + Show(message, "Warning"); + } + public static void Notice(string message) + { + Show(message, "Notice"); + } + public static void Success(string message) + { + Show(message, "Success"); + } } + } diff --git a/Views/Components/NoticePopup.xaml b/Views/Components/NoticePopup.xaml index ab69bae..d4ac661 100644 --- a/Views/Components/NoticePopup.xaml +++ b/Views/Components/NoticePopup.xaml @@ -1,10 +1,9 @@ - diff --git a/Views/Components/NoticePopup.xaml.cs b/Views/Components/NoticePopup.xaml.cs index 1957bc7..700634a 100644 --- a/Views/Components/NoticePopup.xaml.cs +++ b/Views/Components/NoticePopup.xaml.cs @@ -1,9 +1,39 @@ namespace ShoopNCook.Views.Components; +using Microsoft.Maui.Graphics; public partial class NoticePopup : ContentView { - public NoticePopup() - { - InitializeComponent(); - } -} \ No newline at end of file + 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; + }); + + } +} From 70b1237f2ed3c378678758473110750d02e2764d Mon Sep 17 00:00:00 2001 From: Maxime BATISTA Date: Mon, 22 May 2023 16:12:13 +0200 Subject: [PATCH 04/27] add error notification when a RecipeView is clicked without the recipe being found --- Views/HomePage.xaml.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Views/HomePage.xaml.cs b/Views/HomePage.xaml.cs index b74cfd2..3b46cb2 100644 --- a/Views/HomePage.xaml.cs +++ b/Views/HomePage.xaml.cs @@ -20,8 +20,13 @@ public partial class HomePage : ContentPage { layout.Children.Add(new RecipeView(info, () => { - Recipe recipe = service.GetRecipe(info); - Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1)); + Recipe? recipe = service.GetRecipe(info); + if (recipe != null) + Shell.Current.Navigation.PushAsync(new RecipePage(recipe, notifier, preferences, 1)); + else + { + notifier.Error("Could not find recipe"); + } })); } From be38c9174692b05dddc4ca3020688f25b8ba5dbf Mon Sep 17 00:00:00 2001 From: "maxime.BATISTA@etu.uca.fr" Date: Wed, 24 May 2023 12:06:03 +0200 Subject: [PATCH 05/27] parallelize some events and database mutating actions --- .editorconfig | 4 + Controllers/MorePageController.cs | 8 +- .../Data/CatastrophicPerformancesDatabase.cs | 14 +-- Views/ConfirmMail.xaml | 4 +- Views/CreateRecipePage.xaml.cs | 8 +- Views/FavoritesPage.xaml.cs | 6 +- Views/HomePage.xaml.cs | 86 +++++++++---------- Views/MyListPage.xaml.cs | 2 +- Views/MyRecipesPage.xaml.cs | 6 +- Views/RecipePage.xaml.cs | 10 +-- Views/RegisterPage.xaml.cs | 2 +- 11 files changed, 76 insertions(+), 74 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..cde8b2a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# CS1998: Async method lacks 'await' operators and will run synchronously +dotnet_diagnostic.CS1998.severity = none diff --git a/Controllers/MorePageController.cs b/Controllers/MorePageController.cs index c8ecee8..b71aa18 100644 --- a/Controllers/MorePageController.cs +++ b/Controllers/MorePageController.cs @@ -24,14 +24,14 @@ namespace ShoopNCook.Controllers app.ForceLogin(); } - public void GoToMyRecipesPage() + public async void GoToMyRecipesPage() { - Shell.Current.Navigation.PushAsync(new MyRecipesPage(account, endpoint.RecipesService, app.Notifier)); + await Shell.Current.Navigation.PushAsync(new MyRecipesPage(account, endpoint.RecipesService, app.Notifier)); } - public void GoToProfilePage() + public async void GoToProfilePage() { - Shell.Current.Navigation.PushAsync(new ProfilePage(account)); + await Shell.Current.Navigation.PushAsync(new ProfilePage(account)); } } } diff --git a/LocalServices/Data/CatastrophicPerformancesDatabase.cs b/LocalServices/Data/CatastrophicPerformancesDatabase.cs index 0d490a0..451a424 100644 --- a/LocalServices/Data/CatastrophicPerformancesDatabase.cs +++ b/LocalServices/Data/CatastrophicPerformancesDatabase.cs @@ -76,38 +76,38 @@ namespace LocalEndpoint.Data return usersData[user].Rates[recipe]; } - public void InsertInUserList(Guid userId, Guid recipeId, uint persAmount) + public async void InsertInUserList(Guid userId, Guid recipeId, uint persAmount) { usersData[userId].RecipesList[recipeId] = persAmount; Save(USERS_FILENAME, USERS_SERIALIZER, usersData); } - public void RemoveFromUserList(Guid userId, Guid recipeId) + public async void RemoveFromUserList(Guid userId, Guid recipeId) { usersData[userId].RecipesList.Remove(recipeId); Save(USERS_FILENAME, USERS_SERIALIZER, usersData); } - public void InsertRecipe(Recipe recipe) + public async void InsertRecipe(Recipe recipe) { recipesData[recipe.Info.Id] = new RecipeData(recipe.Info, recipe.Owner.Id, recipe.Ingredients, recipe.Steps); Save(RECIPES_FILENAME, RECIPES_SERIALIZER, recipesData); } - public void InsertUser(User user) + public async void InsertUser(User user) { usersData[user.Id] = new UserData(user, new Dictionary(), new Dictionary()); Save(USERS_FILENAME, USERS_SERIALIZER, usersData); } - public void InsertRate(Guid userId, Guid recipeId, RecipeRate rate) + public async void InsertRate(Guid userId, Guid recipeId, RecipeRate rate) { usersData[userId].Rates[recipeId] = rate; Save(USERS_FILENAME, USERS_SERIALIZER, usersData); } - public void RemoveRecipe(Guid id) + public async void RemoveRecipe(Guid id) { recipesData.Remove(id); Save(RECIPES_FILENAME, RECIPES_SERIALIZER, recipesData); @@ -151,7 +151,7 @@ namespace LocalEndpoint.Data return JsonSerializer.Deserialize>(text); } - private void Save(string fileName, DataContractSerializer serializer, Dictionary dict) + private async void Save(string fileName, DataContractSerializer serializer, Dictionary dict) { string json = JsonSerializer.Serialize(dict); File.WriteAllText(dbPath + "/" + fileName, json); diff --git a/Views/ConfirmMail.xaml b/Views/ConfirmMail.xaml index ae22bca..a4458ea 100644 --- a/Views/ConfirmMail.xaml +++ b/Views/ConfirmMail.xaml @@ -37,11 +37,9 @@ + RowDefinitions="*, Auto, Auto">