Dispaly a user message when a recipe is successfully deleted

This commit is contained in:
Greg Burri 2025-05-05 23:28:17 +02:00
parent d86c8ab6fe
commit ec36391ec8
6 changed files with 182 additions and 166 deletions

View file

@ -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

View file

@ -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 = "{}";

View file

@ -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 : '{}' ?"),

View file

@ -2,3 +2,4 @@ pub mod consts;
pub mod ron_api;
pub mod toast;
pub mod utils;
pub mod translation;

161
common/src/translation.rs Normal file
View file

@ -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,
}

View file

@ -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();
}
}
});
})