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
61
use crate::{IconEvent, IconList, Modal, ModalMessage};
use css_in_rust_next::Style;
use yew::{html, Callback, Component, Context, Html, Properties};

#[derive(PartialEq, Properties)]
pub struct EditIconProperties {
  pub event: Callback<EditIconMessage>,
  pub title: String,
}

pub enum EditIconMessage {
  Selected(IconEvent),
  Cancel,
}

pub enum InternalMessage {
  Selected(IconEvent),
  Modal(ModalMessage),
}

pub struct EditIcon {
  style: Style,
}

impl Component for EditIcon {
  type Message = InternalMessage;
  type Properties = EditIconProperties;

  fn create(_ctx: &Context<Self>) -> Self {
    let style = Style::create("Component", include_str!("edit_style.css")).unwrap();
    EditIcon { style }
  }

  fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
    match msg {
      InternalMessage::Selected(icon_event) => ctx
        .props()
        .event
        .emit(EditIconMessage::Selected(icon_event)),

      InternalMessage::Modal(ModalMessage::Cancel) => {
        ctx.props().event.emit(EditIconMessage::Cancel)
      }
      _ => {}
    }
    false
  }

  fn view(&self, ctx: &Context<Self>) -> Html {
    html!(
      <Modal
        event={ctx.link().callback(InternalMessage::Modal)}
        height="50vh" width="19vw"
        modal_title={ctx.props().title.clone()}>
        <div class={self.style.clone()}>
          <IconList event={ctx.link().callback(InternalMessage::Selected)}/>
        </div>
      </Modal>
    )
  }
}