summaryrefslogtreecommitdiffstats
path: root/src/components/icon.rs
blob: 307d36717392ab864dad065298bde6a8ed8451ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use filamento::{chat::Delivery, presence::Show};
use leptos::prelude::*;

use crate::icon::Icon;

// TODO: rename
#[component]
pub fn IconComponent(icon: Icon) -> impl IntoView {
    view! {
        <img
            class:light=icon.light()
            class:icon=true
            style=move || format!("height: {}px; width: {}px", icon.size(), icon.size())
            src=move || icon.src()
        />
    }
}

pub fn show_to_icon(show: Show) -> Icon {
    match show {
        Show::Away => Icon::Away16Color,
        Show::Chat => Icon::Chat16Color,
        Show::DoNotDisturb => Icon::Dnd16Color,
        Show::ExtendedAway => Icon::Xa16Color,
    }
}

#[component]
pub fn Delivery(delivery: Delivery) -> impl IntoView {
    match delivery {
        // TODO: proper icon coloring/theming
        Delivery::Sending => {
            view! { <IconComponent class:visible=true class:light=true icon=Icon::Sending16 /> }
                .into_any()
        }
        Delivery::Written => {
            view! { <IconComponent class:light=true icon=Icon::Sent16 /> }.into_any()
        }
        // TODO: message receipts
        // Delivery::Written => view! {}.into_any(),
        Delivery::Sent => view! { <IconComponent class:light=true icon=Icon::Sent16 /> }.into_any(),
        Delivery::Delivered => {
            view! { <IconComponent class:light=true icon=Icon::Delivered16 /> }.into_any()
        }
        // TODO: check if there is also the icon class
        Delivery::Read => {
            view! { <IconComponent class:light=true class:read=true icon=Icon::Delivered16 /> }
                .into_any()
        }
        Delivery::Failed => {
            view! { <IconComponent class:visible=true class:light=true icon=Icon::Error16Color /> }
                .into_any()
        }
        // TODO: queued icon
        Delivery::Queued => {
            view! { <IconComponent class:visible=true class:light=true icon=Icon::Sending16 /> }
                .into_any()
        }
    }
}