use dioxus::prelude::*;
use crate::state::app_state::AppState;
#[component]
pub fn LiveLocationPicker(room_id: String, on_close: EventHandler<()>) -> Element {
let _state = use_context::<Signal<AppState>>();
let mut duration_minutes = use_signal(|| 15u32);
let mut is_sharing = use_signal(|| false);
let durations = [(15, "15 minutes"), (60, "1 hour"), (480, "8 hours")];
let on_start = {
let rid = room_id.clone();
move |_| {
is_sharing.set(true);
let dur = *duration_minutes.read();
let rid = rid.clone();
spawn(async move {
tracing::info!("Started live location sharing for {dur} minutes in room {rid}");
});
}
};
rsx! {
div {
class: "live-location",
h4 { "Share Live Location" }
p { class: "live-location__desc",
"Share your real-time location with everyone in this room for a set period."
}
if !*is_sharing.read() {
div {
class: "live-location__options",
for (mins, label) in durations.iter() {
{
let m = *mins;
let l = *label;
let is_selected = *duration_minutes.read() == m;
rsx! {
button {
class: if is_selected { "live-location__option live-location__option--selected" } else { "live-location__option" },
onclick: move |_| duration_minutes.set(m),
"{l}"
}
}
}
}
}
div {
class: "live-location__actions",
button { class: "btn btn--secondary", onclick: move |_| on_close.call(()), "Cancel" }
button { class: "btn btn--primary", onclick: on_start, "Share Location" }
}
} else {
div {
class: "live-location__active",
div { class: "live-location__pulse" }
p { "Sharing your location..." }
{
let dur = *duration_minutes.read();
let label = durations.iter().find(|(m, _)| *m == dur).map(|(_, l)| *l).unwrap_or("Unknown");
rsx! { span { class: "live-location__timer", "Duration: {label}" } }
}
button {
class: "btn btn--danger",
onclick: move |_| {
is_sharing.set(false);
on_close.call(());
},
"Stop Sharing"
}
}
}
}
}
}