synpad 0.1.0

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

use crate::state::app_state::AppState;

/// Typing indicator shown at the bottom of the timeline.
#[component]
pub fn TypingIndicator(room_id: String) -> Element {
    let state = use_context::<Signal<AppState>>();

    let typing_members = state
        .read()
        .rooms
        .values()
        .find(|r| r.room_id.to_string() == room_id)
        .map(|r| r.typing_members.clone())
        .unwrap_or_default();

    if typing_members.is_empty() {
        return rsx! {};
    }

    let text = match typing_members.len() {
        1 => format!("{} is typing...", typing_members[0]),
        2 => format!("{} and {} are typing...", typing_members[0], typing_members[1]),
        n => format!("{} and {} others are typing...", typing_members[0], n - 1),
    };

    rsx! {
        div {
            class: "typing-indicator",
            div {
                class: "typing-indicator__dots",
                span { class: "typing-indicator__dot" }
                span { class: "typing-indicator__dot" }
                span { class: "typing-indicator__dot" }
            }
            span {
                class: "typing-indicator__text",
                "{text}"
            }
        }
    }
}