From ca42b85f244ab78d35d5466abca7f3cd695717c7 Mon Sep 17 00:00:00 2001 From: Romulus21 Date: Thu, 5 Nov 2026 22:43:45 +0100 Subject: [PATCH] =?UTF-8?q?Retire=20les=20suggestions=20et=20le=20d=C3=A9c?= =?UTF-8?q?ompte=20sous=20le=20titre=20de=20la=20liste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les tuiles « + Beurre » disparaissent avec leur requête, leur fonction SQL et leurs styles. La ligne « Encore N articles à attraper. » est retirée : le nombre reste affiché dans l'onglet de la liste. Co-Authored-By: Claude Opus 5.5 --- src/api.rs | 11 +-------- src/app/mod.rs | 57 +++---------------------------------------- src/app/tiles.rs | 27 +------------------- src/app/transition.rs | 7 ------ src/db.rs | 45 +--------------------------------- src/model.rs | 8 ------ style/main.css | 15 ------------ 7 files changed, 7 insertions(+), 163 deletions(-) diff --git a/src/api.rs b/src/api.rs index cf7affb..38938d1 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,7 +1,7 @@ use leptos::prelude::*; use leptos::server_fn::codec::Json; -use crate::model::{Account, Item, ItemOp, ListColor, Member, ShoppingList, Suggestion, SyncReport, User}; +use crate::model::{Account, Item, ItemOp, ListColor, Member, ShoppingList, SyncReport, User}; pub const NOT_LOGGED_IN: &str = "Session expirée, reconnecte-toi."; @@ -452,12 +452,3 @@ pub async fn sync_items(ops: Vec) -> Result { notify(users); Ok(SyncReport { created, rejected }) } - -#[server] -pub async fn get_suggestions(list_id: i64) -> Result, ServerFnError> { - use server::*; - let pool = pool()?; - let user = require_user(&pool).await?; - require_list(&pool, &user, list_id).await?; - crate::db::suggestions(&pool, user.id, list_id, 3).await.map_err(db_err) -} diff --git a/src/app/mod.rs b/src/app/mod.rs index 4ea8b60..f7bcf1d 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -16,13 +16,13 @@ use leptos_router::components::{A, Redirect, Route, Router, Routes}; use leptos_router::hooks::use_params_map; use leptos_router::path; -use crate::api::{get_items, get_lists, get_suggestions}; -use crate::model::{Item, ItemOp, ShoppingList, Suggestion, User}; +use crate::api::{get_items, get_lists}; +use crate::model::{Item, ItemOp, ShoppingList, User}; use account::{AccountSheet, Auth, LoginPage, RegisterPage, RequireUser}; use admin::AdminPage; use sheets::{ItemEditor, ItemSheet, ListEditor, ListSheet}; use sync::Sync; -use tiles::{BasketTile, ItemTile, SuggestionTile}; +use tiles::{BasketTile, ItemTile}; pub fn shell(options: LeptosOptions) -> impl IntoView { view! { @@ -186,15 +186,6 @@ fn ListsView(user: User) -> impl IntoView { } }, ); - let suggestions = Resource::new( - move || (active_id.get(), ctx.refresh.get()), - |(id, _)| async move { - match id { - Some(id) => get_suggestions(id).await, - None => Ok(Vec::new()), - } - }, - ); // Items of the open list with unsaved changes, for the add sheet. let list_items = Memo::new(move |_| match (active_id.get(), items.get()) { @@ -242,9 +233,8 @@ fn ListsView(user: User) -> impl IntoView { {move || Suspend::new(async move { let lists = lists.await?; let (items, saved) = items.await?; - let suggestions = suggestions.await?; Ok::<_, ServerFnError>(view! { - + }) })} @@ -263,7 +253,6 @@ fn ListsContent( items: Vec, /// Batches of changes saved when `items` was fetched. saved: u32, - suggestions: Vec, active_id: Option, ) -> impl IntoView { let ctx = expect_context::(); @@ -295,19 +284,6 @@ fn ListsContent( items.sort_by_cached_key(Item::sort_key); items }); - // Hides a suggestion as soon as it is added. - let suggestions = StoredValue::new(suggestions); - let suggestions = Memo::new(move |_| { - current.with(|items| { - suggestions.with_value(|suggestions| { - suggestions - .iter() - .filter(|s| !items.iter().any(|i| i.name.to_lowercase() == s.name.to_lowercase())) - .cloned() - .collect::>() - }) - }) - }); let to_get = Memo::new(move |_| { current.with(|items| { items @@ -371,15 +347,11 @@ fn ListsContent(

} })} -

{move || remaining_text(remaining.get(), total())}

