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