feat: support for reporting posts (closes #30)
This commit is contained in:
parent
62fcb4640d
commit
a91f1f4d7f
|
@ -8,7 +8,10 @@ use relm4_components::web_image::WebImage;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api,
|
api,
|
||||||
dialogs::editor::{DialogMsg, EditorData, EditorDialog, EditorOutput, EditorType},
|
dialogs::{
|
||||||
|
editor::{DialogMsg, EditorData, EditorDialog, EditorOutput, EditorType},
|
||||||
|
report_dialog::{ReportDialog, ReportDialogInput},
|
||||||
|
},
|
||||||
settings,
|
settings,
|
||||||
util::{self, get_web_image_msg, get_web_image_url, markdown_to_pango_markup},
|
util::{self, get_web_image_msg, get_web_image_url, markdown_to_pango_markup},
|
||||||
};
|
};
|
||||||
|
@ -26,6 +29,7 @@ pub struct PostPage {
|
||||||
comments: FactoryVecDeque<CommentRow>,
|
comments: FactoryVecDeque<CommentRow>,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
create_comment_dialog: Controller<EditorDialog>,
|
create_comment_dialog: Controller<EditorDialog>,
|
||||||
|
report_post_dialog: Controller<ReportDialog>,
|
||||||
voting_row: Controller<VotingRowModel>,
|
voting_row: Controller<VotingRowModel>,
|
||||||
thumbnail_height: i32,
|
thumbnail_height: i32,
|
||||||
}
|
}
|
||||||
|
@ -48,6 +52,7 @@ pub enum PostPageInput {
|
||||||
DeletePost,
|
DeletePost,
|
||||||
DoneEditPost(PostView),
|
DoneEditPost(PostView),
|
||||||
PassAppMessage(crate::AppMsg),
|
PassAppMessage(crate::AppMsg),
|
||||||
|
ShowReportDialog,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[relm4::component(pub)]
|
#[relm4::component(pub)]
|
||||||
|
@ -189,6 +194,12 @@ impl SimpleComponent for PostPage {
|
||||||
#[watch]
|
#[watch]
|
||||||
set_active: model.info.post_view.saved,
|
set_active: model.info.post_view.saved,
|
||||||
},
|
},
|
||||||
|
gtk::Button {
|
||||||
|
set_icon_name: "action-unavailable",
|
||||||
|
set_margin_start: 10,
|
||||||
|
connect_clicked => PostPageInput::ShowReportDialog,
|
||||||
|
set_visible: settings::get_current_account().jwt.is_some(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
#[local_ref]
|
#[local_ref]
|
||||||
|
@ -208,7 +219,7 @@ impl SimpleComponent for PostPage {
|
||||||
let comments = FactoryVecDeque::new(gtk::Box::default(), sender.output_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 create_comment_dialog = EditorDialog::builder()
|
||||||
.transient_for(root)
|
.transient_for(root)
|
||||||
.launch(EditorType::Comment)
|
.launch(EditorType::Comment)
|
||||||
.forward(sender.input_sender(), |msg| match msg {
|
.forward(sender.input_sender(), |msg| match msg {
|
||||||
|
@ -220,6 +231,10 @@ impl SimpleComponent for PostPage {
|
||||||
let voting_row = VotingRowModel::builder()
|
let voting_row = VotingRowModel::builder()
|
||||||
.launch(VotingStats::default())
|
.launch(VotingStats::default())
|
||||||
.detach();
|
.detach();
|
||||||
|
let report_post_dialog = ReportDialog::builder()
|
||||||
|
.transient_for(root)
|
||||||
|
.launch((None, None))
|
||||||
|
.detach();
|
||||||
|
|
||||||
let model = PostPage {
|
let model = PostPage {
|
||||||
info: init,
|
info: init,
|
||||||
|
@ -227,7 +242,8 @@ impl SimpleComponent for PostPage {
|
||||||
comments,
|
comments,
|
||||||
creator_avatar,
|
creator_avatar,
|
||||||
community_avatar,
|
community_avatar,
|
||||||
create_comment_dialog: dialog,
|
create_comment_dialog,
|
||||||
|
report_post_dialog,
|
||||||
voting_row,
|
voting_row,
|
||||||
thumbnail_height: 400,
|
thumbnail_height: 400,
|
||||||
};
|
};
|
||||||
|
@ -394,6 +410,13 @@ impl SimpleComponent for PostPage {
|
||||||
PostPageInput::PassAppMessage(message) => {
|
PostPageInput::PassAppMessage(message) => {
|
||||||
sender.output_sender().emit(message);
|
sender.output_sender().emit(message);
|
||||||
}
|
}
|
||||||
|
PostPageInput::ShowReportDialog => {
|
||||||
|
let message = ReportDialogInput::UpdateId(Some(self.info.post_view.post.id), None);
|
||||||
|
self.report_post_dialog.sender().emit(message);
|
||||||
|
self.report_post_dialog
|
||||||
|
.sender()
|
||||||
|
.emit(ReportDialogInput::Show);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,6 @@ impl FactoryComponent for PostRow {
|
||||||
}
|
}
|
||||||
None => unreachable!(),
|
None => unreachable!(),
|
||||||
}
|
}
|
||||||
println!("size {}", self.image_size);
|
|
||||||
let thumbnail = self.thumbnail.widget();
|
let thumbnail = self.thumbnail.widget();
|
||||||
let author_image = self.author_image.widget();
|
let author_image = self.author_image.widget();
|
||||||
let community_image = self.community_image.widget();
|
let community_image = self.community_image.widget();
|
||||||
|
|
|
@ -49,6 +49,8 @@ impl SimpleComponent for ReportDialog {
|
||||||
set_margin_top: 10,
|
set_margin_top: 10,
|
||||||
set_margin_bottom: 10,
|
set_margin_bottom: 10,
|
||||||
set_label: "Report",
|
set_label: "Report",
|
||||||
|
set_hexpand: false,
|
||||||
|
set_halign: gtk::Align::End,
|
||||||
connect_clicked[report_message] => move |_| {
|
connect_clicked[report_message] => move |_| {
|
||||||
let reason = report_message.text().to_string();
|
let reason = report_message.text().to_string();
|
||||||
ReportDialogInput::Report(reason);
|
ReportDialogInput::Report(reason);
|
||||||
|
|
Loading…
Reference in New Issue