From ec36391ec8b6527bc22d45e6a5e3d2fd05861ec2 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Mon, 5 May 2025 23:28:17 +0200 Subject: [PATCH] Dispaly a user message when a recipe is successfully deleted --- README.md | 7 +- backend/src/translation.rs | 159 +---------------------------- backend/translation.ron | 2 + common/src/lib.rs | 1 + common/src/translation.rs | 161 ++++++++++++++++++++++++++++++ frontend/src/pages/recipe_edit.rs | 18 +++- 6 files changed, 182 insertions(+), 166 deletions(-) create mode 100644 common/src/translation.rs diff --git a/README.md b/README.md index 0cabda2..ad828d7 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ * Rust: https://www.rust-lang.org/ * Trunk: https://trunkrs.dev/ -* Nushell: https://www.nushell.sh/ (*nu* need to be in *PATH*) -* Sass: https://sass-lang.com/ (*sass* or *sass.bat* need to be in *PATH*) +* Nushell: https://www.nushell.sh/ (*nu* needs to be in *PATH*) +* Sass: https://sass-lang.com/ (*sass* or *sass.bat* needs to be in *PATH*) # Run in debug mode @@ -13,7 +13,8 @@ Then browse http://127.0.0.1:8082 -At first launch the configuration file `backend/conf.ron` is created. It contains the port the server will listen to and information about the SMTP server which will be used to send email when a user sign up or change its password. +At first launch the configuration file `backend/conf.ron` is created. +It contains the port the server will listen to and information about the SMTP server which will be used to send email when a user sign up or change its password. ## Autoreload diff --git a/backend/src/translation.rs b/backend/src/translation.rs index c9390ee..ebb48e3 100644 --- a/backend/src/translation.rs +++ b/backend/src/translation.rs @@ -1,6 +1,7 @@ use std::{borrow::Borrow, fs::File, sync::LazyLock}; use chrono::Weekday; +pub use common::translation::Sentence; use common::utils; use ron::de::from_reader; use serde::Deserialize; @@ -9,164 +10,6 @@ use tracing::warn; use crate::consts; -#[repr(i64)] -#[derive(Debug, Clone, EnumCount, Deserialize)] -pub enum Sentence { - MainTitle = 0, - CreateNewRecipe, - PrivateRecipes, - UntitledRecipe, - - Name, - EmailAddress, - Password, - - SignOut, - Save, - NotLoggedIn, - - ActionNotAuthorized, - - DatabaseError, - TemplateError, - - // Sign in page. - SignInMenu, - SignInTitle, - SignInButton, - SignInSuccess, - WrongEmailOrPassword, - - // Sign up page. - SignUpMenu, - SignUpTitle, - SignUpButton, - SignUpEmailSent, - SignUpEmailTitle, - SignUpFollowEmailLink, - SignUpEmailValidationSuccess, - SignUpValidationExpired, - SignUpValidationErrorTryAgain, - SignUpClosed, - ChooseAPassword, - ReEnterPassword, - - AccountMustBeValidatedFirst, - InvalidEmail, - PasswordDontMatch, - InvalidPassword, - EmailAlreadyTaken, - UnableToSendEmail, - - // Validation. - ValidationSuccessful, - ValidationExpired, - ValidationErrorTryToSignUpAgain, - ValidationError, - ValidationUserAlreadyExists, - - // Reset password page. - LostPassword, - AskResetChooseNewPassword, - AskResetButton, - AskResetAlreadyLoggedInError, - AskResetEmailAlreadyResetError, - AskResetEmailTitle, - AskResetFollowEmailLink, - AskResetEmailSent, - AskResetTokenMissing, - AskResetTokenExpired, - PasswordReset, - EmailUnknown, - UnableToSendResetEmail, - - // Profile - ProfileTitle, - ProfileEmail, - ProfileDefaultServings, - ProfileFirstDayOfWeek, - ProfileNewPassword, - ProfileFollowEmailTitle, - ProfileFollowEmailLink, - ProfileEmailSent, - ProfileSaved, - - // Recipe. - RecipeNotAllowedToEdit, - RecipeNotAllowedToView, - RecipeNotFound, - RecipeTitle, - RecipeDescription, - RecipeServings, - RecipeEstimatedTime, - RecipeDifficulty, - RecipeDifficultyEasy, - RecipeDifficultyMedium, - RecipeDifficultyHard, - RecipeTags, - RecipeLanguage, - RecipeIsPublic, - RecipeDelete, - RecipeAddAGroup, - RecipeRemoveGroup, - RecipeGroupName, - RecipeGroupComment, - RecipeAddAStep, - RecipeRemoveStep, - RecipeStepAction, - RecipeAddAnIngredient, - RecipeRemoveIngredient, - RecipeIngredientName, - RecipeIngredientQuantity, - RecipeIngredientUnit, - RecipeIngredientComment, - RecipeDeleteConfirmation, - RecipeGroupDeleteConfirmation, - RecipeStepDeleteConfirmation, - RecipeIngredientDeleteConfirmation, - - // View Recipe. - RecipeOneServing, - RecipeSomeServings, - RecipeEstimatedTimeMinAbbreviation, - - // Calendar. - CalendarMonday, - CalendarTuesday, - CalendarWednesday, - CalendarThursday, - CalendarFriday, - CalendarSaturday, - CalendarSunday, - CalendarMondayAbbreviation, - CalendarTuesdayAbbreviation, - CalendarWednesdayAbbreviation, - CalendarThursdayAbbreviation, - CalendarFridayAbbreviation, - CalendarSaturdayAbbreviation, - CalendarSundayAbbreviation, - CalendarJanuary, - CalendarFebruary, - CalendarMarch, - CalendarApril, - CalendarMay, - CalendarJune, - CalendarJuly, - CalendarAugust, - CalendarSeptember, - CalendarOctober, - CalendarNovember, - CalendarDecember, - CalendarAddToPlanner, - CalendarAddToPlannerSuccess, - CalendarAddToPlannerAlreadyExists, - CalendarDateFormat, // See https://docs.rs/chrono/latest/chrono/format/strftime/index.html. - CalendarAddIngredientsToShoppingList, - CalendarRemoveIngredientsFromShoppingList, - CalendarUnschedule, - CalendarUnscheduleConfirmation, -} - pub const DEFAULT_LANGUAGE_CODE: &str = "en"; pub const PLACEHOLDER_SUBSTITUTE: &str = "{}"; diff --git a/backend/translation.ron b/backend/translation.ron index 993cc43..c5210ba 100644 --- a/backend/translation.ron +++ b/backend/translation.ron @@ -107,6 +107,7 @@ (RecipeIngredientUnit, "Unit"), (RecipeIngredientComment, "Comment"), (RecipeDeleteConfirmation, "Are you sure to delete the recipe: '{}'?"), + (RecipeSuccessfullyDeleted, "Recipe successfully deleted"), (RecipeGroupDeleteConfirmation, "Are you sure to delete the group: '{}'?"), (RecipeStepDeleteConfirmation, "Are you sure to delete the step: '{}'?"), (RecipeIngredientDeleteConfirmation, "Are you sure to delete the ingredient: '{}'?"), @@ -259,6 +260,7 @@ (RecipeIngredientUnit, "Unité"), (RecipeIngredientComment, "Commentaire"), (RecipeDeleteConfirmation, "Êtes-vous sûr de vouloir supprimer la recette : '{}' ?"), + (RecipeSuccessfullyDeleted, "Recette supprimée avec succès"), (RecipeGroupDeleteConfirmation, "Êtes-vous sûr de vouloir supprimer le groupe : '{}' ?"), (RecipeStepDeleteConfirmation, "Êtes-vous sûr de vouloir supprimer l'étape : '{}' ?"), (RecipeIngredientDeleteConfirmation, "Êtes-vous sûr de vouloir supprimer 'ingrédient : '{}' ?"), diff --git a/common/src/lib.rs b/common/src/lib.rs index 07b6d84..940d642 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -2,3 +2,4 @@ pub mod consts; pub mod ron_api; pub mod toast; pub mod utils; +pub mod translation; \ No newline at end of file diff --git a/common/src/translation.rs b/common/src/translation.rs new file mode 100644 index 0000000..25a11b8 --- /dev/null +++ b/common/src/translation.rs @@ -0,0 +1,161 @@ +use serde::Deserialize; +use strum::EnumCount; + +#[repr(i64)] +#[derive(Debug, Clone, EnumCount, Deserialize)] +pub enum Sentence { + MainTitle = 0, + CreateNewRecipe, + PrivateRecipes, + UntitledRecipe, + + Name, + EmailAddress, + Password, + + SignOut, + Save, + NotLoggedIn, + + ActionNotAuthorized, + + DatabaseError, + TemplateError, + + // Sign in page. + SignInMenu, + SignInTitle, + SignInButton, + SignInSuccess, + WrongEmailOrPassword, + + // Sign up page. + SignUpMenu, + SignUpTitle, + SignUpButton, + SignUpEmailSent, + SignUpEmailTitle, + SignUpFollowEmailLink, + SignUpEmailValidationSuccess, + SignUpValidationExpired, + SignUpValidationErrorTryAgain, + SignUpClosed, + ChooseAPassword, + ReEnterPassword, + + AccountMustBeValidatedFirst, + InvalidEmail, + PasswordDontMatch, + InvalidPassword, + EmailAlreadyTaken, + UnableToSendEmail, + + // Validation. + ValidationSuccessful, + ValidationExpired, + ValidationErrorTryToSignUpAgain, + ValidationError, + ValidationUserAlreadyExists, + + // Reset password page. + LostPassword, + AskResetChooseNewPassword, + AskResetButton, + AskResetAlreadyLoggedInError, + AskResetEmailAlreadyResetError, + AskResetEmailTitle, + AskResetFollowEmailLink, + AskResetEmailSent, + AskResetTokenMissing, + AskResetTokenExpired, + PasswordReset, + EmailUnknown, + UnableToSendResetEmail, + + // Profile + ProfileTitle, + ProfileEmail, + ProfileDefaultServings, + ProfileFirstDayOfWeek, + ProfileNewPassword, + ProfileFollowEmailTitle, + ProfileFollowEmailLink, + ProfileEmailSent, + ProfileSaved, + + // Recipe. + RecipeNotAllowedToEdit, + RecipeNotAllowedToView, + RecipeNotFound, + RecipeTitle, + RecipeDescription, + RecipeServings, + RecipeEstimatedTime, + RecipeDifficulty, + RecipeDifficultyEasy, + RecipeDifficultyMedium, + RecipeDifficultyHard, + RecipeTags, + RecipeLanguage, + RecipeIsPublic, + RecipeDelete, + RecipeAddAGroup, + RecipeRemoveGroup, + RecipeGroupName, + RecipeGroupComment, + RecipeAddAStep, + RecipeRemoveStep, + RecipeStepAction, + RecipeAddAnIngredient, + RecipeRemoveIngredient, + RecipeIngredientName, + RecipeIngredientQuantity, + RecipeIngredientUnit, + RecipeIngredientComment, + RecipeDeleteConfirmation, + RecipeSuccessfullyDeleted, + RecipeGroupDeleteConfirmation, + RecipeStepDeleteConfirmation, + RecipeIngredientDeleteConfirmation, + + // View Recipe. + RecipeOneServing, + RecipeSomeServings, + RecipeEstimatedTimeMinAbbreviation, + + // Calendar. + CalendarMonday, + CalendarTuesday, + CalendarWednesday, + CalendarThursday, + CalendarFriday, + CalendarSaturday, + CalendarSunday, + CalendarMondayAbbreviation, + CalendarTuesdayAbbreviation, + CalendarWednesdayAbbreviation, + CalendarThursdayAbbreviation, + CalendarFridayAbbreviation, + CalendarSaturdayAbbreviation, + CalendarSundayAbbreviation, + CalendarJanuary, + CalendarFebruary, + CalendarMarch, + CalendarApril, + CalendarMay, + CalendarJune, + CalendarJuly, + CalendarAugust, + CalendarSeptember, + CalendarOctober, + CalendarNovember, + CalendarDecember, + CalendarAddToPlanner, + CalendarAddToPlannerSuccess, + CalendarAddToPlannerAlreadyExists, + CalendarDateFormat, // See https://docs.rs/chrono/latest/chrono/format/strftime/index.html. + CalendarAddIngredientsToShoppingList, + CalendarRemoveIngredientsFromShoppingList, + CalendarUnschedule, + CalendarUnscheduleConfirmation, +} diff --git a/frontend/src/pages/recipe_edit.rs b/frontend/src/pages/recipe_edit.rs index 6ba50bc..623767b 100644 --- a/frontend/src/pages/recipe_edit.rs +++ b/frontend/src/pages/recipe_edit.rs @@ -262,11 +262,19 @@ pub fn setup_page(recipe_id: i64) { .is_some() { let body = ron_api::Id { id: recipe_id }; - let _ = request::delete::<(), _>("recipe", body).await; - window() - .location() - .set_href(&format!("/{}/", get_current_lang())) - .unwrap(); + if let Ok(()) = request::delete::<(), _>("recipe", body).await { + window() + .location() + .set_href(&format!( + "/{}/?{}={}&{}={}", + get_current_lang(), + common::consts::GET_PARAMETER_USER_MESSAGE, + common::translation::Sentence::RecipeSuccessfullyDeleted as i64, + common::consts::GET_PARAMETER_USER_MESSAGE_LEVEL, + common::toast::Level::Success as usize + )) + .unwrap(); + } } }); })