From f351cd83e22f2e71c33655e612c8bff47edc7895 Mon Sep 17 00:00:00 2001 From: mlackner Date: Fri, 21 Nov 2025 00:01:24 +0100 Subject: [PATCH] feat(ui): implement interactive assignment reveal component Add a new AssignmentReveal component that enables users to reveal their secret gift exchange assignments through an interactive hold-to-reveal mechanism. The component includes a frosted glass overlay with smooth fade transitions, an animated progress ring, and comprehensive event handling for both mouse and touch interactions. Backend changes: - Add get_my_assignment server function to fetch user's assignment - Protect event creator from having admin role removed Additional updates: - Update year placeholder in create event form to 2025 - Add CSS utilities for animations, gradients, and effects --- assets/tailwind.css | 88 +++++++++++++++ src/components/assignment_reveal.rs | 160 ++++++++++++++++++++++++++++ src/components/mod.rs | 3 + src/server_fns.rs | 50 +++++++++ src/views/create_event.rs | 2 +- src/views/event_page.rs | 10 +- wichtl.db | Bin 36864 -> 36864 bytes 7 files changed, 309 insertions(+), 4 deletions(-) create mode 100644 src/components/assignment_reveal.rs diff --git a/assets/tailwind.css b/assets/tailwind.css index 18f8d03..4775f83 100644 --- a/assets/tailwind.css +++ b/assets/tailwind.css @@ -285,6 +285,9 @@ .-z-10 { z-index: calc(10 * -1); } + .z-10 { + z-index: 10; + } .z-50 { z-index: 50; } @@ -351,6 +354,9 @@ .ml-2 { margin-left: calc(var(--spacing) * 2); } + .ml-8 { + margin-left: calc(var(--spacing) * 8); + } .block { display: block; } @@ -390,6 +396,9 @@ .h-16 { height: calc(var(--spacing) * 16); } + .h-20 { + height: calc(var(--spacing) * 20); + } .h-24 { height: calc(var(--spacing) * 24); } @@ -399,6 +408,9 @@ .h-screen { height: 100vh; } + .min-h-32 { + min-height: calc(var(--spacing) * 32); + } .min-h-full { min-height: 100%; } @@ -414,6 +426,9 @@ .w-5 { width: calc(var(--spacing) * 5); } + .w-6 { + width: calc(var(--spacing) * 6); + } .w-8 { width: calc(var(--spacing) * 8); } @@ -426,6 +441,9 @@ .w-16 { width: calc(var(--spacing) * 16); } + .w-20 { + width: calc(var(--spacing) * 20); + } .w-24 { width: calc(var(--spacing) * 24); } @@ -589,6 +607,10 @@ border-style: var(--tw-border-style); border-width: 1px; } + .border-2 { + border-style: var(--tw-border-style); + border-width: 2px; + } .border-t { border-top-style: var(--tw-border-style); border-top-width: 1px; @@ -619,6 +641,9 @@ .border-indigo-600 { border-color: var(--color-indigo-600); } + .border-purple-500 { + border-color: var(--color-purple-500); + } .border-red-200 { border-color: var(--color-red-200); } @@ -649,6 +674,12 @@ border-color: color-mix(in oklab, var(--color-white) 10%, transparent); } } + .border-white\/20 { + border-color: color-mix(in srgb, #fff 20%, transparent); + @supports (color: color-mix(in lab, red, red)) { + border-color: color-mix(in oklab, var(--color-white) 20%, transparent); + } + } .bg-black\/30 { background-color: color-mix(in srgb, #000 30%, transparent); @supports (color: color-mix(in lab, red, red)) { @@ -794,6 +825,10 @@ --tw-gradient-from: var(--color-indigo-600); --tw-gradient-stops: var(--tw-gradient-via-stops, var(--tw-gradient-position), var(--tw-gradient-from) var(--tw-gradient-from-position), var(--tw-gradient-to) var(--tw-gradient-to-position)); } + .from-purple-500 { + --tw-gradient-from: var(--color-purple-500); + --tw-gradient-stops: var(--tw-gradient-via-stops, var(--tw-gradient-position), var(--tw-gradient-from) var(--tw-gradient-from-position), var(--tw-gradient-to) var(--tw-gradient-to-position)); + } .from-purple-600 { --tw-gradient-from: var(--color-purple-600); --tw-gradient-stops: var(--tw-gradient-via-stops, var(--tw-gradient-position), var(--tw-gradient-from) var(--tw-gradient-from-position), var(--tw-gradient-to) var(--tw-gradient-to-position)); @@ -815,6 +850,10 @@ --tw-gradient-to: var(--color-cyan-50); --tw-gradient-stops: var(--tw-gradient-via-stops, var(--tw-gradient-position), var(--tw-gradient-from) var(--tw-gradient-from-position), var(--tw-gradient-to) var(--tw-gradient-to-position)); } + .to-pink-500 { + --tw-gradient-to: var(--color-pink-500); + --tw-gradient-stops: var(--tw-gradient-via-stops, var(--tw-gradient-position), var(--tw-gradient-from) var(--tw-gradient-from-position), var(--tw-gradient-to) var(--tw-gradient-to-position)); + } .to-pink-600 { --tw-gradient-to: var(--color-pink-600); --tw-gradient-stops: var(--tw-gradient-via-stops, var(--tw-gradient-position), var(--tw-gradient-from) var(--tw-gradient-from-position), var(--tw-gradient-to) var(--tw-gradient-to-position)); @@ -1045,6 +1084,12 @@ .text-white { color: var(--color-white); } + .text-white\/20 { + color: color-mix(in srgb, #fff 20%, transparent); + @supports (color: color-mix(in lab, red, red)) { + color: color-mix(in oklab, var(--color-white) 20%, transparent); + } + } .uppercase { text-transform: uppercase; } @@ -1070,6 +1115,10 @@ --tw-shadow: 0 20px 25px -5px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 8px 10px -6px var(--tw-shadow-color, rgb(0 0 0 / 0.1)); box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow); } + .ring { + --tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor); + box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow); + } .ring-1 { --tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor); box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow); @@ -1119,6 +1168,14 @@ transition-timing-function: var(--tw-ease, var(--default-transition-timing-function)); transition-duration: var(--tw-duration, var(--default-transition-duration)); } + .duration-100 { + --tw-duration: 100ms; + transition-duration: 100ms; + } + .duration-300 { + --tw-duration: 300ms; + transition-duration: 300ms; + } .outline-none { --tw-outline-style: none; outline-style: none; @@ -1444,6 +1501,14 @@ outline-color: var(--color-white); } } + .active\:scale-95 { + &:active { + --tw-scale-x: 95%; + --tw-scale-y: 95%; + --tw-scale-z: 95%; + scale: var(--tw-scale-x) var(--tw-scale-y); + } + } .active\:bg-slate-300 { &:active { background-color: var(--color-slate-300); @@ -1795,11 +1860,30 @@ syntax: "*"; inherits: false; } +@property --tw-duration { + syntax: "*"; + inherits: false; +} @property --tw-outline-style { syntax: "*"; inherits: false; initial-value: solid; } +@property --tw-scale-x { + syntax: "*"; + inherits: false; + initial-value: 1; +} +@property --tw-scale-y { + syntax: "*"; + inherits: false; + initial-value: 1; +} +@property --tw-scale-z { + syntax: "*"; + inherits: false; + initial-value: 1; +} @keyframes spin { to { transform: rotate(360deg); @@ -1866,7 +1950,11 @@ --tw-backdrop-opacity: initial; --tw-backdrop-saturate: initial; --tw-backdrop-sepia: initial; + --tw-duration: initial; --tw-outline-style: solid; + --tw-scale-x: 1; + --tw-scale-y: 1; + --tw-scale-z: 1; } } } diff --git a/src/components/assignment_reveal.rs b/src/components/assignment_reveal.rs new file mode 100644 index 0000000..4e860bf --- /dev/null +++ b/src/components/assignment_reveal.rs @@ -0,0 +1,160 @@ +use crate::server_fns; +use dioxus::prelude::*; + +#[component] +pub fn AssignmentReveal(event_id: i32) -> Element { + let mut assignment: Resource, ServerFnError>> = + use_resource(move || async move { server_fns::get_my_assignment(event_id).await }); + + let mut is_holding = use_signal(|| false); + let mut reveal_progress = use_signal(|| 0.0f64); + + // Animation effect - runs when holding + use_effect(move || { + if is_holding() && reveal_progress() < 1.0 { + let current = reveal_progress(); + reveal_progress.set((current + 0.016).min(1.0)); + } else if !is_holding() && reveal_progress() > 0.0 { + reveal_progress.set(0.0); + } + }); + + let on_mouse_down = move |_| { + is_holding.set(true); + }; + + let on_mouse_up = move |_| { + is_holding.set(false); + }; + + let on_mouse_leave = move |_| { + is_holding.set(false); + }; + + let on_touch_start = move |_| { + is_holding.set(true); + }; + + let on_touch_end = move |_| { + is_holding.set(false); + }; + + rsx! { + div { + class: "bg-slate-800/50 backdrop-blur-sm border border-white/10 rounded-2xl p-6 shadow-xl mb-8", + + // Title + h2 { class: "text-xl font-bold text-white mb-6 flex items-center gap-2", + span { class: "w-1 h-6 bg-gradient-to-b from-purple-500 to-pink-500 rounded-full block" } + "Dein Wichtel-Partner" + } + + // Content area with frosted effect + div { + class: "relative overflow-hidden rounded-xl border border-white/10", + + // Frosted overlay + div { + class: "absolute inset-0 bg-slate-900/80 backdrop-blur-md transition-all duration-300 z-10 flex items-center justify-center", + style: if reveal_progress() < 1.0 { + format!("opacity: {};", 1.0 - reveal_progress()) + } else { + "opacity: 0; pointer-events: none;".to_string() + }, + + // Frost pattern/text + div { class: "text-center", + svg { + class: "w-16 h-16 mx-auto mb-4 text-slate-400", + fill: "none", + stroke: "currentColor", + view_box: "0 0 24 24", + path { + stroke_linecap: "round", + stroke_linejoin: "round", + stroke_width: "2", + d: "M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 100 4m0-4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 100 4m0-4v2m0-6V4" + } + } + p { class: "text-slate-400 font-medium", "Geheimnis versteckt" } + p { class: "text-sm text-slate-500 mt-2", "Halte die Taste gedrückt" } + } + } + + // Reveal content + div { + class: "p-8 text-center min-h-32 flex items-center justify-center", + + match assignment.read().as_ref() { + Some(Ok(Some(receiver))) => rsx! { + div { class: "space-y-4", + div { class: "w-20 h-20 mx-auto rounded-full bg-gradient-to-br from-purple-600 to-pink-600 flex items-center justify-center text-white text-2xl font-bold border-2 border-white/20", + "{receiver.chars().next().unwrap_or('?')}" + } + p { class: "text-2xl font-bold text-white", "{receiver}" } + p { class: "text-slate-400", "Du bist der Wichtel für:" } + } + }, + Some(Ok(None)) => rsx! { + p { class: "text-slate-400", "Noch keine Zuordnung vorhanden" } + }, + Some(Err(e)) => rsx! { + p { class: "text-red-400", "Fehler: {e}" } + }, + None => rsx! { + div { class: "flex justify-center items-center", + div { class: "animate-spin rounded-full h-8 w-8 border-b-2 border-purple-500" } + } + } + } + } + } + + // Hold button + button { + class: "w-full mt-4 py-3 bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-500 hover:to-pink-500 text-white font-bold rounded-xl shadow-lg shadow-purple-600/20 transition-all active:scale-95", + onmousedown: on_mouse_down, + onmouseup: on_mouse_up, + onmouseleave: on_mouse_leave, + ontouchstart: on_touch_start, + ontouchend: on_touch_end, + + // Progress ring + div { class: "relative inline-flex items-center justify-center", + svg { + class: "w-6 h-6 absolute", + view_box: "0 0 24 24", + circle { + class: "text-white/20", + stroke: "currentColor", + stroke_width: "3", + fill: "none", + r: "10", + cx: "12", + cy: "12" + } + circle { + class: "text-white transition-all duration-100", + stroke: "currentColor", + stroke_width: "3", + fill: "none", + r: "10", + cx: "12", + cy: "12", + stroke_dasharray: "62.83", + stroke_dashoffset: format!("{}", 62.83 * (1.0 - reveal_progress())), + transform: "rotate(-90 12 12)" + } + } + span { class: "ml-8", + if reveal_progress() < 1.0 { + "Halten zum Aufdecken" + } else { + "Aufgedeckt!" + } + } + } + } + } + } +} diff --git a/src/components/mod.rs b/src/components/mod.rs index 302260f..275d704 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -1 +1,4 @@ +pub mod assignment_reveal; pub mod navbar; + +pub use assignment_reveal::AssignmentReveal; diff --git a/src/server_fns.rs b/src/server_fns.rs index 81af625..57d238d 100644 --- a/src/server_fns.rs +++ b/src/server_fns.rs @@ -665,6 +665,21 @@ pub async fn remove_admin_role(participant_id: i32, event_id: i32) -> Result<(), )); } + // Check if the participant is the event creator + let event = events::Entity::find_by_id(event_id) + .one(&db) + .await + .map_err(|e| ServerFnError::new(e.to_string()))? + .ok_or(ServerFnError::new("Event not found"))?; + + if let Some(creator_id) = participant.user_id { + if creator_id == event.creator_id { + return Err(ServerFnError::new( + "Cannot remove admin role from event creator", + )); + } + } + // Update the participant's role to Member let mut participant: db::participants::ActiveModel = participant.into(); participant.role = Set(db::participants::Role::Member); @@ -751,6 +766,41 @@ pub async fn update_event_date(event_id: i32, new_date: String) -> Result<(), Se Ok(()) } +#[server] +pub async fn get_my_assignment(event_id: i32) -> Result, ServerFnError> { + let session: tower_sessions::Session = FullstackContext::extract().await?; + let user_id: i32 = session + .get("user_id") + .await + .map_err(|e| ServerFnError::new(e.to_string()))? + .ok_or(ServerFnError::new("Not logged in"))?; + + let db = db::establish_connection() + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + + // Find the assignment where current user is the giver + let assignment = assignments::Entity::find() + .filter(assignments::Column::EventId.eq(event_id)) + .filter(assignments::Column::GiverId.eq(user_id)) + .one(&db) + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + + if let Some(assignment) = assignment { + // Get the receiver's name + let receiver = participants::Entity::find_by_id(assignment.receiver_id) + .one(&db) + .await + .map_err(|e| ServerFnError::new(e.to_string()))? + .ok_or(ServerFnError::new("Receiver not found"))?; + + Ok(Some(receiver.name)) + } else { + Ok(None) + } +} + #[server] pub async fn delete_event(event_id: i32) -> Result<(), ServerFnError> { let session: tower_sessions::Session = FullstackContext::extract().await?; diff --git a/src/views/create_event.rs b/src/views/create_event.rs index cd5f161..1196e27 100644 --- a/src/views/create_event.rs +++ b/src/views/create_event.rs @@ -41,7 +41,7 @@ pub fn CreateEvent() -> Element { input { id: "event-name", class: "appearance-none block w-full px-4 py-3 bg-slate-900/50 border border-slate-700 rounded-xl text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent transition-all sm:text-sm", - placeholder: "z.B. Familienweihnachten 2024", + placeholder: "z.B. Familienweihnachten 2025", value: "{name}", oninput: move |e| name.set(e.value()), required: true diff --git a/src/views/event_page.rs b/src/views/event_page.rs index ad1e810..43c9cb4 100644 --- a/src/views/event_page.rs +++ b/src/views/event_page.rs @@ -1,5 +1,4 @@ -#[cfg(feature = "server")] -use crate::db; +use crate::components::AssignmentReveal; use crate::server_fns; use crate::Route; use dioxus::prelude::*; @@ -349,10 +348,12 @@ pub fn EventPage(id: i32) -> Element { } } } + } } } - } }, + } + } Some(Err(e)) => rsx! { p { class: "text-red-400", "Error: {e}" } }, None => rsx! { div { class: "flex justify-center py-8", div { class: "animate-spin rounded-full h-8 w-8 border-b-2 border-indigo-500" } } @@ -361,6 +362,9 @@ pub fn EventPage(id: i32) -> Element { } } + // Assignment Reveal Section (for participants) + AssignmentReveal { event_id: id } + // Draw Button (only for admins) if is_admin() { button { diff --git a/wichtl.db b/wichtl.db index 465555883418e7a0b462349c39915f1406358fba..ba6f3bd2bc78af372c9963b89df174dfd59ab7dc 100644 GIT binary patch delta 712 zcmXYtyHDFt6vq96$Ov+XG9c7S(2@=V50v) zE5uxes#}K^i4Aq?(50wrRUxrdsyb9%P`mXyWjdd}d(ZEj@0^?yC+EbA2l(2{hwJ#- zyWQ6?Nrhz$&fr=2Ls-6uOmBoIbZQKXJ{Oh#-s!8kIo>V$JEBm@i1r|!ZZ(fov6Nk{ z#Eg7zopT$-a(S5O9H!LXpsO6`%PUQv?bYM_YJy+(4)RBA*70<51XNXZ1U%rGT4AqL z@T+!brM6R-B;PT!F|n+cy9v$hZ%doWT9&W2QkhOhE~QLPt_UedFD}}LO^?%aIh_~* z+wFD$JGlnr;Ws>W@@)cR^gu_U8qzwxilbvvK}9zpgNjxs#>ptH zD9RMvp{6SguHh$K!B^Du7KCY%e1Z=YYpARGKrx3lMdRcQ?%0}TQ$UdmxMJIS*EBTr z)}#q?me$-rqZKCT(YGliakxfcg!~BEI3B_l9!2RTPt$v*qV|TG$ueweDZwtW$ppiQ z#$F+lGZOuVWLnN@EdWq(iNP=U2A|*(VctL~LWM9ois7?CCPOpYniV1MtsvgLMci9K z(*G8q`KXbeL7|n7p_}h_srg9?ZZPnfY%q@PFff&3_AM;Te7der9G>&Vt0E zlFa1Hg2cR%VooMzNzT-=R3MXsky)Ixv^ce>7^IVt{{{p94WO=b{6=bw>7mjD0&