perspective_viewer/components/
error_message.rs

1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ ██████ ██████ ██████       █      █      █      █      █ █▄  ▀███ █       ┃
3// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█  ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄  ▀█ █ ▀▀▀▀▀ ┃
4// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄   █ ▄▄▄▄▄ ┃
5// ┃ █      ██████ █  ▀█▄       █ ██████      █      ███▌▐███ ███████▄ █       ┃
6// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7// ┃ Copyright (c) 2017, the Perspective Authors.                              ┃
8// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9// ┃ This file is part of the Perspective library, distributed under the terms ┃
10// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
13use perspective_client::clone;
14use yew::prelude::*;
15use yew::{Properties, function_component, html};
16
17use crate::components::style::LocalStyle;
18use crate::css;
19use crate::session::Session;
20use crate::utils::AddListener;
21
22#[derive(PartialEq, Properties)]
23pub struct ErrorMessageProps {
24    pub session: Session,
25}
26
27#[function_component(ErrorMessage)]
28pub fn error_message(p: &ErrorMessageProps) -> yew::Html {
29    let error = use_state(|| p.session.get_error());
30    use_effect_with(
31        (error.setter(), p.session.clone()),
32        |(set_error, session)| {
33            let sub = session.table_errored.add_listener({
34                clone!(set_error);
35                move |y| set_error.set(Some(y))
36            });
37
38            || drop(sub)
39        },
40    );
41
42    html! {
43        <>
44            <LocalStyle href={css!("render-warning")} />
45            <div
46                class="plugin_information plugin_information--warning"
47                id="plugin_information--size"
48            >
49                <span class="plugin_information__icon" />
50                <span class="plugin_information__text" id="plugin_information_count">
51                    if let Some(msg) = error.as_ref() { { msg } }
52                </span>
53            </div>
54        </>
55    }
56}