Doc + formatting
authorGreg Burri <greg.burri@gmail.com>
Tue, 18 Mar 2025 19:03:25 +0000 (20:03 +0100)
committerGreg Burri <greg.burri@gmail.com>
Tue, 18 Mar 2025 19:03:25 +0000 (20:03 +0100)
TODO.md
backend/src/config.rs
backend/src/data/db/recipe.rs
backend/src/data/db/user.rs
common/Cargo.toml
frontend/Cargo.toml
frontend/src/calendar.rs
frontend/src/home.rs
frontend/src/shopping_list.rs

diff --git a/TODO.md b/TODO.md
index 5163115..a4aab03 100644 (file)
--- 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
index 3d2a08d..93e7ebb 100644 (file)
@@ -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
         }
index a6954fe..919162d 100644 (file)
@@ -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?;
index 2935a21..51c71f4 100644 (file)
@@ -1,4 +1,3 @@
-use axum::Error;
 use chrono::{Duration, prelude::*};
 use rand::distr::{Alphanumeric, SampleString};
 use sqlx::Sqlite;
index 2eb81f8..f590015 100644 (file)
@@ -5,6 +5,6 @@ authors = ["GrĂ©gory Burri <greg.burri@gmail.com>"]
 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"] }
index 533f5dc..db04156 100644 (file)
@@ -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"
index 97a00dc..d50cf43 100644 (file)
@@ -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());
index 7e1b9b3..986bd9f 100644 (file)
@@ -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| {
index 452c98a..1af9e7d 100644 (file)
@@ -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,