- - -
@@ -493,24 +465,3 @@ fn EmptyState() -> impl IntoView { fn TicketSkeleton() -> impl IntoView { view! {
} } - -fn remaining_text(remaining: usize, total: usize) -> String { - match (remaining, total) { - (_, 0) => "Liste vide : ajoute ton premier article.".to_owned(), - (0, _) => "Tout est dans le panier !".to_owned(), - (1, _) => "Encore 1 article à attraper.".to_owned(), - (n, _) => format!("Encore {n} articles à attraper."), - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn remaining_wording() { - assert_eq!(remaining_text(5, 7), "Encore 5 articles à attraper."); - assert_eq!(remaining_text(1, 2), "Encore 1 article à attraper."); - assert_eq!(remaining_text(0, 2), "Tout est dans le panier !"); - } -} diff --git a/src/app/tiles.rs b/src/app/tiles.rs index 2e8d8a7..60eae65 100644 --- a/src/app/tiles.rs +++ b/src/app/tiles.rs @@ -4,7 +4,7 @@ use leptos::prelude::*; use super::icons::IconSvg; use super::transition; use super::{Ctx, ItemEditor}; -use crate::model::{Item, ItemInput, ItemOp, Suggestion}; +use crate::model::Item; const LONG_PRESS_MS: u64 = 450; @@ -78,31 +78,6 @@ pub fn ItemTile(item: Item) -> impl IntoView { } } -/// Dashed "+ Beurre" tile: one tap adds a frequently bought product. -#[component] -pub fn SuggestionTile(suggestion: Suggestion, list_id: i64) -> impl IntoView { - let ctx = expect_context::(); - let Suggestion { name, icon, category } = suggestion; - let label = format!("+ {name}"); - let transition_name = transition::suggestion_name(&name); - - let add = move |_| { - let input = ItemInput { name: name.clone(), quantity: None, icon, category }; - ctx.change(ItemOp::Add { id: 0, list_id, input }); - }; - - view! { - - } -} - /// Greyed tile in "Déjà dans le panier": tap puts the item back on the list. #[component] pub fn BasketTile(item: Item) -> impl IntoView { diff --git a/src/app/transition.rs b/src/app/transition.rs index 67ed323..5b627d9 100644 --- a/src/app/transition.rs +++ b/src/app/transition.rs @@ -15,13 +15,6 @@ pub fn item_name(id: i64) -> String { format!("item-{id}") } -/// `view-transition-name` of a suggestion tile. Product names may contain -/// spaces or accents, which are not allowed in an identifier: hex-encode them. -pub fn suggestion_name(name: &str) -> String { - let hex: String = name.bytes().map(|b| format!("{b:02x}")).collect(); - format!("suggestion-{hex}") -} - #[cfg(feature = "hydrate")] mod browser { use js_sys::{Function, Promise, Reflect}; diff --git a/src/db.rs b/src/db.rs index 1d87367..4c54cb6 100644 --- a/src/db.rs +++ b/src/db.rs @@ -3,7 +3,7 @@ use sqlx::{Row, SqliteConnection}; use std::str::FromStr; use crate::model::{ - Account, Category, Icon, Item, ItemInput, ItemOp, ListColor, Member, Quantity, ShoppingList, Suggestion, Unit, User, + Account, Category, Icon, Item, ItemInput, ItemOp, ListColor, Member, Quantity, ShoppingList, Unit, User, }; pub async fn connect(url: &str) -> Result { @@ -439,32 +439,6 @@ pub async fn apply_item_ops(pool: &SqlitePool, user_id: i64, ops: &[ItemOp]) -> Ok(created) } -/// The user's most used products not already on the list. -pub async fn suggestions(pool: &SqlitePool, user_id: i64, list_id: i64, limit: i64) -> Result, sqlx::Error> { - sqlx::query( - "SELECT name, icon, category FROM catalog c - WHERE c.user_id = ? AND NOT EXISTS ( - SELECT 1 FROM items i WHERE i.list_id = ? AND i.name = c.name COLLATE NOCASE - ) - ORDER BY use_count DESC, name - LIMIT ?", - ) - .bind(user_id) - .bind(list_id) - .bind(limit) - .fetch_all(pool) - .await? - .iter() - .map(|row| { - Ok(Suggestion { - name: row.try_get("name")?, - icon: decode(Icon::parse(row.try_get("icon")?), "icon")?, - category: decode(Category::parse(row.try_get("category")?), "category")?, - }) - }) - .collect() -} - #[cfg(test)] mod tests { use super::*; @@ -587,23 +561,6 @@ mod tests { assert!(all[0].checked); } - #[tokio::test] - async fn suggestions_skip_items_on_list() { - let pool = pool().await; - let me = user(&pool, "a@x.fr").await; - let list = lists(&pool, me).await.unwrap()[0].id; - add_item(&mut *conn(&pool).await, me, list, &input("beurre")).await.unwrap(); - - let names: Vec<_> = suggestions(&pool, me, list, 3) - .await - .unwrap() - .into_iter() - .map(|s| s.name) - .collect(); - assert!(!names.iter().any(|n| n.eq_ignore_ascii_case("beurre"))); - assert_eq!(names.len(), 3); - } - #[tokio::test] async fn deleting_list_cascades() { let pool = pool().await; diff --git a/src/model.rs b/src/model.rs index a39d3d5..5aa8715 100644 --- a/src/model.rs +++ b/src/model.rs @@ -282,14 +282,6 @@ text_enum!(Icon { Basket => "basket", }); -/// A frequently bought product, offered as a dashed "+ Beurre" tile. -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -pub struct Suggestion { - pub name: String, - pub icon: Icon, - pub category: Category, -} - /// Payload for creating or editing an item. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct ItemInput { diff --git a/style/main.css b/style/main.css index 17ff4a7..95079c9 100644 --- a/style/main.css +++ b/style/main.css @@ -445,21 +445,6 @@ fieldset { line-height: 1rem; } -/* Suggestion : tuile en pointillés. */ -.tile-suggestion { - border-style: dashed; - border-color: var(--ink-35); - color: var(--ink-55); -} - -.tile-suggestion:active { - background: var(--ink-5); -} - -.tile-suggestion svg { - opacity: 0.6; -} - /* Article dans le panier : tuile grise barrée. */ .tile-off { border-color: transparent;