Add some logic to messages

This commit is contained in:
Adrian Wozniak 2020-05-28 16:52:14 +02:00
parent ce440ae08c
commit e7ade80fe3
4 changed files with 81 additions and 14 deletions

View File

@ -108,10 +108,17 @@ nav#sidebar .linkItem > a > .linkText {
min-width: 800px;
}
.styledTooltip.messages > .messagesList {}
.styledTooltip.messages > .messagesList {
}
.styledTooltip.messages > .messagesList > .message {
padding: 15px;
max-height: 90px;
overflow: hidden;
}
.styledTooltip.messages > .messagesList > .message:hover {
max-height: 100%;
}
.styledTooltip.messages > .messagesList > .message > .summary {
@ -130,8 +137,13 @@ nav#sidebar .linkItem > a > .linkText {
color: var(--primary);
}
.styledTooltip.messages > .messagesList > .message > .hyperlink > a:hover {
text-decoration: underline;
}
.styledTooltip.messages > .messagesList > .message > .hyperlink > a > .styledIcon {
padding-right: 15px;
padding-right: 5px;
font-size: 14.5px;
}
.styledTooltip.messages > .messagesList > .message > .actions {

View File

@ -91,6 +91,11 @@ pub enum Msg {
ModalDropped,
ModalChanged(FieldChange),
// popups
MessageSeen(MessageId),
MessageInvitationApproved(InvitationToken),
MessageInvitationDismiss(InvitationToken),
// WebSocket
WebSocketChange(WebSocketChanged),
}
@ -178,6 +183,7 @@ fn update(msg: Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>) {
_ => (),
}
crate::shared::aside::update(&msg, model, orders);
crate::shared::navbar_left::update(&msg, model, orders);
crate::modal::update(&msg, model, orders);
match model.page {
Page::Project | Page::AddIssue | Page::EditIssue(..) => project::update(msg, model, orders),

View File

@ -1,12 +1,13 @@
use seed::{prelude::*, *};
use jirs_data::{Message, MessageType};
use jirs_data::{InvitationToken, Message, MessageType, WsMsg};
use crate::model::Model;
use crate::shared::styled_avatar::StyledAvatar;
use crate::shared::styled_button::StyledButton;
use crate::shared::styled_icon::{Icon, StyledIcon};
use crate::shared::{divider, styled_tooltip, ToNode};
use crate::ws::send_ws_msg;
use crate::Msg;
trait IntoNavItemIcon {
@ -25,6 +26,26 @@ impl IntoNavItemIcon for Icon {
}
}
pub fn update(msg: &Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
match msg {
Msg::MessageInvitationApproved(token) => {
send_ws_msg(
WsMsg::InvitationAcceptRequest(token.clone()),
model.ws.as_ref(),
orders,
);
}
Msg::MessageInvitationDismiss(token) => {
send_ws_msg(
WsMsg::InvitationRejectRequest(token.clone()),
model.ws.as_ref(),
orders,
);
}
_ => (),
}
}
pub fn render(model: &Model) -> Vec<Node<Msg>> {
let logo_svg = Node::from_html(include_str!("../../static/logo.svg"));
@ -111,12 +132,15 @@ fn messages_tooltip_popup(model: &Model) -> Node<Msg> {
});
let mut messages: Vec<Node<Msg>> = vec![];
for (idx, message) in model.messages.iter().enumerate() {
let message_ui = message_ui(model, message);
messages.push(message_ui);
if idx != model.messages.len() - 1 {
messages.push(divider());
}
match message_ui(model, message) {
Some(message_ui) => {
messages.push(message_ui);
if idx != model.messages.len() - 1 {
messages.push(divider());
}
}
None => (),
};
}
let body = div![on_click, class!["messagesList"], messages];
styled_tooltip::StyledTooltip::build()
@ -128,7 +152,7 @@ fn messages_tooltip_popup(model: &Model) -> Node<Msg> {
.into_node()
}
fn message_ui(model: &Model, message: &Message) -> Node<Msg> {
fn message_ui(model: &Model, message: &Message) -> Option<Node<Msg>> {
let Message {
id: _,
receiver_id: _,
@ -141,31 +165,50 @@ fn message_ui(model: &Model, message: &Message) -> Node<Msg> {
updated_at: _,
} = message;
let hyperlink = if hyper_link.is_empty() {
let hyperlink = if hyper_link.is_empty() && !hyper_link.starts_with("#") {
empty![]
} else {
let link_icon = StyledIcon::build(Icon::Link).build().into_node();
div![
class!["hyperlink"],
a![attrs![At::Href => hyper_link], link_icon, hyper_link]
a![
class!["styledLink"],
attrs![At::Href => hyper_link],
link_icon,
hyper_link
]
]
};
let message_description = parse_description(model, description.as_str());
match message_type {
let node = match message_type {
MessageType::ReceivedInvitation => {
let token: InvitationToken = match hyper_link.trim_start_matches("#").parse() {
Err(_) => return None,
Ok(n) => n,
};
let accept = StyledButton::build()
.primary()
.text("Accept")
.active(true)
.icon(Icon::Check)
.on_click(mouse_ev(Ev::Click, move |ev| {
ev.stop_propagation();
ev.prevent_default();
Some(Msg::MessageInvitationApproved(token.clone()))
}))
.build()
.into_node();
let reject = StyledButton::build()
.danger()
.text("Dismiss")
.icon(Icon::Close)
.on_click(mouse_ev(Ev::Click, move |ev| {
ev.stop_propagation();
ev.prevent_default();
Some(Msg::MessageInvitationDismiss(token))
}))
.active(true)
.build()
.into_node();
@ -189,7 +232,8 @@ fn message_ui(model: &Model, message: &Message) -> Node<Msg> {
div![class!["description"], message_description],
hyperlink,
],
}
};
Some(node)
}
fn about_tooltip_popup(model: &Model) -> Node<Msg> {

View File

@ -751,6 +751,11 @@ pub enum WsMsg {
InvitationAcceptRequest(InvitationToken),
InvitationAcceptSuccess(BindToken),
InvitationAcceptFailure(InvitationToken),
//
InvitationRejectRequest(InvitationToken),
InvitationRejectSuccess,
InvitationRejectFailure(InvitationToken),
//
InvitedUserRemoveRequest(UserId),
InvitedUserRemoveSuccess(UserId),