synpad 0.1.0

A full-featured Matrix chat client built with Dioxus
use dioxus::prelude::*;

use crate::components::modal::Modal;

/// Dialog for sharing a room link/permalink.
#[component]
pub fn ShareRoomDialog(
    room_id: String,
    room_name: String,
    on_close: EventHandler<()>,
) -> Element {
    let mut copied = use_signal(|| false);

    // Generate matrix.to permalink
    let permalink = format!("https://matrix.to/#/{room_id}");

    rsx! {
        Modal {
            title: "Share Room".to_string(),
            on_close: move |_| on_close.call(()),

            div {
                class: "share-room-dialog",

                p {
                    class: "share-room-dialog__info",
                    "Share a link to \"{room_name}\" with others."
                }

                div {
                    class: "share-room-dialog__link-row",
                    input {
                        r#type: "text",
                        class: "share-room-dialog__link-input",
                        value: "{permalink}",
                        readonly: true,
                    }
                    button {
                        class: "btn btn--primary",
                        onclick: move |_| {
                            let link = permalink.clone();
                            copied.set(true);
                            spawn(async move {
                                let _ = dioxus::prelude::document::eval(
                                    &format!("navigator.clipboard.writeText({})", serde_json::to_string(&link).unwrap_or_default()),
                                );
                            });
                        },
                        if *copied.read() { "Copied!" } else { "Copy Link" }
                    }
                }

                div {
                    class: "share-room-dialog__room-id",
                    label { "Room ID:" }
                    code { "{room_id}" }
                }
            }
        }
    }
}