diff --git a/Cargo.lock b/Cargo.lock index 4e2893b..5984b24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1397,6 +1397,7 @@ dependencies = [ "console_error_panic_hook", "dotenvy", "hex", + "js-sys", "leptos", "leptos_axum", "leptos_meta", diff --git a/Cargo.toml b/Cargo.toml index 22da9e9..a0fd924 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ hex = { version = "0.4", optional = true } dotenvy = { version = "0.15", optional = true } serde = { version = "1", features = ["derive"] } wasm-bindgen = { version = "=0.2.128", optional = true } +js-sys = { version = "0.3", optional = true } web-sys = { version = "0.3", features = ["CloseEvent", "Document", "Location", "MessageEvent", "VisibilityState", "WebSocket", "Window"], optional = true } send_wrapper = { version = "0.6", optional = true } console_error_panic_hook = { version = "0.1", optional = true } @@ -30,6 +31,7 @@ hydrate = [ "leptos/hydrate", "dep:console_error_panic_hook", "dep:wasm-bindgen", + "dep:js-sys", "dep:web-sys", "dep:send_wrapper", ] diff --git a/src/app/mod.rs b/src/app/mod.rs index fcdcb24..9f59920 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -5,6 +5,7 @@ mod live; mod sheets; mod sync; mod tiles; +mod transition; use std::future::Future; @@ -128,8 +129,10 @@ impl Ctx { self.sync.push(self, op); } + /// Moves the item between the list and the basket, with an animation. fn toggle(self, item: &Item) { - self.change(ItemOp::SetChecked { id: item.id, checked: !item.checked }); + let op = ItemOp::SetChecked { id: item.id, checked: !item.checked }; + transition::animate(move || self.change(op)); } } diff --git a/src/app/tiles.rs b/src/app/tiles.rs index 912a186..5e06e57 100644 --- a/src/app/tiles.rs +++ b/src/app/tiles.rs @@ -2,6 +2,7 @@ use leptos::ev; use leptos::prelude::*; use super::icons::IconSvg; +use super::transition; use super::{Ctx, ItemEditor}; use crate::model::{Item, ItemInput, ItemOp, Suggestion}; @@ -44,8 +45,8 @@ pub fn ItemTile(item: Item) -> impl IntoView { open_editor(); }; - let (name, icon, category, badge) = item.with_value(|item| { - (item.name.clone(), item.icon, item.category, item.quantity.map(|q| q.label())) + let (id, name, icon, category, badge) = item.with_value(|item| { + (item.id, item.name.clone(), item.icon, item.category, item.quantity.map(|q| q.label())) }); let aria_label = format!("{name} : mettre dans le panier"); @@ -55,6 +56,7 @@ pub fn ItemTile(item: Item) -> impl IntoView { "tile-shadow relative flex aspect-square touch-manipulation flex-col items-center gap-1 rounded-2xl border-2 border-ink p-2 pb-2.5 text-center select-none active:translate-y-1 active:shadow-none [-webkit-touch-callout:none] {}", category.tile_class(), ) + style:view-transition-name=transition::item_name(id) aria-label=aria_label on:click=on_click on:contextmenu=on_context_menu @@ -85,6 +87,7 @@ 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 }; @@ -94,6 +97,7 @@ pub fn SuggestionTile(suggestion: Suggestion, list_id: i64) -> impl IntoView { view! {