Parse mode css
This commit is contained in:
parent
8ee6566e3b
commit
f8963882ea
@ -5,12 +5,13 @@ use jirs_data::*;
|
|||||||
|
|
||||||
use crate::api::send_ws_msg;
|
use crate::api::send_ws_msg;
|
||||||
use crate::model::{Model, Page, PageContent, ProfilePage};
|
use crate::model::{Model, Page, PageContent, ProfilePage};
|
||||||
|
use crate::shared::styled_button::StyledButton;
|
||||||
use crate::shared::styled_field::StyledField;
|
use crate::shared::styled_field::StyledField;
|
||||||
use crate::shared::styled_form::StyledForm;
|
use crate::shared::styled_form::StyledForm;
|
||||||
use crate::shared::styled_image_input::StyledImageInput;
|
use crate::shared::styled_image_input::StyledImageInput;
|
||||||
use crate::shared::styled_input::StyledInput;
|
use crate::shared::styled_input::StyledInput;
|
||||||
use crate::shared::{inner_layout, ToNode};
|
use crate::shared::{inner_layout, ToNode};
|
||||||
use crate::{FieldId, Msg, HOST_URL};
|
use crate::{FieldId, Msg, PageChanged, ProfilePageChange, HOST_URL};
|
||||||
|
|
||||||
pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Orders<Msg>) {
|
pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Orders<Msg>) {
|
||||||
let user = match model.user {
|
let user = match model.user {
|
||||||
@ -59,6 +60,12 @@ pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Order
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Msg::PageChanged(PageChanged::Profile(ProfilePageChange::SubmitForm)) => {
|
||||||
|
send_ws_msg(WsMsg::ProfileUpdate(
|
||||||
|
profile_page.email.value.clone(),
|
||||||
|
profile_page.name.value.clone(),
|
||||||
|
))
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,11 +106,27 @@ pub fn view(model: &Model) -> Node<Msg> {
|
|||||||
.build()
|
.build()
|
||||||
.into_node();
|
.into_node();
|
||||||
|
|
||||||
|
let submit = StyledButton::build()
|
||||||
|
.primary()
|
||||||
|
.text("Save")
|
||||||
|
.on_click(mouse_ev(Ev::Click, |ev| {
|
||||||
|
ev.prevent_default();
|
||||||
|
Msg::PageChanged(PageChanged::Profile(ProfilePageChange::SubmitForm))
|
||||||
|
}))
|
||||||
|
.build()
|
||||||
|
.into_node();
|
||||||
|
let submit_field = StyledField::build().input(submit).build().into_node();
|
||||||
|
|
||||||
let content = StyledForm::build()
|
let content = StyledForm::build()
|
||||||
.heading("Profile")
|
.heading("Profile")
|
||||||
|
.on_submit(ev(Ev::Submit, |ev| {
|
||||||
|
ev.prevent_default();
|
||||||
|
Msg::PageChanged(PageChanged::Profile(ProfilePageChange::SubmitForm))
|
||||||
|
}))
|
||||||
.add_field(avatar)
|
.add_field(avatar)
|
||||||
.add_field(username_field)
|
.add_field(username_field)
|
||||||
.add_field(email_field)
|
.add_field(email_field)
|
||||||
|
.add_field(submit_field)
|
||||||
.build()
|
.build()
|
||||||
.into_node();
|
.into_node();
|
||||||
inner_layout(model, "profile", vec![content], empty![])
|
inner_layout(model, "profile", vec![content], empty![])
|
||||||
|
@ -770,4 +770,6 @@ pub enum WsMsg {
|
|||||||
|
|
||||||
// users
|
// users
|
||||||
AvatarUrlChanged(UserId, String),
|
AvatarUrlChanged(UserId, String),
|
||||||
|
ProfileUpdate(EmailString, UsernameString),
|
||||||
|
ProfileUpdated,
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,11 @@ repository = "https://gitlab.com/adrian.wozniak/jirs"
|
|||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
#license-file = "../LICENSE"
|
#license-file = "../LICENSE"
|
||||||
|
|
||||||
|
[target.x86_64-unknown-linux-gnu]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-arg=-fuse-ld=lld",
|
||||||
|
]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "jirs_server"
|
name = "jirs_server"
|
||||||
path = "./src/main.rs"
|
path = "./src/main.rs"
|
||||||
|
@ -240,6 +240,43 @@ impl Handler<UpdateAvatarUrl> for DbExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct ProfileUpdate {
|
||||||
|
pub user_id: UserId,
|
||||||
|
pub name: String,
|
||||||
|
pub email: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Message for ProfileUpdate {
|
||||||
|
type Result = Result<User, ServiceErrors>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Handler<ProfileUpdate> for DbExecutor {
|
||||||
|
type Result = Result<User, ServiceErrors>;
|
||||||
|
|
||||||
|
fn handle(&mut self, msg: ProfileUpdate, _ctx: &mut Self::Context) -> Self::Result {
|
||||||
|
use crate::schema::users::dsl::{email, id, name, users};
|
||||||
|
|
||||||
|
let conn = &self
|
||||||
|
.pool
|
||||||
|
.get()
|
||||||
|
.map_err(|_| ServiceErrors::DatabaseConnectionLost)?;
|
||||||
|
let update_query = diesel::update(users)
|
||||||
|
.set((email.eq(msg.email), name.eq(msg.name)))
|
||||||
|
.filter(id.eq(msg.user_id));
|
||||||
|
debug!("{}", diesel::debug_query::<Pg, _>(&update_query));
|
||||||
|
update_query
|
||||||
|
.execute(conn)
|
||||||
|
.map_err(|e| ServiceErrors::DatabaseQueryFailed(format!("{}", e)))?;
|
||||||
|
|
||||||
|
let user_query = users.find(msg.user_id);
|
||||||
|
debug!("{}", diesel::debug_query::<Pg, _>(&user_query));
|
||||||
|
user_query
|
||||||
|
.first(conn)
|
||||||
|
.map_err(|e| ServiceErrors::DatabaseQueryFailed(format!("{}", e)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::db::build_pool;
|
use crate::db::build_pool;
|
||||||
|
@ -140,6 +140,11 @@ impl WebSocketActor {
|
|||||||
WsMsg::InvitationRevokeRequest(id) => self.handle_msg(RevokeInvitation { id }, ctx)?,
|
WsMsg::InvitationRevokeRequest(id) => self.handle_msg(RevokeInvitation { id }, ctx)?,
|
||||||
WsMsg::InvitedUsersRequest => self.handle_msg(LoadInvitedUsers, ctx)?,
|
WsMsg::InvitedUsersRequest => self.handle_msg(LoadInvitedUsers, ctx)?,
|
||||||
|
|
||||||
|
// users
|
||||||
|
WsMsg::ProfileUpdate(email, name) => {
|
||||||
|
self.handle_msg(ProfileUpdate { email, name }, ctx)?
|
||||||
|
}
|
||||||
|
|
||||||
// else fail
|
// else fail
|
||||||
_ => {
|
_ => {
|
||||||
error!("No handle for {:?} specified", msg);
|
error!("No handle for {:?} specified", msg);
|
||||||
|
@ -61,3 +61,26 @@ impl WsHandler<LoadInvitedUsers> for WebSocketActor {
|
|||||||
Ok(Some(WsMsg::InvitedUsersLoaded(users)))
|
Ok(Some(WsMsg::InvitedUsersLoaded(users)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct ProfileUpdate {
|
||||||
|
pub name: String,
|
||||||
|
pub email: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WsHandler<ProfileUpdate> for WebSocketActor {
|
||||||
|
fn handle_msg(&mut self, msg: ProfileUpdate, _ctx: &mut Self::Context) -> WsResult {
|
||||||
|
let user_id = self.require_user()?.id;
|
||||||
|
let ProfileUpdate { name, email } = msg;
|
||||||
|
|
||||||
|
match block_on(self.db.send(crate::db::users::ProfileUpdate {
|
||||||
|
user_id,
|
||||||
|
name,
|
||||||
|
email,
|
||||||
|
})) {
|
||||||
|
Ok(Ok(_users)) => (),
|
||||||
|
_ => return Ok(None),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Some(WsMsg::ProfileUpdated))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user