support for saving/bookmarking comments
This commit is contained in:
parent
572b1992b1
commit
900928be71
|
@ -1,5 +1,7 @@
|
|||
use lemmy_api_common::{
|
||||
comment::{CommentResponse, CreateComment, CreateCommentLike, DeleteComment, EditComment},
|
||||
comment::{
|
||||
CommentResponse, CreateComment, CreateCommentLike, DeleteComment, EditComment, SaveComment,
|
||||
},
|
||||
lemmy_db_schema::newtypes::{CommentId, PostId},
|
||||
};
|
||||
|
||||
|
@ -30,7 +32,10 @@ pub fn like_comment(comment_id: CommentId, score: i16) -> Result<CommentResponse
|
|||
super::post("/comment/like", ¶ms)
|
||||
}
|
||||
|
||||
pub fn edit_comment(body: String, comment_id: CommentId) -> Result<CommentResponse, reqwest::Error> {
|
||||
pub fn edit_comment(
|
||||
body: String,
|
||||
comment_id: CommentId,
|
||||
) -> Result<CommentResponse, reqwest::Error> {
|
||||
let params = EditComment {
|
||||
content: Some(body),
|
||||
comment_id,
|
||||
|
@ -48,3 +53,12 @@ pub fn delete_comment(comment_id: CommentId) -> Result<CommentResponse, reqwest:
|
|||
};
|
||||
super::post("/comment/delete", ¶ms)
|
||||
}
|
||||
|
||||
pub fn save_comment(comment_id: CommentId, save: bool) -> Result<CommentResponse, reqwest::Error> {
|
||||
let params = SaveComment {
|
||||
auth: settings::get_current_account().jwt.unwrap(),
|
||||
comment_id,
|
||||
save,
|
||||
};
|
||||
super::put("/comment/save", ¶ms)
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ pub struct CommentRow {
|
|||
pub enum CommentRowMsg {
|
||||
OpenPerson,
|
||||
DeleteComment,
|
||||
ToggleSaved,
|
||||
OpenEditor(bool),
|
||||
EditCommentRequest(EditorData),
|
||||
CreateCommentRequest(EditorData),
|
||||
|
@ -97,6 +98,15 @@ impl FactoryComponent for CommentRow {
|
|||
set_visible: settings::get_current_account().jwt.is_some(),
|
||||
},
|
||||
|
||||
gtk::ToggleButton {
|
||||
set_icon_name: "bookmark-new",
|
||||
set_margin_start: 5,
|
||||
connect_clicked => CommentRowMsg::ToggleSaved,
|
||||
set_visible: settings::get_current_account().jwt.is_some(),
|
||||
#[watch]
|
||||
set_active: self.comment.saved,
|
||||
},
|
||||
|
||||
gtk::Button {
|
||||
set_icon_name: "document-edit",
|
||||
connect_clicked => CommentRowMsg::OpenEditor(false),
|
||||
|
@ -214,6 +224,18 @@ impl FactoryComponent for CommentRow {
|
|||
};
|
||||
});
|
||||
}
|
||||
CommentRowMsg::ToggleSaved => {
|
||||
let comment_id = self.comment.comment.id;
|
||||
let new_state = !self.comment.saved;
|
||||
std::thread::spawn(move || {
|
||||
match api::comment::save_comment(comment_id, new_state) {
|
||||
Ok(comment) => {
|
||||
sender.input(CommentRowMsg::UpdateComment(comment.comment_view))
|
||||
}
|
||||
Err(err) => println!("{}", err),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue