Compare commits
8
Commits
9aa81a22fe
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f83787fbd | ||
|
|
28a1a17802 | ||
|
|
3afb658b40 | ||
|
|
ca42b85f24 | ||
|
|
e47db8b070 | ||
|
|
6b5eaa0ba6 | ||
|
|
444319f9a5 | ||
|
|
a34e86dea6 |
No files matched your search
+2
-2
@@ -22,7 +22,7 @@ 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 }
|
||||
web-sys = { version = "0.3", features = ["CloseEvent", "Document", "Element", "Location", "MessageEvent", "VisibilityState", "WebSocket", "Window"], optional = true }
|
||||
send_wrapper = { version = "0.6", optional = true }
|
||||
console_error_panic_hook = { version = "0.1", optional = true }
|
||||
|
||||
@@ -61,7 +61,7 @@ panic = "abort"
|
||||
output-name = "lisette"
|
||||
site-root = "target/site"
|
||||
site-pkg-dir = "pkg"
|
||||
tailwind-input-file = "style/main.css"
|
||||
style-file = "style/main.css"
|
||||
assets-dir = "public"
|
||||
site-addr = "127.0.0.1:3002"
|
||||
reload-port = 3001
|
||||
|
||||
+1
-10
@@ -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<ItemOp>) -> Result<SyncReport, ServerFnError> {
|
||||
notify(users);
|
||||
Ok(SyncReport { created, rejected })
|
||||
}
|
||||
|
||||
#[server]
|
||||
pub async fn get_suggestions(list_id: i64) -> Result<Vec<Suggestion>, 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)
|
||||
}
|
||||
+20
-20
@@ -83,13 +83,13 @@ fn RedirectIfSignedIn() -> impl IntoView {
|
||||
fn AuthLayout(title: &'static str, children: Children) -> impl IntoView {
|
||||
view! {
|
||||
<RedirectIfSignedIn />
|
||||
<main class="mx-auto flex min-h-dvh max-w-md flex-col px-4 pt-[max(1.5rem,env(safe-area-inset-top))] pb-16">
|
||||
<h1 class="font-display text-5xl leading-[0.9] font-extrabold tracking-tight">
|
||||
<main class="page page-auth">
|
||||
<h1 class="page-title">
|
||||
"mes listes"
|
||||
</h1>
|
||||
<section class="ticket relative mt-8 bg-paper px-5 pt-6 pb-8">
|
||||
<p class="font-mono text-sm tracking-[0.2em] text-ink/60 uppercase">"Lisette · Courses"</p>
|
||||
<h2 class="mt-1 font-display text-[1.7rem] leading-tight font-bold tracking-tight">{title}</h2>
|
||||
<section class="ticket">
|
||||
<p class="eyebrow">"Lisette · Courses"</p>
|
||||
<h2 class="ticket-title">{title}</h2>
|
||||
{children()}
|
||||
</section>
|
||||
</main>
|
||||
@@ -101,7 +101,7 @@ pub fn FormError(#[prop(into)] error: Signal<Option<String>>) -> impl IntoView {
|
||||
move || {
|
||||
error.get().map(|msg| {
|
||||
view! {
|
||||
<p role="alert" class="rounded-xl border-2 border-ink bg-pink px-3 py-2 font-medium">
|
||||
<p role="alert" class="form-error">
|
||||
{msg}
|
||||
</p>
|
||||
}
|
||||
@@ -114,7 +114,7 @@ pub fn LoginPage() -> impl IntoView {
|
||||
let auth = expect_context::<Auth>();
|
||||
view! {
|
||||
<AuthLayout title="Connexion">
|
||||
<ActionForm action=auth.login attr:class="mt-5 flex flex-col gap-4">
|
||||
<ActionForm action=auth.login attr:class="form form-compact">
|
||||
<FormError error=Signal::derive(move || auth.login.value().get().and_then(Result::err).map(error_message)) />
|
||||
<Field label="Email">
|
||||
<input class="field" type="email" name="email" required autocomplete="email" />
|
||||
@@ -135,9 +135,9 @@ pub fn LoginPage() -> impl IntoView {
|
||||
matches!(auth.registration.await, Ok(true))
|
||||
.then(|| {
|
||||
view! {
|
||||
<p class="mt-6 text-center text-ink/70">
|
||||
<p class="footnote">
|
||||
"Pas encore de compte ? "
|
||||
<A href="/inscription" attr:class="font-semibold text-ink underline">
|
||||
<A href="/inscription">
|
||||
"Créer un compte"
|
||||
</A>
|
||||
</p>
|
||||
@@ -158,14 +158,14 @@ pub fn RegisterPage() -> impl IntoView {
|
||||
{move || Suspend::new(async move {
|
||||
if !matches!(auth.registration.await, Ok(true)) {
|
||||
return view! {
|
||||
<p class="mt-4 text-lg text-ink/70">
|
||||
<p class="lead">
|
||||
"Les inscriptions sont fermées pour le moment."
|
||||
</p>
|
||||
}
|
||||
.into_any();
|
||||
}
|
||||
view! {
|
||||
<ActionForm action=auth.register attr:class="mt-5 flex flex-col gap-4">
|
||||
<ActionForm action=auth.register attr:class="form form-compact">
|
||||
<FormError error=Signal::derive(move || auth.register.value().get().and_then(Result::err).map(error_message)) />
|
||||
<Field label="Prénom ou pseudo">
|
||||
<input
|
||||
@@ -196,9 +196,9 @@ pub fn RegisterPage() -> impl IntoView {
|
||||
.into_any()
|
||||
})}
|
||||
</Suspense>
|
||||
<p class="mt-6 text-center text-ink/70">
|
||||
<p class="footnote">
|
||||
"Déjà inscrit·e ? "
|
||||
<A href="/connexion" attr:class="font-semibold text-ink underline">
|
||||
<A href="/connexion">
|
||||
"Se connecter"
|
||||
</A>
|
||||
</p>
|
||||
@@ -209,8 +209,8 @@ pub fn RegisterPage() -> impl IntoView {
|
||||
#[component]
|
||||
pub fn Field(label: &'static str, children: Children) -> impl IntoView {
|
||||
view! {
|
||||
<label class="flex flex-col gap-1.5">
|
||||
<span class="font-mono text-xs tracking-[0.2em] text-ink/60 uppercase">{label}</span>
|
||||
<label class="field-group">
|
||||
<span class="label">{label}</span>
|
||||
{children()}
|
||||
</label>
|
||||
}
|
||||
@@ -221,7 +221,7 @@ fn SubmitButton(#[prop(into)] pending: Signal<bool>, label: &'static str) -> imp
|
||||
view! {
|
||||
<button
|
||||
type="submit"
|
||||
class="tile-shadow mt-2 rounded-2xl border-2 border-ink bg-pink px-4 py-3 font-display text-lg font-bold active:translate-y-1 active:shadow-none disabled:opacity-60"
|
||||
class="button button-primary"
|
||||
disabled=move || pending.get()
|
||||
>
|
||||
{label}
|
||||
@@ -240,23 +240,23 @@ pub fn AccountSheet(user: User) -> impl IntoView {
|
||||
view! {
|
||||
<Show when=move || ctx.account_open.get()>
|
||||
<Sheet title=user.with_value(|u| u.name.clone()) on_close=close>
|
||||
<p class="mt-1 text-ink/70">{user.with_value(|u| u.email.clone())}</p>
|
||||
<p class="sheet-text">{user.with_value(|u| u.email.clone())}</p>
|
||||
{user
|
||||
.with_value(|u| u.is_admin)
|
||||
.then(|| {
|
||||
view! {
|
||||
<A
|
||||
href="/admin"
|
||||
attr:class="mt-6 block w-full rounded-2xl border-2 border-ink bg-lime px-4 py-3 text-center font-semibold"
|
||||
attr:class="button button-lime button-block"
|
||||
>
|
||||
"Gérer les utilisateurs"
|
||||
</A>
|
||||
}
|
||||
})}
|
||||
<ActionForm action=auth.logout attr:class="mt-3">
|
||||
<ActionForm action=auth.logout>
|
||||
<button
|
||||
type="submit"
|
||||
class="w-full rounded-2xl border-2 border-ink px-4 py-3 font-semibold"
|
||||
class="button button-block"
|
||||
>
|
||||
"Se déconnecter"
|
||||
</button>
|
||||
|
||||
+25
-26
@@ -25,8 +25,8 @@ fn AdminView(me: User) -> impl IntoView {
|
||||
if !me.is_admin {
|
||||
return view! {
|
||||
<AdminLayout>
|
||||
<section class="ticket relative mt-6 bg-paper px-5 pt-6 pb-8">
|
||||
<p class="text-lg text-ink/70">"Cette page est réservée aux administrateurs."</p>
|
||||
<section class="ticket">
|
||||
<p class="lead">"Cette page est réservée aux administrateurs."</p>
|
||||
</section>
|
||||
</AdminLayout>
|
||||
}
|
||||
@@ -40,17 +40,17 @@ fn AdminView(me: User) -> impl IntoView {
|
||||
|
||||
view! {
|
||||
<AdminLayout>
|
||||
<section class="ticket relative mt-6 bg-paper px-5 pt-6 pb-8">
|
||||
<p class="font-mono text-sm tracking-[0.2em] text-ink/60 uppercase">"Lisette · Comptes"</p>
|
||||
<h2 class="mt-1 font-display text-[1.7rem] leading-tight font-bold tracking-tight">
|
||||
<section class="ticket">
|
||||
<p class="eyebrow">"Lisette · Comptes"</p>
|
||||
<h2 class="ticket-title">
|
||||
"Utilisateurs"
|
||||
</h2>
|
||||
<Transition fallback=|| view! { <p class="mt-4 text-ink/50">"…"</p> }>
|
||||
<Transition fallback=|| view! { <p class="loading">"…"</p> }>
|
||||
{move || Suspend::new(async move {
|
||||
match accounts.await {
|
||||
Ok(accounts) => view! { <AccountRows accounts me_id editor /> }.into_any(),
|
||||
Err(err) => {
|
||||
view! { <p class="mt-4 font-medium">{error_message(err)}</p> }.into_any()
|
||||
view! { <p class="lead">{error_message(err)}</p> }.into_any()
|
||||
}
|
||||
}
|
||||
})}
|
||||
@@ -58,7 +58,7 @@ fn AdminView(me: User) -> impl IntoView {
|
||||
</section>
|
||||
|
||||
<button
|
||||
class="tile-shadow fixed right-[max(1rem,calc(50vw-14rem+1rem))] bottom-[max(1.25rem,env(safe-area-inset-bottom))] z-10 rounded-2xl border-2 border-ink bg-pink px-6 py-4 font-display text-xl font-bold active:translate-y-1 active:shadow-none"
|
||||
class="fab"
|
||||
on:click=move |_| editor.set(Some(AccountEditor::New))
|
||||
>
|
||||
"+ compte"
|
||||
@@ -86,12 +86,12 @@ fn AdminView(me: User) -> impl IntoView {
|
||||
#[component]
|
||||
fn AdminLayout(children: Children) -> impl IntoView {
|
||||
view! {
|
||||
<main class="mx-auto flex min-h-dvh max-w-md flex-col px-4 pt-[max(1.5rem,env(safe-area-inset-top))] pb-32">
|
||||
<header class="flex items-start justify-between gap-4">
|
||||
<h1 class="font-display text-5xl leading-[0.9] font-extrabold tracking-tight">"admin"</h1>
|
||||
<main class="page">
|
||||
<header class="page-header">
|
||||
<h1 class="page-title">"admin"</h1>
|
||||
<A
|
||||
href="/"
|
||||
attr:class="shrink-0 rounded-2xl border-2 border-ink bg-paper px-4 py-3 font-semibold"
|
||||
attr:class="button button-paper"
|
||||
>
|
||||
"← mes listes"
|
||||
</A>
|
||||
@@ -108,13 +108,13 @@ fn AccountRows(
|
||||
editor: RwSignal<Option<AccountEditor>>,
|
||||
) -> impl IntoView {
|
||||
view! {
|
||||
<p class="mt-1 text-lg text-ink/70">
|
||||
<p class="lead">
|
||||
{match accounts.len() {
|
||||
1 => "1 compte.".to_owned(),
|
||||
n => format!("{n} comptes."),
|
||||
}}
|
||||
</p>
|
||||
<ul class="mt-5 flex flex-col gap-2">
|
||||
<ul class="people">
|
||||
{accounts
|
||||
.into_iter()
|
||||
.map(|Account { user, created_at }| {
|
||||
@@ -123,22 +123,22 @@ fn AccountRows(
|
||||
view! {
|
||||
<li>
|
||||
<button
|
||||
class="flex w-full items-center justify-between gap-3 rounded-xl bg-mist px-3 py-2 text-left active:bg-ink/10"
|
||||
class="person"
|
||||
on:click=move |_| editor.set(Some(AccountEditor::Edit(edited.clone())))
|
||||
>
|
||||
<div class="min-w-0">
|
||||
<p class="truncate font-semibold">
|
||||
<div class="person-info">
|
||||
<p class="person-name">
|
||||
{user.name.clone()}
|
||||
{is_me.then_some(" (toi)")}
|
||||
</p>
|
||||
<p class="truncate text-sm text-ink/60">{user.email.clone()}</p>
|
||||
<p class="text-sm text-ink/50">{format!("Inscrit·e le {}", french_date(&created_at))}</p>
|
||||
<p class="person-email">{user.email.clone()}</p>
|
||||
<p class="person-date">{format!("Inscrit·e le {}", french_date(&created_at))}</p>
|
||||
</div>
|
||||
{user
|
||||
.is_admin
|
||||
.then(|| {
|
||||
view! {
|
||||
<span class="shrink-0 rounded-lg border-2 border-ink bg-lime px-2 py-0.5 font-mono text-xs uppercase">
|
||||
<span class="badge">
|
||||
"admin"
|
||||
</span>
|
||||
}
|
||||
@@ -234,7 +234,7 @@ fn AccountForm(
|
||||
|
||||
view! {
|
||||
<Sheet title=title.to_owned() on_close>
|
||||
<form class="mt-4 flex flex-col gap-4" on:submit=submit>
|
||||
<form class="form form-compact" on:submit=submit>
|
||||
<FormError error=error />
|
||||
<Field label="Prénom ou pseudo">
|
||||
<input class="field" required maxlength="40" autocomplete="off" bind:value=name />
|
||||
@@ -253,23 +253,22 @@ fn AccountForm(
|
||||
bind:value=password
|
||||
/>
|
||||
</Field>
|
||||
<label class="flex items-center gap-3 font-medium">
|
||||
<label class="checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="size-6 accent-ink"
|
||||
disabled=is_me
|
||||
bind:checked=is_admin
|
||||
/>
|
||||
"Administrateur"
|
||||
</label>
|
||||
|
||||
<div class="mt-2 flex gap-3">
|
||||
<div class="actions">
|
||||
{(user_id.is_some() && !is_me)
|
||||
.then(|| {
|
||||
view! {
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-2xl border-2 border-ink px-4 py-3 font-semibold"
|
||||
class="button"
|
||||
disabled=move || pending.get()
|
||||
on:click=delete
|
||||
>
|
||||
@@ -279,7 +278,7 @@ fn AccountForm(
|
||||
})}
|
||||
<button
|
||||
type="submit"
|
||||
class="tile-shadow flex-1 rounded-2xl border-2 border-ink bg-pink px-4 py-3 font-display text-lg font-bold active:translate-y-1 active:shadow-none disabled:opacity-60"
|
||||
class="button button-primary"
|
||||
disabled=move || pending.get()
|
||||
>
|
||||
{if user_id.is_some() { "Enregistrer" } else { "Créer" }}
|
||||
|
||||
+172
-24
@@ -14,32 +14,101 @@ fn paths(icon: Icon) -> &'static [&'static str] {
|
||||
"M4 6.5c1.3-.3 2.2.4 2.4 1.5.7 4.4 4 7.6 8.5 8.1 1.6.2 3.3 0 4.8-.6l.6 1.3c-2.2 1.9-5.1 2.8-8 2.4C7 18.5 3.4 13.8 3.3 8.2c0-.8.3-1.5.7-1.7Z",
|
||||
"M3.4 4.6 5.6 4l.5 2.4-1.9.5Z",
|
||||
],
|
||||
Icon::Lemon => &[
|
||||
"M19.6 6.5c.9-.4 1.1-1.6.4-2.3-.7-.7-1.9-.5-2.3.4-3.4-1.6-8-.4-10.9 2.5S2.6 13.8 4.2 17.2c-.9.4-1.1 1.6-.4 2.3.7.7 1.9.5 2.3-.4 3.4 1.6 8 .4 10.9-2.5s4.2-6.7 2.6-10.1Z",
|
||||
],
|
||||
Icon::Pear => &[
|
||||
"M12 5.5c-1.8 0-3 1.4-3 3.3 0 1.6-.6 2.6-1.6 3.8A5.6 5.6 0 0 0 6 16.3C6 19.5 8.7 22 12 22s6-2.5 6-5.7c0-1.4-.5-2.7-1.4-3.7-1-1.2-1.6-2.2-1.6-3.8 0-1.9-1.2-3.3-3-3.3Z",
|
||||
"M11.4 1.8h1.3l-.1 2.9h-1.2Z",
|
||||
"M13.4 4c.9-1.4 2.5-2 4.1-1.5-.6 1.6-2.3 2.3-4.1 1.5Z",
|
||||
],
|
||||
Icon::Grapes => &[
|
||||
"M5.1 8.5a2.1 2.1 0 1 0 4.2 0 2.1 2.1 0 1 0-4.2 0Z",
|
||||
"M9.9 8.5a2.1 2.1 0 1 0 4.2 0 2.1 2.1 0 1 0-4.2 0Z",
|
||||
"M14.7 8.5a2.1 2.1 0 1 0 4.2 0 2.1 2.1 0 1 0-4.2 0Z",
|
||||
"M7.5 12.7a2.1 2.1 0 1 0 4.2 0 2.1 2.1 0 1 0-4.2 0Z",
|
||||
"M12.3 12.7a2.1 2.1 0 1 0 4.2 0 2.1 2.1 0 1 0-4.2 0Z",
|
||||
"M9.9 16.9a2.1 2.1 0 1 0 4.2 0 2.1 2.1 0 1 0-4.2 0Z",
|
||||
"M11.4 2h1.3v4.1h-1.3Z",
|
||||
"M13.2 5c1-1.7 3-2.5 5-2-.8 1.8-2.8 2.7-5 2Z",
|
||||
],
|
||||
Icon::Strawberry => &[
|
||||
"M5 9.6c0-1 1-1.6 2.6-1.6h8.8c1.6 0 2.6.6 2.6 1.6 0 4.6-3.4 10.6-7 11.9-3.6-1.3-7-7.3-7-11.9Zm4 1.9a.7.7 0 1 0 0-.01Zm6 0a.7.7 0 1 0 0-.01ZM12 13a.7.7 0 1 0 0-.01Zm-2.2 2.8a.7.7 0 1 0 0-.01Zm4.4 0a.7.7 0 1 0 0-.01Z",
|
||||
"M6.8 6.9c1.4-.9 3-1 4.3-.4L12 3.8l.9 2.7c1.3-.6 2.9-.5 4.3.4-1.4.5-3.2.8-5.2.8s-3.8-.3-5.2-.8Z",
|
||||
],
|
||||
Icon::Cherries => &[
|
||||
"M3.9 17a3.6 3.6 0 1 0 7.2 0 3.6 3.6 0 1 0-7.2 0Z",
|
||||
"M12.4 17.4a3.6 3.6 0 1 0 7.2 0 3.6 3.6 0 1 0-7.2 0Z",
|
||||
"M7 13.4c.6-3.6 2.4-7 5.6-9.6l.9 1c-3 2.4-4.6 5.5-5.2 8.8Z",
|
||||
"M13.2 4.4c1.4 2.6 2.4 6 2.7 9.5l-1.3.1c-.3-3.3-1.2-6.5-2.5-8.9Z",
|
||||
"M13.6 4c1.4-1.6 3.8-2.2 6-1.4-1.2 1.9-3.6 2.6-6 1.4Z",
|
||||
],
|
||||
Icon::Avocado => &[
|
||||
"M12 2.5c-2.5 0-3.6 2.4-4.2 5-.5 2-2.3 3.5-2.3 6.5a6.5 6.5 0 0 0 13 0c0-3-1.8-4.5-2.3-6.5-.6-2.6-1.7-5-4.2-5Zm-3 12a3 3 0 1 0 6 0 3 3 0 1 0-6 0Z",
|
||||
],
|
||||
Icon::Tomato => &[
|
||||
"M4.5 14.5a7.5 6.5 0 1 0 15 0 7.5 6.5 0 1 0-15 0Z",
|
||||
"M11.3 2h1.4v3.5h-1.4Z",
|
||||
"M6.5 7c1.8-1.6 3.8-2 5.5-1.2C13.7 5 15.7 5.4 17.5 7c-2 .6-3.9.5-5.5-.2-1.6.7-3.5.8-5.5.2Z",
|
||||
],
|
||||
Icon::Carrot => &[
|
||||
"M14.8 9.2c-1.3-1.3-3.4-1.3-4.7 0L3.3 19.4c-.4.6.3 1.3.9.9l10.2-6.8c1.6-1.1 1.8-3.3.4-4.3Z",
|
||||
"M15.5 8.5c.2-2 1.2-4.2 3-5.3l.8 1.2c-1.2.8-2 2.3-2.3 3.8 1.5-.3 3-1 3.9-2.2l1.1.9c-1.2 1.8-3.8 2.8-6.5 1.6Z",
|
||||
],
|
||||
Icon::Lemon => &[
|
||||
"M19.6 6.5c.9-.4 1.1-1.6.4-2.3-.7-.7-1.9-.5-2.3.4-3.4-1.6-8-.4-10.9 2.5S2.6 13.8 4.2 17.2c-.9.4-1.1 1.6-.4 2.3.7.7 1.9.5 2.3-.4 3.4 1.6 8 .4 10.9-2.5s4.2-6.7 2.6-10.1Z",
|
||||
Icon::Salad => &[
|
||||
"M3.5 20.5c0-9.5 5.3-16.5 17-16.5 0 11.5-7.4 16.5-17 16.5Zm2.6-1.6 9.6-10.6-.9-.8-9.6 10.6Z",
|
||||
],
|
||||
Icon::Glass => &[
|
||||
"M5 3h14l-1.6 16.2A2 2 0 0 1 15.4 21H8.6a2 2 0 0 1-2-1.8Z",
|
||||
Icon::Onion => &[
|
||||
"M12 2.5c.4 2 2 3.3 3.9 4.6 2.3 1.6 4.1 3.6 4.1 6.7 0 4-3.6 6.7-8 6.7s-8-2.7-8-6.7c0-3.1 1.8-5.1 4.1-6.7C10 5.8 11.6 4.5 12 2.5Zm-.9 8.5c-.6 2.8-.6 5.5 0 8h1c-.5-2.5-.5-5.2 0-8Z",
|
||||
"M9.5 21.2h5V22h-5Z",
|
||||
],
|
||||
Icon::Potato => &[
|
||||
"M6.2 6.4C8.7 3.9 13 3.5 16.4 5.2c3.6 1.8 5 5.4 3.8 8.8-1.3 3.7-5 6.4-9.3 6.5-4.4.1-7.6-2.5-7.7-6.2-.1-2.7 1-5.8 3-7.9ZM9 9.2a.9.9 0 1 0 0-.01Zm6.2-.6a.8.8 0 1 0 0-.01Zm-1.8 6.2a.9.9 0 1 0 0-.01ZM8 15a.7.7 0 1 0 0-.01Z",
|
||||
],
|
||||
Icon::Mushroom => &[
|
||||
"M3 12C3 6.8 7 3.5 12 3.5s9 3.3 9 8.5a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1Z",
|
||||
"M9 14.5h6l.8 5.2a1.6 1.6 0 0 1-1.6 1.8H9.8a1.6 1.6 0 0 1-1.6-1.8Z",
|
||||
],
|
||||
Icon::Milk => &[
|
||||
"M8 2h8v3l2 3.5V20a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V8.5L8 5Z",
|
||||
],
|
||||
Icon::Egg => &[
|
||||
"M12 2.5c-3.6 0-7 6.3-7 11.2A7 7 0 0 0 12 21a7 7 0 0 0 7-7.3c0-4.9-3.4-11.2-7-11.2Z",
|
||||
],
|
||||
Icon::Cheese => &[
|
||||
"M2.5 11 14 4.5c2.8.3 5.7 2.5 7.5 6.5v8a1 1 0 0 1-1 1h-17a1 1 0 0 1-1-1Zm6 4a1.5 1.5 0 1 0 0-.01Zm8-1.5a1 1 0 1 0 0-.01Z",
|
||||
],
|
||||
Icon::Yogurt => &[
|
||||
"M4 3h16v2.2H4Z",
|
||||
"M5 6.5h14l-1.5 13a2 2 0 0 1-2 1.8h-7a2 2 0 0 1-2-1.8Z",
|
||||
],
|
||||
Icon::IceCream => &[
|
||||
"M12 2a5 5 0 0 0-4.9 4A3.5 3.5 0 0 0 7.5 13h9a3.5 3.5 0 0 0 .4-7A5 5 0 0 0 12 2Z",
|
||||
"M8 14h8l-3.3 7.4a.8.8 0 0 1-1.4 0Z",
|
||||
],
|
||||
Icon::Cheese => &[
|
||||
"M2.5 11 14 4.5c2.8.3 5.7 2.5 7.5 6.5v8a1 1 0 0 1-1 1h-17a1 1 0 0 1-1-1Zm6 4a1.5 1.5 0 1 0 0-.01Zm8-1.5a1 1 0 1 0 0-.01Z",
|
||||
Icon::Frozen => &[
|
||||
"M11.2 2 12.8 2 12.8 22 11.2 22Z",
|
||||
"M20.26 6.31 21.06 7.69 3.74 17.69 2.94 16.31Z",
|
||||
"M21.06 16.31 20.26 17.69 2.94 7.69 3.74 6.31Z",
|
||||
"M12 5.6 15.4 3 16.2 4.1 12 7.4Z",
|
||||
"M12 7.4 7.8 4.1 8.6 3 12 5.6Z",
|
||||
"M17.54 8.8 21.49 10.44 20.94 11.69 15.98 9.7Z",
|
||||
"M15.98 9.7 16.74 4.41 18.09 4.56 17.54 8.8Z",
|
||||
"M17.54 15.2 18.09 19.44 16.74 19.59 15.98 14.3Z",
|
||||
"M15.98 14.3 20.94 12.31 21.49 13.56 17.54 15.2Z",
|
||||
"M12 18.4 8.6 21 7.8 19.9 12 16.6Z",
|
||||
"M12 16.6 16.2 19.9 15.4 21 12 18.4Z",
|
||||
"M6.46 15.2 2.51 13.56 3.06 12.31 8.02 14.3Z",
|
||||
"M8.02 14.3 7.26 19.59 5.91 19.44 6.46 15.2Z",
|
||||
"M6.46 8.8 5.91 4.56 7.26 4.41 8.02 9.7Z",
|
||||
"M8.02 9.7 3.06 11.69 2.51 10.44 6.46 8.8Z",
|
||||
],
|
||||
Icon::Egg => &[
|
||||
"M12 2.5c-3.6 0-7 6.3-7 11.2A7 7 0 0 0 12 21a7 7 0 0 0 7-7.3c0-4.9-3.4-11.2-7-11.2Z",
|
||||
Icon::Meat => &[
|
||||
"M14.5 3.5c3.6 0 6 2.7 6 6 0 4.4-4.6 8-8.5 8-1.1 0-2 .4-2.6 1.1l-1.7 2a1.8 1.8 0 1 1-2.6-2.4l.3-.3a1.8 1.8 0 1 1 1.1-3.3c.9-.6 1.4-1.6 1.4-2.7 0-4 3-8.4 6.6-8.4Z",
|
||||
],
|
||||
Icon::Coffee => &[
|
||||
"M3 6h13v6a6 6 0 0 1-6 6H9a6 6 0 0 1-6-6Zm13 1.5h1.5a3 3 0 0 1 0 6h-1.8l.3-2h1.5a1 1 0 0 0 0-2H16Z",
|
||||
"M3 20h13v1.8H3Z",
|
||||
Icon::Fish => &[
|
||||
"M2 12c2.5-3.6 6-5.5 9.6-5.5 3.7 0 6.6 2.4 8 5.5-1.4 3.1-4.3 5.5-8 5.5C8 17.5 4.5 15.6 2 12Zm14.5-1.2a1.2 1.2 0 1 0 0 .01Z",
|
||||
"M20.5 12 23 8v8Z",
|
||||
],
|
||||
Icon::Bread => &[
|
||||
"M12 3C6.5 3 3 5.3 3 8.3c0 1.4 1 2.4 2 2.7V19a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-8c1-.3 2-1.3 2-2.7C21 5.3 17.5 3 12 3Z",
|
||||
@@ -49,20 +118,75 @@ fn paths(icon: Icon) -> &'static [&'static str] {
|
||||
"M8.3 6.6 6.8 15H4.5L3 9.6Zm7.4 0 5.3 3-1.5 5.4h-2.3Z",
|
||||
"M2 11.5 4 17H2.5L1 13Zm20 0L23 13l-1.5 4H20Z",
|
||||
],
|
||||
Icon::Cake => &[
|
||||
"M12 1c1 1.2 1.5 2 1.5 2.7a1.5 1.5 0 0 1-3 0c0-.7.5-1.5 1.5-2.7Z",
|
||||
"M11.2 6h1.6v3.2h-1.6Z",
|
||||
"M6 10.5h12a2 2 0 0 1 2 2V15H4v-2.5a2 2 0 0 1 2-2Z",
|
||||
"M4 16.5h16V21H4Z",
|
||||
],
|
||||
Icon::Cookie => &[
|
||||
"M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0Zm5-2.5a1.3 1.3 0 1 0 0-.01Zm6-3a1.1 1.1 0 1 0 0-.01Zm2.5 6a1.3 1.3 0 1 0 0-.01Zm-5.5 3a1.2 1.2 0 1 0 0-.01Zm.5-5a.9.9 0 1 0 0-.01Z",
|
||||
],
|
||||
Icon::Pizza => &[
|
||||
"M3 6c5.8-3 12.2-3 18 0l-9 16Zm1.3 2.2c5.1-2.4 10.3-2.4 15.4 0l.5-.9c-5.4-2.6-11-2.6-16.4 0ZM10 11.2a1.3 1.3 0 1 0 0-.01Zm4.2.4a1.1 1.1 0 1 0 0-.01ZM12 15.5a1.1 1.1 0 1 0 0-.01Z",
|
||||
],
|
||||
Icon::Pasta => &[
|
||||
"M4 10h16v2a8 8 0 0 1-16 0Z",
|
||||
"M7 9c0-3 1.5-6 3-7l1 .6C9.8 4 9 6.4 9 9Zm4 0c0-3 1.5-6 3-7l1 .6c-1.2 1.4-2 3.8-2 6.4Z",
|
||||
],
|
||||
Icon::Meat => &[
|
||||
"M14.5 3.5c3.6 0 6 2.7 6 6 0 4.4-4.6 8-8.5 8-1.1 0-2 .4-2.6 1.1l-1.7 2a1.8 1.8 0 1 1-2.6-2.4l.3-.3a1.8 1.8 0 1 1 1.1-3.3c.9-.6 1.4-1.6 1.4-2.7 0-4 3-8.4 6.6-8.4Z",
|
||||
Icon::Can => &[
|
||||
"M5 5.5C5 4 8.1 3 12 3s7 1 7 2.5v13C19 20 15.9 21 12 21s-7-1-7-2.5Zm0 1.2c1.6 1 4 1.5 7 1.5s5.4-.5 7-1.5V8c-1.6 1-4 1.5-7 1.5S6.6 9 5 8Zm0 9c1.6 1 4 1.5 7 1.5s5.4-.5 7-1.5V17c-1.6 1-4 1.5-7 1.5S6.6 18 5 17Z",
|
||||
],
|
||||
Icon::Fish => &[
|
||||
"M2 12c2.5-3.6 6-5.5 9.6-5.5 3.7 0 6.6 2.4 8 5.5-1.4 3.1-4.3 5.5-8 5.5C8 17.5 4.5 15.6 2 12Zm14.5-1.2a1.2 1.2 0 1 0 0 .01Z",
|
||||
"M20.5 12 23 8v8Z",
|
||||
Icon::Jar => &[
|
||||
"M7 2.5h10v3H7Z",
|
||||
"M7.5 6.5h9L18 9v10a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 6 19V9Zm1 5v5h7v-5Z",
|
||||
],
|
||||
Icon::Chocolate => &[
|
||||
"M6 3h5.3v5.3H5V4a1 1 0 0 1 1-1Z",
|
||||
"M12.7 3H18a1 1 0 0 1 1 1v4.3h-6.3Z",
|
||||
"M5 9.6h6.3v5.3H5Z",
|
||||
"M12.7 9.6H19v5.3h-6.3Z",
|
||||
"M5 16.2h6.3V21H6a1 1 0 0 1-1-1Z",
|
||||
"M12.7 16.2H19V20a1 1 0 0 1-1 1h-5.3Z",
|
||||
],
|
||||
Icon::Candy => &[
|
||||
"M7.5 12a4.5 4.5 0 1 0 9 0 4.5 4.5 0 1 0-9 0Z",
|
||||
"M2 8l5.2 2.4v3.2L2 16Z",
|
||||
"M22 8l-5.2 2.4v3.2L22 16Z",
|
||||
],
|
||||
Icon::Coffee => &[
|
||||
"M3 6h13v6a6 6 0 0 1-6 6H9a6 6 0 0 1-6-6Zm13 1.5h1.5a3 3 0 0 1 0 6h-1.8l.3-2h1.5a1 1 0 0 0 0-2H16Z",
|
||||
"M3 20h13v1.8H3Z",
|
||||
],
|
||||
Icon::Water => &[
|
||||
"M12 2.5C9 7 5.5 10.7 5.5 14.5a6.5 6.5 0 0 0 13 0C18.5 10.7 15 7 12 2.5Z",
|
||||
],
|
||||
Icon::Glass => &[
|
||||
"M5 3h14l-1.6 16.2A2 2 0 0 1 15.4 21H8.6a2 2 0 0 1-2-1.8Z",
|
||||
],
|
||||
Icon::Bottle => &[
|
||||
"M10 2h4v4.5c2 1 3 2.7 3 4.8V20a2 2 0 0 1-2 2H9a2 2 0 0 1-2-2v-8.7c0-2.1 1-3.8 3-4.8Z",
|
||||
],
|
||||
Icon::Wine => &[
|
||||
"M6.5 2h11l.4 4.5c.5 3.6-2 6.6-5.2 7V19H16v2H8v-2h3.3v-5.5c-3.2-.4-5.7-3.4-5.2-7Z",
|
||||
],
|
||||
Icon::Spray => &[
|
||||
"M7.5 3h8.5l3 2v2h-3v1.2H8Z",
|
||||
"M15.3 8.8l2.7 3-1 .8-2.5-2.7Z",
|
||||
"M8 9.5h6.5l1 2.5V20a1.5 1.5 0 0 1-1.5 1.5H8.5A1.5 1.5 0 0 1 7 20v-8Z",
|
||||
],
|
||||
Icon::BabyBottle => &[
|
||||
"M10.5 5c0-1.5.6-3 1.5-3s1.5 1.5 1.5 3Z",
|
||||
"M8.5 6h7v2.5h-7Z",
|
||||
"M9 9.5h6l.5 1.5v9a1.5 1.5 0 0 1-1.5 1.5h-4A1.5 1.5 0 0 1 8.5 20v-9Zm-.5 3.5h3v.9h-3Zm0 3h3v.9h-3Z",
|
||||
],
|
||||
Icon::Paw => &[
|
||||
"M12 11.5c-2.6 0-5.5 3.2-5.5 6 0 1.8 1.3 3 3 3 1 0 1.6-.4 2.5-.4s1.5.4 2.5.4c1.7 0 3-1.2 3-3 0-2.8-2.9-6-5.5-6Z",
|
||||
"M3.2 10.5a1.8 2.3 0 1 0 3.6 0 1.8 2.3 0 1 0-3.6 0Z",
|
||||
"M7.1 6.2a1.9 2.5 0 1 0 3.8 0 1.9 2.5 0 1 0-3.8 0Z",
|
||||
"M13.1 6.2a1.9 2.5 0 1 0 3.8 0 1.9 2.5 0 1 0-3.8 0Z",
|
||||
"M17.2 10.5a1.8 2.3 0 1 0 3.6 0 1.8 2.3 0 1 0-3.6 0Z",
|
||||
],
|
||||
Icon::Basket => &[
|
||||
"M7.6 9 11 3.4l1.3.8L9.3 9h5.4l-3-4.8 1.3-.8L16.4 9H22l-2 10.5a2 2 0 0 1-2 1.5H6a2 2 0 0 1-2-1.5L2 9Z",
|
||||
],
|
||||
@@ -73,20 +197,44 @@ pub fn icon_label(icon: Icon) -> &'static str {
|
||||
match icon {
|
||||
Icon::Apple => "Pomme",
|
||||
Icon::Banana => "Banane",
|
||||
Icon::Carrot => "Carotte",
|
||||
Icon::Lemon => "Citron",
|
||||
Icon::Glass => "Verre",
|
||||
Icon::Pear => "Poire",
|
||||
Icon::Grapes => "Raisin",
|
||||
Icon::Strawberry => "Fraise",
|
||||
Icon::Cherries => "Cerises",
|
||||
Icon::Avocado => "Avocat",
|
||||
Icon::Tomato => "Tomate",
|
||||
Icon::Carrot => "Carotte",
|
||||
Icon::Salad => "Salade",
|
||||
Icon::Onion => "Oignon",
|
||||
Icon::Potato => "Pomme de terre",
|
||||
Icon::Mushroom => "Champignon",
|
||||
Icon::Milk => "Brique de lait",
|
||||
Icon::IceCream => "Glace",
|
||||
Icon::Cheese => "Fromage",
|
||||
Icon::Egg => "Œuf",
|
||||
Icon::Coffee => "Café",
|
||||
Icon::Bread => "Pain",
|
||||
Icon::Croissant => "Viennoiserie",
|
||||
Icon::Pasta => "Pâtes",
|
||||
Icon::Cheese => "Fromage",
|
||||
Icon::Yogurt => "Yaourt",
|
||||
Icon::IceCream => "Glace",
|
||||
Icon::Frozen => "Surgelés",
|
||||
Icon::Meat => "Viande",
|
||||
Icon::Fish => "Poisson",
|
||||
Icon::Bread => "Pain",
|
||||
Icon::Croissant => "Viennoiserie",
|
||||
Icon::Cake => "Gâteau",
|
||||
Icon::Cookie => "Biscuit",
|
||||
Icon::Pizza => "Pizza",
|
||||
Icon::Pasta => "Pâtes",
|
||||
Icon::Can => "Conserve",
|
||||
Icon::Jar => "Bocal",
|
||||
Icon::Chocolate => "Chocolat",
|
||||
Icon::Candy => "Bonbon",
|
||||
Icon::Coffee => "Café",
|
||||
Icon::Water => "Eau",
|
||||
Icon::Glass => "Verre",
|
||||
Icon::Bottle => "Bouteille",
|
||||
Icon::Wine => "Vin",
|
||||
Icon::Spray => "Produit ménager",
|
||||
Icon::BabyBottle => "Bébé",
|
||||
Icon::Paw => "Animaux",
|
||||
Icon::Basket => "Panier",
|
||||
}
|
||||
}
|
||||
|
||||
+57
-124
@@ -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! {
|
||||
@@ -41,7 +41,7 @@ pub fn shell(options: LeptosOptions) -> impl IntoView {
|
||||
"if ('serviceWorker' in navigator) navigator.serviceWorker.register('/sw.js');"
|
||||
</script>
|
||||
</head>
|
||||
<body class="bg-lime text-ink font-sans antialiased">
|
||||
<body>
|
||||
<App />
|
||||
</body>
|
||||
</html>
|
||||
@@ -71,7 +71,7 @@ pub fn App() -> impl IntoView {
|
||||
<Title text="Lisette" />
|
||||
|
||||
<Router>
|
||||
<Routes fallback=|| view! { <p class="p-4">"Page introuvable."</p> }>
|
||||
<Routes fallback=|| view! { <p class="page-not-found">"Page introuvable."</p> }>
|
||||
<Route path=path!("/") view=ListsPage />
|
||||
<Route path=path!("/l/:id") view=ListsPage />
|
||||
<Route path=path!("/connexion") view=LoginPage />
|
||||
@@ -186,24 +186,25 @@ 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()) {
|
||||
(Some(id), Some(Ok((items, _)))) => {
|
||||
let mut items = ctx.sync.apply(id, &items);
|
||||
items.sort_by_cached_key(|item| crate::model::fold_name(&item.name));
|
||||
items
|
||||
}
|
||||
},
|
||||
);
|
||||
_ => Vec::new(),
|
||||
});
|
||||
|
||||
view! {
|
||||
<main class="mx-auto flex min-h-dvh max-w-md flex-col px-4 pt-[max(1.5rem,env(safe-area-inset-top))] pb-32">
|
||||
<header class="flex items-start justify-between gap-4">
|
||||
<h1 class="font-display text-5xl leading-[0.9] font-extrabold tracking-tight">
|
||||
<main class="page">
|
||||
<header class="page-header">
|
||||
<h1 class="page-title">
|
||||
"mes listes"
|
||||
</h1>
|
||||
<button
|
||||
class="grid size-14 shrink-0 place-items-center rounded-2xl bg-ink font-display text-lg font-bold text-lime"
|
||||
class="avatar"
|
||||
aria-label="Mon compte"
|
||||
on:click=move |_| ctx.account_open.set(true)
|
||||
>
|
||||
@@ -213,7 +214,7 @@ fn ListsView(user: User) -> impl IntoView {
|
||||
|
||||
<ErrorBanner />
|
||||
<Show when=move || ctx.sync.offline()>
|
||||
<p class="mt-4 rounded-2xl bg-paper/70 px-4 py-3 font-medium text-ink/70">
|
||||
<p class="notice">
|
||||
"Réseau indisponible : tes changements partiront dès que possible."
|
||||
</p>
|
||||
</Show>
|
||||
@@ -221,7 +222,7 @@ fn ListsView(user: User) -> impl IntoView {
|
||||
<Transition fallback=|| view! { <TicketSkeleton /> }>
|
||||
<ErrorBoundary fallback=|errors| {
|
||||
view! {
|
||||
<p class="mt-6 rounded-2xl bg-paper p-4">
|
||||
<p class="panel">
|
||||
"Oups : "
|
||||
{move || {
|
||||
errors.get().into_iter().map(|(_, e)| e.to_string()).collect::<Vec<_>>().join(", ")
|
||||
@@ -232,16 +233,15 @@ 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! {
|
||||
<ListsContent lists items saved suggestions active_id=active_id.get() />
|
||||
<ListsContent lists items saved active_id=active_id.get() />
|
||||
})
|
||||
})}
|
||||
</ErrorBoundary>
|
||||
</Transition>
|
||||
</main>
|
||||
|
||||
<ItemSheet list_id=active_id />
|
||||
<ItemSheet list_id=active_id items=list_items />
|
||||
<ListSheet />
|
||||
<AccountSheet user />
|
||||
}
|
||||
@@ -253,7 +253,6 @@ fn ListsContent(
|
||||
items: Vec<Item>,
|
||||
/// Batches of changes saved when `items` was fetched.
|
||||
saved: u32,
|
||||
suggestions: Vec<Suggestion>,
|
||||
active_id: Option<i64>,
|
||||
) -> impl IntoView {
|
||||
let ctx = expect_context::<Ctx>();
|
||||
@@ -271,7 +270,7 @@ fn ListsContent(
|
||||
let Some(list) = lists.iter().find(|l| l.id == active_id).cloned() else {
|
||||
return view! {
|
||||
<ListTabs lists active=None remaining=0 />
|
||||
<p class="mt-6 rounded-2xl bg-paper p-4">"Cette liste n'existe plus."</p>
|
||||
<p class="panel">"Cette liste n'existe plus."</p>
|
||||
}
|
||||
.into_any();
|
||||
};
|
||||
@@ -285,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::<Vec<_>>()
|
||||
})
|
||||
})
|
||||
});
|
||||
let to_get = Memo::new(move |_| {
|
||||
current.with(|items| {
|
||||
items
|
||||
@@ -319,60 +305,62 @@ fn ListsContent(
|
||||
let total = move || current.with(Vec::len);
|
||||
let remaining = Signal::derive(move || to_get.with(Vec::len));
|
||||
|
||||
// The page takes the color of the open list.
|
||||
let color = list.color;
|
||||
Effect::new(move |_| {
|
||||
if let Ok(Some(meta)) = document().query_selector("meta[name=theme-color]") {
|
||||
_ = meta.set_attribute("content", color.hex());
|
||||
}
|
||||
});
|
||||
|
||||
let edit_list = {
|
||||
let list = list.clone();
|
||||
move |_| ctx.list_editor.set(Some(ListEditor::Edit(list.clone())))
|
||||
};
|
||||
|
||||
view! {
|
||||
<div class=format!("page-bg {}", color.dot_class()) aria-hidden="true"></div>
|
||||
<ListTabs lists active=Some(active_id) remaining />
|
||||
|
||||
<section class="ticket relative mt-6 bg-paper px-5 pt-6 pb-8">
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<p class="font-mono text-sm tracking-[0.2em] text-ink/60 uppercase">
|
||||
{format!("Ticket N°{:03} · {}", list.id, ticket_date(&list.created_at))}
|
||||
</p>
|
||||
<section class="ticket">
|
||||
<div class="ticket-head">
|
||||
<h2 class="ticket-title">
|
||||
{list.name.clone()}
|
||||
</h2>
|
||||
<button
|
||||
class="-mt-2 -mr-2 grid size-11 place-items-center rounded-full text-ink/60 active:bg-ink/5"
|
||||
class="icon-button"
|
||||
aria-label="Modifier la liste"
|
||||
on:click=edit_list
|
||||
>
|
||||
<svg viewBox="0 0 24 24" fill="currentColor" class="size-6" aria-hidden="true">
|
||||
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
||||
<circle cx="5" cy="12" r="2" />
|
||||
<circle cx="12" cy="12" r="2" />
|
||||
<circle cx="19" cy="12" r="2" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<h2 class="mt-1 font-display text-[1.7rem] leading-tight font-bold tracking-tight">
|
||||
{list.name.clone()}
|
||||
</h2>
|
||||
{(!list.is_owner)
|
||||
.then(|| {
|
||||
view! {
|
||||
<p class="mt-1 font-medium text-ink/60">
|
||||
<p class="ticket-owner">
|
||||
{format!("Partagée par {}", list.owner_name)}
|
||||
</p>
|
||||
}
|
||||
})}
|
||||
<p class="mt-1 text-lg text-ink/70">{move || remaining_text(remaining.get(), total())}</p>
|
||||
|
||||
<div class="mt-5 grid grid-cols-3 gap-3">
|
||||
<div class="tiles">
|
||||
<For each=move || to_get.get() key=|item| (item.id, item.quantity.map(|q| q.label()), item.name.clone(), item.icon, item.category) let:item>
|
||||
<ItemTile item />
|
||||
</For>
|
||||
<For each=move || suggestions.get() key=|suggestion| suggestion.name.clone() let:suggestion>
|
||||
<SuggestionTile suggestion list_id=active_id />
|
||||
</For>
|
||||
</div>
|
||||
|
||||
<Show when=move || !in_basket.with(Vec::is_empty)>
|
||||
<div class="mt-6 border-t-2 border-dashed border-ink/15 pt-5">
|
||||
<div class="flex justify-between font-mono text-sm tracking-[0.2em] text-ink/60 uppercase">
|
||||
<div class="basket">
|
||||
<div class="basket-head">
|
||||
<span>"Déjà dans le panier"</span>
|
||||
<span>{move || format!("{}/{}", in_basket.with(Vec::len), total())}</span>
|
||||
</div>
|
||||
<div class="mt-4 grid grid-cols-4 gap-2">
|
||||
<div class="tiles">
|
||||
<For each=move || in_basket.get() key=|item| (item.id, item.name.clone(), item.icon) let:item>
|
||||
<BasketTile item />
|
||||
</For>
|
||||
@@ -382,10 +370,10 @@ fn ListsContent(
|
||||
</section>
|
||||
|
||||
<button
|
||||
class="tile-shadow fixed right-[max(1rem,calc(50vw-14rem+1rem))] bottom-[max(1.25rem,env(safe-area-inset-bottom))] z-10 rounded-2xl border-2 border-ink bg-pink px-6 py-4 font-display text-xl font-bold active:translate-y-1 active:shadow-none"
|
||||
class="fab"
|
||||
on:click=move |_| ctx.item_editor.set(Some(ItemEditor::New))
|
||||
>
|
||||
"+ article"
|
||||
"ajouter"
|
||||
</button>
|
||||
}
|
||||
.into_any()
|
||||
@@ -399,30 +387,21 @@ fn ListTabs(
|
||||
) -> impl IntoView {
|
||||
let ctx = expect_context::<Ctx>();
|
||||
view! {
|
||||
<nav class="-mx-4 mt-5 flex gap-3 overflow-x-auto px-4 pb-1 [scrollbar-width:none]">
|
||||
<nav class="tabs">
|
||||
{lists
|
||||
.into_iter()
|
||||
.map(|list| {
|
||||
let is_active = active == Some(list.id);
|
||||
let class = if is_active {
|
||||
"border-ink bg-ink text-paper"
|
||||
} else {
|
||||
"border-ink bg-paper"
|
||||
};
|
||||
let class = if is_active { "tab tab-active" } else { "tab" };
|
||||
view! {
|
||||
<A
|
||||
href=format!("/l/{}", list.id)
|
||||
attr:class=format!(
|
||||
"flex shrink-0 items-center gap-2 rounded-2xl border-2 px-5 py-3 text-lg font-semibold whitespace-nowrap {class}",
|
||||
)
|
||||
attr:class=class
|
||||
>
|
||||
{(!is_active)
|
||||
.then(|| {
|
||||
view! {
|
||||
<span class=format!(
|
||||
"size-4 rounded-full border-2 border-ink {}",
|
||||
list.color.dot_class(),
|
||||
) />
|
||||
<span class=format!("dot {}", list.color.dot_class()) />
|
||||
}
|
||||
})}
|
||||
{list.name.clone()}
|
||||
@@ -432,7 +411,7 @@ fn ListTabs(
|
||||
})
|
||||
.collect_view()}
|
||||
<button
|
||||
class="shrink-0 rounded-2xl border-2 border-dashed border-ink/50 px-5 py-3 text-lg font-semibold text-ink/70"
|
||||
class="tab tab-new"
|
||||
aria-label="Nouvelle liste"
|
||||
on:click=move |_| ctx.list_editor.set(Some(ListEditor::New))
|
||||
>
|
||||
@@ -453,10 +432,10 @@ fn ErrorBanner() -> impl IntoView {
|
||||
view! {
|
||||
<div
|
||||
role="alert"
|
||||
class="mt-4 flex items-center justify-between gap-3 rounded-2xl border-2 border-ink bg-pink px-4 py-3 font-medium"
|
||||
class="alert"
|
||||
>
|
||||
<span>{msg}</span>
|
||||
<button class="font-bold" on:click=move |_| ctx.error.set(None)>
|
||||
<button on:click=move |_| ctx.error.set(None)>
|
||||
"OK"
|
||||
</button>
|
||||
</div>
|
||||
@@ -470,10 +449,10 @@ fn ErrorBanner() -> impl IntoView {
|
||||
fn EmptyState() -> impl IntoView {
|
||||
let ctx = expect_context::<Ctx>();
|
||||
view! {
|
||||
<section class="ticket relative mt-6 bg-paper px-5 pt-6 pb-8 text-center">
|
||||
<p class="text-lg text-ink/70">"Aucune liste pour l'instant."</p>
|
||||
<section class="ticket ticket-empty">
|
||||
<p class="lead">"Aucune liste pour l'instant."</p>
|
||||
<button
|
||||
class="tile-shadow mt-4 rounded-2xl border-2 border-ink bg-pink px-5 py-3 font-display font-bold"
|
||||
class="button button-primary"
|
||||
on:click=move |_| ctx.list_editor.set(Some(ListEditor::New))
|
||||
>
|
||||
"Créer une liste"
|
||||
@@ -484,51 +463,5 @@ fn EmptyState() -> impl IntoView {
|
||||
|
||||
#[component]
|
||||
fn TicketSkeleton() -> impl IntoView {
|
||||
view! { <div class="ticket mt-20 h-96 animate-pulse bg-paper/60"></div> }
|
||||
}
|
||||
|
||||
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."),
|
||||
}
|
||||
}
|
||||
|
||||
/// "2026-10-07" → "mer. 07/10" (upper-cased by CSS).
|
||||
fn ticket_date(iso: &str) -> String {
|
||||
const DAYS: [&str; 7] = ["dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam."];
|
||||
const OFFSETS: [i32; 12] = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];
|
||||
|
||||
let mut parts = iso.split('-').map(|p| p.parse::<i32>().ok());
|
||||
let (Some(Some(y)), Some(Some(m @ 1..=12)), Some(Some(d))) =
|
||||
(parts.next(), parts.next(), parts.next())
|
||||
else {
|
||||
return String::new();
|
||||
};
|
||||
// Sakamoto's algorithm, 0 = Sunday.
|
||||
let y_adj = if m < 3 { y - 1 } else { y };
|
||||
let weekday =
|
||||
(y_adj + y_adj / 4 - y_adj / 100 + y_adj / 400 + OFFSETS[(m - 1) as usize] + d) % 7;
|
||||
format!("{} {d:02}/{m:02}", DAYS[weekday as usize])
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn formats_ticket_date() {
|
||||
assert_eq!(ticket_date("2026-10-07"), "mer. 07/10");
|
||||
assert_eq!(ticket_date("2024-02-29"), "jeu. 29/02");
|
||||
assert_eq!(ticket_date("garbage"), "");
|
||||
}
|
||||
|
||||
#[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 !");
|
||||
}
|
||||
view! { <div class="ticket ticket-skeleton"></div> }
|
||||
}
|
||||
+208
-104
@@ -5,7 +5,7 @@ use leptos_router::hooks::use_navigate;
|
||||
use super::Ctx;
|
||||
use super::icons::{IconSvg, icon_label};
|
||||
use crate::api::get_members;
|
||||
use crate::model::{Category, Icon, Item, ItemInput, ItemOp, ListColor, Quantity, ShoppingList, Unit};
|
||||
use crate::model::{Category, Icon, Item, ItemInput, ItemOp, ListColor, Quantity, ShoppingList, Unit, fold_name};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum ItemEditor {
|
||||
@@ -30,11 +30,11 @@ pub fn Sheet(title: String, on_close: impl Fn() + Copy + Send + Sync + 'static,
|
||||
on_cleanup(move || handle.remove());
|
||||
|
||||
view! {
|
||||
<div class="fixed inset-0 z-20 flex items-end justify-center" role="dialog" aria-modal="true">
|
||||
<div class="absolute inset-0 bg-ink/50" on:click=move |_| on_close()></div>
|
||||
<div class="relative max-h-[90dvh] w-full max-w-md overflow-y-auto rounded-t-3xl border-2 border-b-0 border-ink bg-paper px-5 pt-3 pb-[max(1.5rem,env(safe-area-inset-bottom))]">
|
||||
<div class="mx-auto mb-4 h-1.5 w-12 rounded-full bg-ink/20"></div>
|
||||
<h2 class="font-display text-2xl font-bold">{title}</h2>
|
||||
<div class="sheet" role="dialog" aria-modal="true">
|
||||
<div class="sheet-backdrop" on:click=move |_| on_close()></div>
|
||||
<div class="sheet-panel">
|
||||
<div class="sheet-handle"></div>
|
||||
<h2 class="sheet-title">{title}</h2>
|
||||
{children()}
|
||||
</div>
|
||||
</div>
|
||||
@@ -42,36 +42,174 @@ pub fn Sheet(title: String, on_close: impl Fn() + Copy + Send + Sync + 'static,
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn ItemSheet(#[prop(into)] list_id: Signal<Option<i64>>) -> impl IntoView {
|
||||
pub fn ItemSheet(
|
||||
#[prop(into)] list_id: Signal<Option<i64>>,
|
||||
/// Items of the open list, searched by the add sheet.
|
||||
items: Memo<Vec<Item>>,
|
||||
) -> impl IntoView {
|
||||
let ctx = expect_context::<Ctx>();
|
||||
move || {
|
||||
let editor = ctx.item_editor.get()?;
|
||||
let list_id = list_id.get()?;
|
||||
Some(view! { <ItemForm editor list_id /> })
|
||||
Some(match editor {
|
||||
ItemEditor::New => view! { <AddForm list_id items /> }.into_any(),
|
||||
ItemEditor::Edit(item) => view! { <ItemForm item /> }.into_any(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Search box over the list: a match is tapped to put it on the list or in
|
||||
/// the basket, and an unknown name is added.
|
||||
#[component]
|
||||
fn AddForm(list_id: i64, items: Memo<Vec<Item>>) -> impl IntoView {
|
||||
let ctx = expect_context::<Ctx>();
|
||||
let close = move || ctx.item_editor.set(None);
|
||||
let query = RwSignal::new(String::new());
|
||||
let input = NodeRef::<leptos::html::Input>::new();
|
||||
let refocus = move || {
|
||||
query.set(String::new());
|
||||
if let Some(input) = input.get_untracked() {
|
||||
_ = input.focus();
|
||||
}
|
||||
};
|
||||
// `autofocus` is ignored on elements added after page load.
|
||||
Effect::new(move |_| {
|
||||
if let Some(input) = input.get() {
|
||||
_ = input.focus();
|
||||
}
|
||||
});
|
||||
|
||||
let needle = Memo::new(move |_| fold_name(query.read().trim()));
|
||||
let matches = Memo::new(move |_| {
|
||||
let needle = needle.get();
|
||||
if needle.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
items.with(|items| {
|
||||
items
|
||||
.iter()
|
||||
.filter(|item| fold_name(&item.name).contains(&needle))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
});
|
||||
let exact = move || {
|
||||
let needle = needle.get();
|
||||
matches.with(|items| items.iter().find(|item| fold_name(&item.name) == needle).cloned())
|
||||
};
|
||||
let can_add = move || !needle.with(String::is_empty) && exact().is_none();
|
||||
|
||||
let submit = move |ev: ev::SubmitEvent| {
|
||||
ev.prevent_default();
|
||||
match exact() {
|
||||
// Enter on a name already in the basket puts it back on the list.
|
||||
Some(item) => {
|
||||
if item.checked {
|
||||
ctx.change(ItemOp::SetChecked { id: item.id, checked: false });
|
||||
}
|
||||
}
|
||||
None if can_add() => {
|
||||
let input = ItemInput {
|
||||
name: query.get_untracked().trim().to_owned(),
|
||||
quantity: None,
|
||||
icon: Icon::Basket,
|
||||
category: Category::Autre,
|
||||
};
|
||||
ctx.change(ItemOp::Add { id: 0, list_id, input });
|
||||
}
|
||||
None => return,
|
||||
}
|
||||
refocus();
|
||||
};
|
||||
|
||||
view! {
|
||||
<Sheet title="Ajouter".to_owned() on_close=close>
|
||||
<form class="form form-compact" on:submit=submit>
|
||||
<input
|
||||
class="field"
|
||||
type="search"
|
||||
enterkeyhint="done"
|
||||
maxlength="60"
|
||||
placeholder="Avocats, pain…"
|
||||
aria-label="Article"
|
||||
node_ref=input
|
||||
bind:value=query
|
||||
/>
|
||||
|
||||
<Show when=move || !matches.with(Vec::is_empty)>
|
||||
<ul class="tiles">
|
||||
<For
|
||||
each=move || matches.get()
|
||||
key=|item| (item.id, item.checked, item.name.clone(), item.icon)
|
||||
let:item
|
||||
>
|
||||
<SearchResult item on_pick=refocus />
|
||||
</For>
|
||||
</ul>
|
||||
</Show>
|
||||
|
||||
<Show when=can_add>
|
||||
<button
|
||||
type="submit"
|
||||
class="button button-primary button-add"
|
||||
>
|
||||
{move || format!("+ Ajouter « {} »", query.read().trim())}
|
||||
</button>
|
||||
</Show>
|
||||
</form>
|
||||
</Sheet>
|
||||
}
|
||||
}
|
||||
|
||||
/// A list item found by the search: tap moves it between the list and the basket.
|
||||
#[component]
|
||||
fn SearchResult(item: Item, on_pick: impl Fn() + Copy + Send + Sync + 'static) -> impl IntoView {
|
||||
let ctx = expect_context::<Ctx>();
|
||||
let selected = !item.checked;
|
||||
let (id, icon, name) = (item.id, item.icon, item.name);
|
||||
// Same looks as the tiles of the list and of the basket.
|
||||
let class = if selected {
|
||||
format!("tile tile-item {}", item.category.tile_class())
|
||||
} else {
|
||||
"tile tile-off".to_owned()
|
||||
};
|
||||
let aria_label = format!("{name} : {}", if selected { "mettre dans le panier" } else { "remettre dans la liste" });
|
||||
view! {
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
class=class
|
||||
aria-label=aria_label
|
||||
aria-pressed=selected.to_string()
|
||||
on:click=move |_| {
|
||||
ctx.change(ItemOp::SetChecked { id, checked: selected });
|
||||
on_pick();
|
||||
}
|
||||
>
|
||||
<IconSvg icon />
|
||||
<span class="tile-label">
|
||||
{name}
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn ItemForm(editor: ItemEditor, list_id: i64) -> impl IntoView {
|
||||
fn ItemForm(item: Item) -> impl IntoView {
|
||||
let ctx = expect_context::<Ctx>();
|
||||
let close = move || ctx.item_editor.set(None);
|
||||
|
||||
let existing = match &editor {
|
||||
ItemEditor::Edit(item) => Some(item.clone()),
|
||||
ItemEditor::New => None,
|
||||
};
|
||||
let name = RwSignal::new(existing.as_ref().map(|i| i.name.clone()).unwrap_or_default());
|
||||
let name = RwSignal::new(item.name.clone());
|
||||
let amount = RwSignal::new(
|
||||
existing
|
||||
.as_ref()
|
||||
.and_then(|i| i.quantity)
|
||||
item.quantity
|
||||
.map(|q| q.amount.to_string().replace('.', ","))
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
let unit = RwSignal::new(existing.as_ref().and_then(|i| i.quantity).map_or(Unit::Piece, |q| q.unit));
|
||||
let icon = RwSignal::new(existing.as_ref().map_or(Icon::Basket, |i| i.icon));
|
||||
let category = RwSignal::new(existing.as_ref().map_or(Category::Autre, |i| i.category));
|
||||
let item_id = existing.as_ref().map(|i| i.id);
|
||||
let unit = RwSignal::new(item.quantity.map_or(Unit::Piece, |q| q.unit));
|
||||
let icon = RwSignal::new(item.icon);
|
||||
let category = RwSignal::new(item.category);
|
||||
let item_id = item.id;
|
||||
|
||||
let invalid_amount = Memo::new(move |_| amount.with(|a| !a.trim().is_empty() && parse_amount(a).is_none()));
|
||||
|
||||
@@ -86,43 +224,35 @@ fn ItemForm(editor: ItemEditor, list_id: i64) -> impl IntoView {
|
||||
icon: icon.get(),
|
||||
category: category.get(),
|
||||
};
|
||||
ctx.change(match item_id {
|
||||
Some(id) => ItemOp::Update { id, input },
|
||||
None => ItemOp::Add { id: 0, list_id, input },
|
||||
});
|
||||
ctx.change(ItemOp::Update { id: item_id, input });
|
||||
close();
|
||||
};
|
||||
let delete = move |_| {
|
||||
if let Some(id) = item_id {
|
||||
ctx.change(ItemOp::Delete { id });
|
||||
ctx.change(ItemOp::Delete { id: item_id });
|
||||
close();
|
||||
}
|
||||
};
|
||||
|
||||
let title = if item_id.is_some() { "Modifier l'article" } else { "Nouvel article" };
|
||||
|
||||
view! {
|
||||
<Sheet title=title.to_owned() on_close=close>
|
||||
<form class="mt-4 flex flex-col gap-5" on:submit=submit>
|
||||
<label class="flex flex-col gap-1.5">
|
||||
<span class="font-mono text-xs tracking-[0.2em] text-ink/60 uppercase">"Nom"</span>
|
||||
<Sheet title="Modifier l'article".to_owned() on_close=close>
|
||||
<form class="form" on:submit=submit>
|
||||
<label class="field-group">
|
||||
<span class="label">"Nom"</span>
|
||||
<input
|
||||
class="field"
|
||||
required
|
||||
maxlength="60"
|
||||
autofocus
|
||||
placeholder="Avocats"
|
||||
bind:value=name
|
||||
/>
|
||||
</label>
|
||||
|
||||
<div class="flex flex-col gap-1.5">
|
||||
<span class="font-mono text-xs tracking-[0.2em] text-ink/60 uppercase">
|
||||
<div class="field-group">
|
||||
<span class="label">
|
||||
"Quantité (facultatif)"
|
||||
</span>
|
||||
<div class="flex gap-2">
|
||||
<div class="quantity">
|
||||
<input
|
||||
class="field w-28"
|
||||
class="field"
|
||||
inputmode="decimal"
|
||||
placeholder="3"
|
||||
aria-label="Quantité"
|
||||
@@ -130,7 +260,7 @@ fn ItemForm(editor: ItemEditor, list_id: i64) -> impl IntoView {
|
||||
bind:value=amount
|
||||
/>
|
||||
<select
|
||||
class="field flex-1"
|
||||
class="field"
|
||||
aria-label="Unité"
|
||||
on:change=move |ev| {
|
||||
if let Some(u) = Unit::parse(&event_target_value(&ev)) {
|
||||
@@ -151,28 +281,22 @@ fn ItemForm(editor: ItemEditor, list_id: i64) -> impl IntoView {
|
||||
</select>
|
||||
</div>
|
||||
<Show when=move || invalid_amount.get()>
|
||||
<p class="text-sm text-red-700">"Quantité invalide."</p>
|
||||
<p class="field-error">"Quantité invalide."</p>
|
||||
</Show>
|
||||
</div>
|
||||
|
||||
<fieldset class="flex flex-col gap-1.5">
|
||||
<legend class="mb-1.5 font-mono text-xs tracking-[0.2em] text-ink/60 uppercase">
|
||||
<fieldset class="field-group">
|
||||
<legend class="label">
|
||||
"Rayon"
|
||||
</legend>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<div class="chips">
|
||||
{Category::ALL
|
||||
.iter()
|
||||
.map(|&c| {
|
||||
view! {
|
||||
<button
|
||||
type="button"
|
||||
class=move || {
|
||||
format!(
|
||||
"rounded-full border-2 px-3 py-1.5 text-sm font-semibold {} {}",
|
||||
c.tile_class(),
|
||||
if category.get() == c { "border-ink" } else { "border-transparent opacity-70" },
|
||||
)
|
||||
}
|
||||
class=format!("chip {}", c.tile_class())
|
||||
aria-pressed=move || (category.get() == c).to_string()
|
||||
on:click=move |_| category.set(c)
|
||||
>
|
||||
@@ -184,33 +308,24 @@ fn ItemForm(editor: ItemEditor, list_id: i64) -> impl IntoView {
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="flex flex-col gap-1.5">
|
||||
<legend class="mb-1.5 font-mono text-xs tracking-[0.2em] text-ink/60 uppercase">
|
||||
<fieldset class="field-group">
|
||||
<legend class="label">
|
||||
"Icône"
|
||||
</legend>
|
||||
<div class="grid grid-cols-6 gap-2">
|
||||
<div class="icon-grid">
|
||||
{Icon::ALL
|
||||
.iter()
|
||||
.map(|&i| {
|
||||
view! {
|
||||
<button
|
||||
type="button"
|
||||
class=move || {
|
||||
format!(
|
||||
"grid aspect-square place-items-center rounded-xl border-2 {}",
|
||||
if icon.get() == i {
|
||||
"border-ink bg-lime"
|
||||
} else {
|
||||
"border-ink/10 bg-mist"
|
||||
},
|
||||
)
|
||||
}
|
||||
class="icon-choice"
|
||||
title=icon_label(i)
|
||||
aria-label=icon_label(i)
|
||||
aria-pressed=move || (icon.get() == i).to_string()
|
||||
on:click=move |_| icon.set(i)
|
||||
>
|
||||
<IconSvg icon=i class="size-7" />
|
||||
<IconSvg icon=i />
|
||||
</button>
|
||||
}
|
||||
})
|
||||
@@ -218,24 +333,19 @@ fn ItemForm(editor: ItemEditor, list_id: i64) -> impl IntoView {
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div class="flex gap-3">
|
||||
{item_id
|
||||
.map(|_| {
|
||||
view! {
|
||||
<div class="actions">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-2xl border-2 border-ink px-4 py-3 font-semibold"
|
||||
class="button"
|
||||
on:click=delete
|
||||
>
|
||||
"Supprimer"
|
||||
</button>
|
||||
}
|
||||
})}
|
||||
<button
|
||||
type="submit"
|
||||
class="tile-shadow flex-1 rounded-2xl border-2 border-ink bg-pink px-4 py-3 font-display text-lg font-bold active:translate-y-1 active:shadow-none"
|
||||
class="button button-primary"
|
||||
>
|
||||
{if item_id.is_some() { "Enregistrer" } else { "Ajouter" }}
|
||||
"Enregistrer"
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -308,9 +418,9 @@ fn ListForm(editor: ListEditor) -> impl IntoView {
|
||||
|
||||
view! {
|
||||
<Sheet title=title.to_owned() on_close=close>
|
||||
<form class="mt-4 flex flex-col gap-5" on:submit=submit>
|
||||
<label class="flex flex-col gap-1.5">
|
||||
<span class="font-mono text-xs tracking-[0.2em] text-ink/60 uppercase">"Nom"</span>
|
||||
<form class="form" on:submit=submit>
|
||||
<label class="field-group">
|
||||
<span class="label">"Nom"</span>
|
||||
<input
|
||||
class="field"
|
||||
required
|
||||
@@ -323,23 +433,17 @@ fn ListForm(editor: ListEditor) -> impl IntoView {
|
||||
|
||||
<Show when=move || list_id.is_none()>
|
||||
<fieldset>
|
||||
<legend class="mb-1.5 font-mono text-xs tracking-[0.2em] text-ink/60 uppercase">
|
||||
<legend class="label">
|
||||
"Couleur"
|
||||
</legend>
|
||||
<div class="flex gap-3">
|
||||
<div class="swatches">
|
||||
{ListColor::ALL
|
||||
.iter()
|
||||
.map(|&c| {
|
||||
view! {
|
||||
<button
|
||||
type="button"
|
||||
class=move || {
|
||||
format!(
|
||||
"size-11 rounded-full border-2 {} {}",
|
||||
c.dot_class(),
|
||||
if color.get() == c { "border-ink ring-2 ring-ink ring-offset-2 ring-offset-paper" } else { "border-ink/40" },
|
||||
)
|
||||
}
|
||||
class=format!("swatch {}", c.dot_class())
|
||||
aria-label=c.as_str()
|
||||
aria-pressed=move || (color.get() == c).to_string()
|
||||
on:click=move |_| color.set(c)
|
||||
@@ -351,13 +455,13 @@ fn ListForm(editor: ListEditor) -> impl IntoView {
|
||||
</fieldset>
|
||||
</Show>
|
||||
|
||||
<div class="flex gap-3">
|
||||
<div class="actions">
|
||||
{list_id
|
||||
.map(|_| {
|
||||
view! {
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-2xl border-2 border-ink px-4 py-3 font-semibold"
|
||||
class="button"
|
||||
on:click=delete
|
||||
>
|
||||
"Supprimer"
|
||||
@@ -366,7 +470,7 @@ fn ListForm(editor: ListEditor) -> impl IntoView {
|
||||
})}
|
||||
<button
|
||||
type="submit"
|
||||
class="tile-shadow flex-1 rounded-2xl border-2 border-ink bg-pink px-4 py-3 font-display text-lg font-bold active:translate-y-1 active:shadow-none"
|
||||
class="button button-primary"
|
||||
>
|
||||
{if list_id.is_some() { "Enregistrer" } else { "Créer" }}
|
||||
</button>
|
||||
@@ -395,29 +499,29 @@ fn SharePanel(list_id: i64) -> impl IntoView {
|
||||
};
|
||||
|
||||
view! {
|
||||
<section class="mt-6 border-t-2 border-dashed border-ink/15 pt-5">
|
||||
<h3 class="font-mono text-xs tracking-[0.2em] text-ink/60 uppercase">"Partagée avec"</h3>
|
||||
<Transition fallback=|| view! { <p class="mt-2 text-ink/50">"…"</p> }>
|
||||
<section class="section">
|
||||
<h3 class="label">"Partagée avec"</h3>
|
||||
<Transition fallback=|| view! { <p class="section-text">"…"</p> }>
|
||||
{move || Suspend::new(async move {
|
||||
let members = members.await.unwrap_or_default();
|
||||
if members.is_empty() {
|
||||
return view! { <p class="mt-2 text-ink/60">"Personne pour l'instant."</p> }.into_any();
|
||||
return view! { <p class="section-text">"Personne pour l'instant."</p> }.into_any();
|
||||
}
|
||||
view! {
|
||||
<ul class="mt-2 flex flex-col gap-2">
|
||||
<ul class="people">
|
||||
{members
|
||||
.into_iter()
|
||||
.map(|member| {
|
||||
let user_id = member.user_id;
|
||||
view! {
|
||||
<li class="flex items-center justify-between gap-3 rounded-xl bg-mist px-3 py-2">
|
||||
<div class="min-w-0">
|
||||
<p class="truncate font-semibold">{member.name}</p>
|
||||
<p class="truncate text-sm text-ink/60">{member.email}</p>
|
||||
<li class="person">
|
||||
<div class="person-info">
|
||||
<p class="person-name">{member.name}</p>
|
||||
<p class="person-email">{member.email}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="shrink-0 rounded-lg px-2 py-1 text-sm font-semibold underline"
|
||||
class="link-button"
|
||||
on:click=move |_| {
|
||||
ctx.mutate(crate::api::remove_member(list_id, user_id), move |_| bump())
|
||||
}
|
||||
@@ -433,16 +537,16 @@ fn SharePanel(list_id: i64) -> impl IntoView {
|
||||
.into_any()
|
||||
})}
|
||||
</Transition>
|
||||
<form class="mt-3 flex gap-2" on:submit=share>
|
||||
<form class="share-form" on:submit=share>
|
||||
<input
|
||||
class="field min-w-0 flex-1"
|
||||
class="field"
|
||||
type="email"
|
||||
required
|
||||
placeholder="email@exemple.fr"
|
||||
aria-label="Email de la personne"
|
||||
bind:value=email
|
||||
/>
|
||||
<button type="submit" class="shrink-0 rounded-2xl border-2 border-ink bg-lime px-4 font-semibold">
|
||||
<button type="submit" class="button button-lime">
|
||||
"Partager"
|
||||
</button>
|
||||
</form>
|
||||
@@ -471,10 +575,10 @@ fn SharedListInfo(list: ShoppingList) -> impl IntoView {
|
||||
|
||||
view! {
|
||||
<Sheet title=list.name.clone() on_close=close>
|
||||
<p class="mt-1 text-ink/70">{format!("Liste de {}, partagée avec toi.", list.owner_name)}</p>
|
||||
<p class="sheet-text">{format!("Liste de {}, partagée avec toi.", list.owner_name)}</p>
|
||||
<button
|
||||
type="button"
|
||||
class="mt-6 w-full rounded-2xl border-2 border-ink px-4 py-3 font-semibold"
|
||||
class="button button-block"
|
||||
on:click=leave
|
||||
>
|
||||
"Quitter la liste"
|
||||
|
||||
+8
-36
@@ -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;
|
||||
|
||||
@@ -52,10 +52,7 @@ pub fn ItemTile(item: Item) -> impl IntoView {
|
||||
|
||||
view! {
|
||||
<button
|
||||
class=format!(
|
||||
"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(),
|
||||
)
|
||||
class=format!("tile tile-item {}", category.tile_class())
|
||||
style:view-transition-name=transition::item_name(id)
|
||||
aria-label=aria_label
|
||||
on:click=on_click
|
||||
@@ -68,44 +65,19 @@ pub fn ItemTile(item: Item) -> impl IntoView {
|
||||
{badge
|
||||
.map(|badge| {
|
||||
view! {
|
||||
<span class="absolute top-2 right-2 rounded-lg bg-ink px-1.5 py-0.5 font-mono text-xs text-paper">
|
||||
<span class="tile-badge">
|
||||
{badge}
|
||||
</span>
|
||||
}
|
||||
})}
|
||||
<IconSvg icon class="min-h-0 w-full flex-1 text-ink" />
|
||||
<span class="line-clamp-2 text-[0.95rem] leading-tight font-semibold break-words hyphens-auto">
|
||||
<IconSvg icon />
|
||||
<span class="tile-label">
|
||||
{name}
|
||||
</span>
|
||||
</button>
|
||||
}
|
||||
}
|
||||
|
||||
/// 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::<Ctx>();
|
||||
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! {
|
||||
<button
|
||||
class="relative flex aspect-square flex-col items-center gap-1 rounded-2xl border-2 border-dashed border-ink/35 p-2 pb-2.5 text-center text-ink/55 active:bg-ink/5"
|
||||
style:view-transition-name=transition_name
|
||||
on:click=add
|
||||
>
|
||||
<IconSvg icon class="min-h-0 w-full flex-1 opacity-60" />
|
||||
<span class="line-clamp-2 text-[0.95rem] leading-tight font-semibold">{label}</span>
|
||||
</button>
|
||||
}
|
||||
}
|
||||
|
||||
/// Greyed tile in "Déjà dans le panier": tap puts the item back on the list.
|
||||
#[component]
|
||||
pub fn BasketTile(item: Item) -> impl IntoView {
|
||||
@@ -116,13 +88,13 @@ pub fn BasketTile(item: Item) -> impl IntoView {
|
||||
|
||||
view! {
|
||||
<button
|
||||
class="flex aspect-square flex-col items-center gap-0.5 rounded-2xl bg-mist p-1.5 text-center text-ink/45 active:bg-ink/10"
|
||||
class="tile tile-off"
|
||||
style:view-transition-name=transition::item_name(id)
|
||||
aria-label=aria_label
|
||||
on:click=move |_| item.with_value(|item| ctx.toggle(item))
|
||||
>
|
||||
<IconSvg icon class="min-h-0 w-full flex-1" />
|
||||
<span class="line-clamp-2 text-xs leading-tight font-medium line-through decoration-ink/30">
|
||||
<IconSvg icon />
|
||||
<span class="tile-label">
|
||||
{name}
|
||||
</span>
|
||||
</button>
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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<SqlitePool, sqlx::Error> {
|
||||
@@ -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<Vec<Suggestion>, 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;
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Leptos view types nest deeply: the add sheet exceeds the default limit.
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
pub mod api;
|
||||
pub mod app;
|
||||
pub mod model;
|
||||
|
||||
+76
-26
@@ -95,6 +95,16 @@ impl ListColor {
|
||||
ListColor::Peach => "bg-peach",
|
||||
}
|
||||
}
|
||||
|
||||
/// Same color as `dot_class`, for the browser's `theme-color`.
|
||||
pub fn hex(self) -> &'static str {
|
||||
match self {
|
||||
ListColor::Lime => "#bfe383",
|
||||
ListColor::Pink => "#ffadd6",
|
||||
ListColor::Sky => "#7fdffb",
|
||||
ListColor::Peach => "#ffbd76",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@@ -117,7 +127,7 @@ impl Item {
|
||||
|
||||
/// Lowercases and strips French accents so "Œufs" sorts with "o" and
|
||||
/// "Épinards" with "e".
|
||||
fn fold_name(name: &str) -> String {
|
||||
pub fn fold_name(name: &str) -> String {
|
||||
let mut folded = String::with_capacity(name.len());
|
||||
for c in name.chars().flat_map(char::to_lowercase) {
|
||||
match c {
|
||||
@@ -218,7 +228,7 @@ impl Category {
|
||||
}
|
||||
}
|
||||
|
||||
/// Tailwind background class for the item tile.
|
||||
/// Background class for the item tile (see style/main.css).
|
||||
pub fn tile_class(self) -> &'static str {
|
||||
match self {
|
||||
Category::FruitsLegumes => "bg-lime",
|
||||
@@ -235,51 +245,91 @@ impl Category {
|
||||
pub enum Icon {
|
||||
Apple,
|
||||
Banana,
|
||||
Carrot,
|
||||
Lemon,
|
||||
Glass,
|
||||
Pear,
|
||||
Grapes,
|
||||
Strawberry,
|
||||
Cherries,
|
||||
Avocado,
|
||||
Tomato,
|
||||
Carrot,
|
||||
Salad,
|
||||
Onion,
|
||||
Potato,
|
||||
Mushroom,
|
||||
Milk,
|
||||
IceCream,
|
||||
Cheese,
|
||||
Egg,
|
||||
Coffee,
|
||||
Bread,
|
||||
Croissant,
|
||||
Pasta,
|
||||
Cheese,
|
||||
Yogurt,
|
||||
IceCream,
|
||||
Frozen,
|
||||
Meat,
|
||||
Fish,
|
||||
Bread,
|
||||
Croissant,
|
||||
Cake,
|
||||
Cookie,
|
||||
Pizza,
|
||||
Pasta,
|
||||
Can,
|
||||
Jar,
|
||||
Chocolate,
|
||||
Candy,
|
||||
Coffee,
|
||||
Water,
|
||||
Glass,
|
||||
Bottle,
|
||||
Wine,
|
||||
Spray,
|
||||
BabyBottle,
|
||||
Paw,
|
||||
Basket,
|
||||
}
|
||||
|
||||
text_enum!(Icon {
|
||||
Apple => "apple",
|
||||
Banana => "banana",
|
||||
Carrot => "carrot",
|
||||
Lemon => "lemon",
|
||||
Glass => "glass",
|
||||
Pear => "pear",
|
||||
Grapes => "grapes",
|
||||
Strawberry => "strawberry",
|
||||
Cherries => "cherries",
|
||||
Avocado => "avocado",
|
||||
Tomato => "tomato",
|
||||
Carrot => "carrot",
|
||||
Salad => "salad",
|
||||
Onion => "onion",
|
||||
Potato => "potato",
|
||||
Mushroom => "mushroom",
|
||||
Milk => "milk",
|
||||
IceCream => "ice_cream",
|
||||
Cheese => "cheese",
|
||||
Egg => "egg",
|
||||
Coffee => "coffee",
|
||||
Bread => "bread",
|
||||
Croissant => "croissant",
|
||||
Pasta => "pasta",
|
||||
Cheese => "cheese",
|
||||
Yogurt => "yogurt",
|
||||
IceCream => "ice_cream",
|
||||
Frozen => "frozen",
|
||||
Meat => "meat",
|
||||
Fish => "fish",
|
||||
Bread => "bread",
|
||||
Croissant => "croissant",
|
||||
Cake => "cake",
|
||||
Cookie => "cookie",
|
||||
Pizza => "pizza",
|
||||
Pasta => "pasta",
|
||||
Can => "can",
|
||||
Jar => "jar",
|
||||
Chocolate => "chocolate",
|
||||
Candy => "candy",
|
||||
Coffee => "coffee",
|
||||
Water => "water",
|
||||
Glass => "glass",
|
||||
Bottle => "bottle",
|
||||
Wine => "wine",
|
||||
Spray => "spray",
|
||||
BabyBottle => "baby_bottle",
|
||||
Paw => "paw",
|
||||
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 {
|
||||
|
||||
+1056
-37
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user