daydream

A small matrix web client written in rust
git clone git://archive.git.mtrnord.blog/daydream-mx/daydream.git
Log | Files | Refs | README | LICENSE

main_view.rs (3026B)


      1 use std::rc::Rc;
      2 
      3 use log::*;
      4 use matrix_sdk::Room;
      5 use serde::{Deserialize, Serialize};
      6 use yew::prelude::*;
      7 use yew::ComponentLink;
      8 
      9 use tr::tr;
     10 
     11 use crate::app::components::{event_list::EventList, room_list::RoomList};
     12 use crate::app::matrix::{MatrixAgent, Request};
     13 
     14 pub struct MainView {
     15     link: ComponentLink<Self>,
     16     state: State,
     17 }
     18 
     19 pub enum Msg {
     20     ChangeRoom(Rc<Room>),
     21 }
     22 
     23 #[derive(Serialize, Deserialize, Default)]
     24 pub struct State {
     25     pub current_room: Option<Rc<Room>>,
     26     pub current_room_displayname: String,
     27 }
     28 
     29 impl Component for MainView {
     30     type Message = Msg;
     31     type Properties = ();
     32 
     33     fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
     34         let mut matrix_agent = MatrixAgent::dispatcher();
     35         matrix_agent.send(Request::StartSync);
     36         let state = State {
     37             current_room: None,
     38             current_room_displayname: Default::default(),
     39         };
     40 
     41         MainView { link, state }
     42     }
     43 
     44     fn update(&mut self, msg: Self::Message) -> bool {
     45         match msg {
     46             Msg::ChangeRoom(room) => {
     47                 info!("Changing room to: {}", room.room_id);
     48                 self.state.current_room = Some(room);
     49             }
     50         }
     51         true
     52     }
     53 
     54     fn change(&mut self, _props: Self::Properties) -> bool {
     55         false
     56     }
     57 
     58     //noinspection RsTypeCheck
     59     fn view(&self) -> Html {
     60         match &self.state.current_room {
     61             None => html! {
     62                 <div class="uk-flex auto-scrollable-container uk-background-default" style="height: 100%">
     63                     <RoomList change_room_callback=self.link.callback(Msg::ChangeRoom)/>
     64 
     65                     <div class="container uk-flex uk-width-5-6 uk-padding">
     66                         <div class="scrollable">
     67                             // TODO add some content to the empty page
     68                         </div>
     69                     </div>
     70                 </div>
     71             },
     72             Some(room) if room.is_encrypted() => html! {
     73                 <div class="uk-flex auto-scrollable-container" style="height: 100%">
     74                     <RoomList change_room_callback=self.link.callback(Msg::ChangeRoom)/>
     75                     <div class="event-list">
     76                         <div class="room-title"><h1>{ room.display_name() }</h1></div>
     77                         <h4>
     78                             {
     79                                 tr!(
     80                                     // A warning for encrypted rooms
     81                                     "Daydream currently does not support encryption."
     82                                 )
     83                             }
     84                         </h4>
     85                     </div>
     86                 </div>
     87             },
     88             Some(room) => html! {
     89                 <div class="uk-flex auto-scrollable-container" style="height: 100%">
     90                     <RoomList change_room_callback=self.link.callback(Msg::ChangeRoom)/>
     91                     <EventList current_room=room />
     92                 </div>
     93             },
     94         }
     95     }
     96 }