From 995f77d1ef48f19959d9178f6ae5f65327c2c227 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Tue, 18 Mar 2025 20:03:25 +0100 Subject: [PATCH] Doc + formatting --- TODO.md | 8 +++++++- backend/src/config.rs | 20 +++++++++++--------- backend/src/data/db/recipe.rs | 23 +++++++++++------------ backend/src/data/db/user.rs | 1 - common/Cargo.toml | 2 +- frontend/Cargo.toml | 2 +- frontend/src/calendar.rs | 6 +++--- frontend/src/home.rs | 3 +++ frontend/src/shopping_list.rs | 4 ++-- 9 files changed, 39 insertions(+), 30 deletions(-) diff --git a/TODO.md b/TODO.md index 5163115..a4aab03 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,9 @@ +* Finish all local storage API (remove scheduled, add ingredient, etc..) +* Find an elegant/global way to adapt the quantities to servings (e.g. shopping list) * FIX: when the event blur is triggered when changing page, the async process doesn't finish all the time * User can change default_servings in profile +* Add a way to retrieve a backup of the database (only if admin) + * Maybe make a dev-page with logs and other tools/information * Can choose servings number in recipe view * Default number is the user setting user.default_servings * A symbol show the native recipe servings number @@ -7,8 +11,10 @@ * Define the UI (mockups). * Two CSS: one for desktop and one for mobile * Use CSS flex/grid to define a good design/layout +* CSS for dark mode + autodetect * CSS for toast and modal dialog -* Calendar: Choose the first day of the week +* Calendar: Choose the first day of the week +* i18n: prefix uri with the language: /fr/recipe/view/2 * Make a search page Use FTS5: https://sqlite.org/fts5.html diff --git a/backend/src/config.rs b/backend/src/config.rs index 3d2a08d..93e7ebb 100644 --- a/backend/src/config.rs +++ b/backend/src/config.rs @@ -2,7 +2,7 @@ use std::{fmt, fs::File}; use ron::{ de::from_reader, - ser::{to_writer_pretty, PrettyConfig}, + ser::{PrettyConfig, to_writer_pretty}, }; use serde::{Deserialize, Serialize}; @@ -49,7 +49,7 @@ pub fn load() -> Config { ) }), Err(_) => { - let file = File::create(consts::FILE_CONF).unwrap_or_else(|error| { + let mut file = File::create(consts::FILE_CONF).unwrap_or_else(|error| { panic!( "Failed to create default configuration file {}: {}", consts::FILE_CONF, @@ -59,13 +59,15 @@ pub fn load() -> Config { let default_config = Config::default(); - to_writer_pretty(file, &default_config, PrettyConfig::new()).unwrap_or_else(|error| { - panic!( - "Failed to write default configuration file {}: {}", - consts::FILE_CONF, - error - ) - }); + to_writer_pretty(&mut file, &default_config, PrettyConfig::new()).unwrap_or_else( + |error| { + panic!( + "Failed to write default configuration file {}: {}", + consts::FILE_CONF, + error + ) + }, + ); default_config } diff --git a/backend/src/data/db/recipe.rs b/backend/src/data/db/recipe.rs index a6954fe..919162d 100644 --- a/backend/src/data/db/recipe.rs +++ b/backend/src/data/db/recipe.rs @@ -829,15 +829,13 @@ VALUES ($1, $2, $3, $4) { Err(Error::Database(error)) if error.code() == Some(std::borrow::Cow::Borrowed("2067")) - && error.message() == "UNIQUE constraint failed: RecipeScheduled.user_id, RecipeScheduled.recipe_id, RecipeScheduled.date" => + && error.message() + == "UNIQUE constraint failed: RecipeScheduled.user_id, RecipeScheduled.recipe_id, RecipeScheduled.date" => { Ok(AddScheduledRecipeResult::RecipeAlreadyScheduledAtThisDate) } - Err(error) => { - Err(DBError::from(error)) - } + Err(error) => Err(DBError::from(error)), Ok(insert_result) => { - if add_ingredients_to_shopping_list { sqlx::query( r#" @@ -847,13 +845,14 @@ INSERT INTO [ShoppingEntry] ([ingredient_id], [user_id], [recipe_scheduled_id], INNER JOIN [Group] ON [Group].[id] = [Step].[group_id] INNER JOIN [Recipe] ON [Recipe].[id] = [Group].[recipe_id] WHERE [Recipe].[id] = $1 - "#) - .bind(recipe_id) - .bind(user_id) - .bind(insert_result.last_insert_rowid()) - .bind(servings) - .execute(&mut *tx) - .await?; + "#, + ) + .bind(recipe_id) + .bind(user_id) + .bind(insert_result.last_insert_rowid()) + .bind(servings) + .execute(&mut *tx) + .await?; } tx.commit().await?; diff --git a/backend/src/data/db/user.rs b/backend/src/data/db/user.rs index 2935a21..51c71f4 100644 --- a/backend/src/data/db/user.rs +++ b/backend/src/data/db/user.rs @@ -1,4 +1,3 @@ -use axum::Error; use chrono::{Duration, prelude::*}; use rand::distr::{Alphanumeric, SampleString}; use sqlx::Sqlite; diff --git a/common/Cargo.toml b/common/Cargo.toml index 2eb81f8..f590015 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -5,6 +5,6 @@ authors = ["Grégory Burri "] edition = "2024" [dependencies] -ron = "0.8" +ron = "0.8" # Can't upgrade to 0.9 because of https://github.com/ron-rs/ron/issues/561. serde = { version = "1.0", features = ["derive"] } chrono = { version = "0.4", features = ["serde"] } diff --git a/frontend/Cargo.toml b/frontend/Cargo.toml index 533f5dc..db04156 100644 --- a/frontend/Cargo.toml +++ b/frontend/Cargo.toml @@ -15,7 +15,7 @@ common = { path = "../common" } chrono = { version = "0.4", features = ["serde", "unstable-locales"] } -ron = "0.8" +ron = "0.8" # Can't upgrade to 0.9 because of https://github.com/ron-rs/ron/issues/561. serde = { version = "1.0", features = ["derive"] } serde_html_form = "0.2" thiserror = "2" diff --git a/frontend/src/calendar.rs b/frontend/src/calendar.rs index 97a00dc..d50cf43 100644 --- a/frontend/src/calendar.rs +++ b/frontend/src/calendar.rs @@ -1,6 +1,6 @@ use std::{cell::RefCell, rc::Rc}; -use chrono::{offset::Local, Datelike, Days, Months, NaiveDate, Weekday}; +use chrono::{Datelike, Days, Months, NaiveDate, Weekday, offset::Local}; use common::{ron_api, utils::substitute_with_names}; use gloo::{ console::log, @@ -16,7 +16,7 @@ use crate::{ modal_dialog, recipe_scheduler::RecipeScheduler, request, - utils::{by_id, get_locale, selector, selector_all, SelectorExt}, + utils::{SelectorExt, by_id, get_locale, selector, selector_all}, }; struct CalendarStateInternal { @@ -116,7 +116,7 @@ pub fn setup( EventListener::new(&days, "click", move |event| { let target: Element = event.target().unwrap().dyn_into().unwrap(); - log!(event); + // log!(event); // TODO: Remove. if target.class_name() == "number" && options.can_select_date { let first_day = first_grid_day(state_clone.get_displayed_date()); diff --git a/frontend/src/home.rs b/frontend/src/home.rs index 7e1b9b3..986bd9f 100644 --- a/frontend/src/home.rs +++ b/frontend/src/home.rs @@ -61,6 +61,9 @@ pub fn setup_page(is_user_logged: bool) { } EventListener::new( + // TODO: Find the right place to move the item based on: + // 1) recipe id, 2) name, 3) shopping entry id + // Se shopping_list.rs@L30 &item_element.selector(".item-is-checked"), "change", move |event| { diff --git a/frontend/src/shopping_list.rs b/frontend/src/shopping_list.rs index 452c98a..1af9e7d 100644 --- a/frontend/src/shopping_list.rs +++ b/frontend/src/shopping_list.rs @@ -1,7 +1,7 @@ use chrono::{Datelike, Days, Months, NaiveDate}; use common::ron_api; use gloo::storage::{LocalStorage, Storage}; -use ron::ser::{to_string_pretty, PrettyConfig}; +use ron::ser::{PrettyConfig, to_string_pretty}; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -37,7 +37,7 @@ impl ShoppingList { if self.is_local { todo!(); } else { - request::put( + request::patch( "shopping_list/set_checked", ron_api::Value { id: item_id, -- 2.49.0