Support for viewing comments by a user
This commit is contained in:
parent
514191f75c
commit
f8f5c80450
|
@ -39,10 +39,10 @@ pub enum CommentRowMsg {
|
|||
impl FactoryComponent for CommentRow {
|
||||
type Init = CommentView;
|
||||
type Input = CommentRowMsg;
|
||||
type Output = PostPageInput;
|
||||
type Output = crate::AppMsg;
|
||||
type CommandOutput = ();
|
||||
type Widgets = PostViewWidgets;
|
||||
type ParentInput = PostPageInput;
|
||||
type ParentInput = crate::AppMsg;
|
||||
type ParentWidget = gtk::Box;
|
||||
|
||||
view! {
|
||||
|
@ -171,17 +171,13 @@ impl FactoryComponent for CommentRow {
|
|||
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
|
||||
match message {
|
||||
CommentRowMsg::OpenPerson => {
|
||||
sender.output(PostPageInput::PassAppMessage(crate::AppMsg::OpenPerson(
|
||||
self.comment.creator.id.clone(),
|
||||
)));
|
||||
sender.output(crate::AppMsg::OpenPerson(self.comment.creator.id.clone()));
|
||||
}
|
||||
CommentRowMsg::DeleteComment => {
|
||||
let comment_id = self.comment.comment.id;
|
||||
std::thread::spawn(move || {
|
||||
let _ = api::comment::delete_comment(comment_id);
|
||||
sender.output_sender().emit(PostPageInput::PassAppMessage(
|
||||
crate::AppMsg::StartFetchPosts(None, true),
|
||||
));
|
||||
sender.output_sender().emit(crate::AppMsg::StartFetchPosts(None, true));
|
||||
});
|
||||
}
|
||||
CommentRowMsg::OpenEditor(is_new) => {
|
||||
|
@ -223,8 +219,8 @@ impl FactoryComponent for CommentRow {
|
|||
std::thread::spawn(move || {
|
||||
match api::comment::create_comment(post_id, data.body, Some(parent_id))
|
||||
{
|
||||
Ok(comment) => {
|
||||
sender.output_sender().emit(PostPageInput::CreatedComment(comment.comment_view));
|
||||
Ok(_comment) => {
|
||||
// TODO sender.output_sender().emit(PostPageInput::CreatedComment(comment.comment_view));
|
||||
}
|
||||
Err(err) => {
|
||||
println!("{}", err.to_string());
|
||||
|
|
|
@ -201,7 +201,7 @@ impl SimpleComponent for PostPage {
|
|||
sender: relm4::ComponentSender<Self>,
|
||||
) -> relm4::ComponentParts<Self> {
|
||||
let image = WebImage::builder().launch("".to_string()).detach();
|
||||
let comments = FactoryVecDeque::new(gtk::Box::default(), sender.input_sender());
|
||||
let comments = FactoryVecDeque::new(gtk::Box::default(), sender.output_sender());
|
||||
let creator_avatar = WebImage::builder().launch("".to_string()).detach();
|
||||
let community_avatar = WebImage::builder().launch("".to_string()).detach();
|
||||
let dialog = EditorDialog::builder()
|
||||
|
|
|
@ -13,11 +13,15 @@ use crate::util::get_web_image_msg;
|
|||
use crate::util::markdown_to_pango_markup;
|
||||
|
||||
use super::post_row::PostRow;
|
||||
use super::community_row::CommunityRow;
|
||||
use super::comment_row::CommentRow;
|
||||
|
||||
pub struct ProfilePage {
|
||||
info: GetPersonDetailsResponse,
|
||||
avatar: Controller<WebImage>,
|
||||
posts: FactoryVecDeque<PostRow>,
|
||||
comments: FactoryVecDeque<CommentRow>,
|
||||
communities: FactoryVecDeque<CommunityRow>,
|
||||
editor_dialog: Controller<EditorDialog>,
|
||||
}
|
||||
|
||||
|
@ -82,9 +86,36 @@ impl SimpleComponent for ProfilePage {
|
|||
|
||||
gtk::Separator {},
|
||||
|
||||
#[local_ref]
|
||||
posts -> gtk::Box {
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
gtk::StackSwitcher {
|
||||
set_stack: Some(&stack),
|
||||
},
|
||||
|
||||
#[name(stack)]
|
||||
gtk::Stack {
|
||||
add_child = >k::Box {
|
||||
#[local_ref]
|
||||
posts -> gtk::Box {
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
}
|
||||
} -> {
|
||||
set_title: "Posts",
|
||||
},
|
||||
add_child = >k::Box {
|
||||
#[local_ref]
|
||||
comments -> gtk::Box {
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
}
|
||||
} -> {
|
||||
set_title: "Comments",
|
||||
},
|
||||
add_child = >k::Box {
|
||||
#[local_ref]
|
||||
communities -> gtk::Box {
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
}
|
||||
} -> {
|
||||
set_title: "Moderates",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,6 +129,8 @@ impl SimpleComponent for ProfilePage {
|
|||
) -> relm4::ComponentParts<Self> {
|
||||
let avatar = WebImage::builder().launch("".to_string()).detach();
|
||||
let posts = FactoryVecDeque::new(gtk::Box::default(), sender.output_sender());
|
||||
let communities = FactoryVecDeque::new(gtk::Box::default(), sender.output_sender());
|
||||
let comments = FactoryVecDeque::new(gtk::Box::default(), sender.output_sender());
|
||||
let editor_dialog = EditorDialog::builder()
|
||||
.transient_for(root)
|
||||
.launch(EditorType::PrivateMessage)
|
||||
|
@ -109,10 +142,14 @@ impl SimpleComponent for ProfilePage {
|
|||
info: init,
|
||||
avatar,
|
||||
posts,
|
||||
comments,
|
||||
communities,
|
||||
editor_dialog,
|
||||
};
|
||||
let avatar = model.avatar.widget();
|
||||
let posts = model.posts.widget();
|
||||
let comments = model.comments.widget();
|
||||
let communities = model.communities.widget();
|
||||
let widgets = view_output!();
|
||||
|
||||
ComponentParts { model, widgets }
|
||||
|
@ -124,10 +161,17 @@ impl SimpleComponent for ProfilePage {
|
|||
self.info = person.clone();
|
||||
self.avatar
|
||||
.emit(get_web_image_msg(person.person_view.person.avatar));
|
||||
|
||||
self.posts.guard().clear();
|
||||
self.comments.guard().clear();
|
||||
self.communities.guard().clear();
|
||||
|
||||
for post in person.posts {
|
||||
self.posts.guard().push_back(post);
|
||||
}
|
||||
for comment in person.comments {
|
||||
self.comments.guard().push_back(comment);
|
||||
}
|
||||
}
|
||||
ProfileInput::SendMessageRequest => self.editor_dialog.sender().emit(DialogMsg::Show),
|
||||
ProfileInput::SendMessage(content) => {
|
||||
|
|
Loading…
Reference in New Issue