2021-06-07 22:34:05 +00:00
|
|
|
use yewdux::prelude::*;
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub(crate) struct Room {
|
|
|
|
pub room_id: String,
|
|
|
|
pub display_name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, Clone)]
|
|
|
|
pub(crate) struct WebUiState {
|
2021-06-11 13:46:05 +00:00
|
|
|
pub jwt_token: Option<String>,
|
2021-06-07 22:34:05 +00:00
|
|
|
pub rooms: Vec<Room>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) enum Action {
|
2021-06-11 13:46:05 +00:00
|
|
|
UpdateJwt(String),
|
2021-06-07 22:34:05 +00:00
|
|
|
AddRoom(Room),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Reducer for WebUiState {
|
|
|
|
type Action = Action;
|
|
|
|
|
|
|
|
fn new() -> Self {
|
2021-06-11 13:46:05 +00:00
|
|
|
Self {
|
|
|
|
jwt_token: None,
|
|
|
|
rooms: vec![],
|
|
|
|
}
|
2021-06-07 22:34:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn reduce(&mut self, action: Self::Action) -> bool {
|
|
|
|
match action {
|
2021-06-11 13:46:05 +00:00
|
|
|
Action::UpdateJwt(jwt_token) => self.jwt_token = Some(jwt_token),
|
|
|
|
Action::AddRoom(room) => self.rooms.push(room.clone()),
|
|
|
|
};
|
|
|
|
|
|
|
|
true
|
2021-06-07 22:34:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) type WebUiDispatcher = DispatchProps<ReducerStore<WebUiState>>;
|