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
This commit is contained in:
mlackner 2025-11-21 00:01:24 +01:00
parent 7ef4ff4221
commit f351cd83e2
7 changed files with 309 additions and 4 deletions

View File

@ -285,6 +285,9 @@
.-z-10 { .-z-10 {
z-index: calc(10 * -1); z-index: calc(10 * -1);
} }
.z-10 {
z-index: 10;
}
.z-50 { .z-50 {
z-index: 50; z-index: 50;
} }
@ -351,6 +354,9 @@
.ml-2 { .ml-2 {
margin-left: calc(var(--spacing) * 2); margin-left: calc(var(--spacing) * 2);
} }
.ml-8 {
margin-left: calc(var(--spacing) * 8);
}
.block { .block {
display: block; display: block;
} }
@ -390,6 +396,9 @@
.h-16 { .h-16 {
height: calc(var(--spacing) * 16); height: calc(var(--spacing) * 16);
} }
.h-20 {
height: calc(var(--spacing) * 20);
}
.h-24 { .h-24 {
height: calc(var(--spacing) * 24); height: calc(var(--spacing) * 24);
} }
@ -399,6 +408,9 @@
.h-screen { .h-screen {
height: 100vh; height: 100vh;
} }
.min-h-32 {
min-height: calc(var(--spacing) * 32);
}
.min-h-full { .min-h-full {
min-height: 100%; min-height: 100%;
} }
@ -414,6 +426,9 @@
.w-5 { .w-5 {
width: calc(var(--spacing) * 5); width: calc(var(--spacing) * 5);
} }
.w-6 {
width: calc(var(--spacing) * 6);
}
.w-8 { .w-8 {
width: calc(var(--spacing) * 8); width: calc(var(--spacing) * 8);
} }
@ -426,6 +441,9 @@
.w-16 { .w-16 {
width: calc(var(--spacing) * 16); width: calc(var(--spacing) * 16);
} }
.w-20 {
width: calc(var(--spacing) * 20);
}
.w-24 { .w-24 {
width: calc(var(--spacing) * 24); width: calc(var(--spacing) * 24);
} }
@ -589,6 +607,10 @@
border-style: var(--tw-border-style); border-style: var(--tw-border-style);
border-width: 1px; border-width: 1px;
} }
.border-2 {
border-style: var(--tw-border-style);
border-width: 2px;
}
.border-t { .border-t {
border-top-style: var(--tw-border-style); border-top-style: var(--tw-border-style);
border-top-width: 1px; border-top-width: 1px;
@ -619,6 +641,9 @@
.border-indigo-600 { .border-indigo-600 {
border-color: var(--color-indigo-600); border-color: var(--color-indigo-600);
} }
.border-purple-500 {
border-color: var(--color-purple-500);
}
.border-red-200 { .border-red-200 {
border-color: var(--color-red-200); border-color: var(--color-red-200);
} }
@ -649,6 +674,12 @@
border-color: color-mix(in oklab, var(--color-white) 10%, transparent); 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 { .bg-black\/30 {
background-color: color-mix(in srgb, #000 30%, transparent); background-color: color-mix(in srgb, #000 30%, transparent);
@supports (color: color-mix(in lab, red, red)) { @supports (color: color-mix(in lab, red, red)) {
@ -794,6 +825,10 @@
--tw-gradient-from: var(--color-indigo-600); --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)); --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 { .from-purple-600 {
--tw-gradient-from: var(--color-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)); --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-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)); --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 { .to-pink-600 {
--tw-gradient-to: var(--color-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)); --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 { .text-white {
color: var(--color-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 { .uppercase {
text-transform: 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)); --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); 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 { .ring-1 {
--tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor); --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); 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-timing-function: var(--tw-ease, var(--default-transition-timing-function));
transition-duration: var(--tw-duration, var(--default-transition-duration)); 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 { .outline-none {
--tw-outline-style: none; --tw-outline-style: none;
outline-style: none; outline-style: none;
@ -1444,6 +1501,14 @@
outline-color: var(--color-white); 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\:bg-slate-300 {
&:active { &:active {
background-color: var(--color-slate-300); background-color: var(--color-slate-300);
@ -1795,11 +1860,30 @@
syntax: "*"; syntax: "*";
inherits: false; inherits: false;
} }
@property --tw-duration {
syntax: "*";
inherits: false;
}
@property --tw-outline-style { @property --tw-outline-style {
syntax: "*"; syntax: "*";
inherits: false; inherits: false;
initial-value: solid; 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 { @keyframes spin {
to { to {
transform: rotate(360deg); transform: rotate(360deg);
@ -1866,7 +1950,11 @@
--tw-backdrop-opacity: initial; --tw-backdrop-opacity: initial;
--tw-backdrop-saturate: initial; --tw-backdrop-saturate: initial;
--tw-backdrop-sepia: initial; --tw-backdrop-sepia: initial;
--tw-duration: initial;
--tw-outline-style: solid; --tw-outline-style: solid;
--tw-scale-x: 1;
--tw-scale-y: 1;
--tw-scale-z: 1;
} }
} }
} }

View File

@ -0,0 +1,160 @@
use crate::server_fns;
use dioxus::prelude::*;
#[component]
pub fn AssignmentReveal(event_id: i32) -> Element {
let mut assignment: Resource<Result<Option<String>, 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!"
}
}
}
}
}
}
}

View File

@ -1 +1,4 @@
pub mod assignment_reveal;
pub mod navbar; pub mod navbar;
pub use assignment_reveal::AssignmentReveal;

View File

@ -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 // Update the participant's role to Member
let mut participant: db::participants::ActiveModel = participant.into(); let mut participant: db::participants::ActiveModel = participant.into();
participant.role = Set(db::participants::Role::Member); 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(()) Ok(())
} }
#[server]
pub async fn get_my_assignment(event_id: i32) -> Result<Option<String>, 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] #[server]
pub async fn delete_event(event_id: i32) -> Result<(), ServerFnError> { pub async fn delete_event(event_id: i32) -> Result<(), ServerFnError> {
let session: tower_sessions::Session = FullstackContext::extract().await?; let session: tower_sessions::Session = FullstackContext::extract().await?;

View File

@ -41,7 +41,7 @@ pub fn CreateEvent() -> Element {
input { input {
id: "event-name", 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", 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}", value: "{name}",
oninput: move |e| name.set(e.value()), oninput: move |e| name.set(e.value()),
required: true required: true

View File

@ -1,5 +1,4 @@
#[cfg(feature = "server")] use crate::components::AssignmentReveal;
use crate::db;
use crate::server_fns; use crate::server_fns;
use crate::Route; use crate::Route;
use dioxus::prelude::*; use dioxus::prelude::*;
@ -349,10 +348,12 @@ pub fn EventPage(id: i32) -> Element {
} }
} }
} }
} }
} }
} }
} }, }
}
Some(Err(e)) => rsx! { p { class: "text-red-400", "Error: {e}" } }, Some(Err(e)) => rsx! { p { class: "text-red-400", "Error: {e}" } },
None => rsx! { 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" } } 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) // Draw Button (only for admins)
if is_admin() { if is_admin() {
button { button {

BIN
wichtl.db

Binary file not shown.