feat: support for reporting posts (closes #30)

This commit is contained in:
Bnyro 2023-09-15 10:44:04 +02:00
parent 62fcb4640d
commit a91f1f4d7f
3 changed files with 28 additions and 4 deletions

View File

@ -8,7 +8,10 @@ use relm4_components::web_image::WebImage;
use crate::{
api,
dialogs::editor::{DialogMsg, EditorData, EditorDialog, EditorOutput, EditorType},
dialogs::{
editor::{DialogMsg, EditorData, EditorDialog, EditorOutput, EditorType},
report_dialog::{ReportDialog, ReportDialogInput},
},
settings,
util::{self, get_web_image_msg, get_web_image_url, markdown_to_pango_markup},
};
@ -26,6 +29,7 @@ pub struct PostPage {
comments: FactoryVecDeque<CommentRow>,
#[allow(dead_code)]
create_comment_dialog: Controller<EditorDialog>,
report_post_dialog: Controller<ReportDialog>,
voting_row: Controller<VotingRowModel>,
thumbnail_height: i32,
}
@ -48,6 +52,7 @@ pub enum PostPageInput {
DeletePost,
DoneEditPost(PostView),
PassAppMessage(crate::AppMsg),
ShowReportDialog,
}
#[relm4::component(pub)]
@ -189,6 +194,12 @@ impl SimpleComponent for PostPage {
#[watch]
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]
@ -208,7 +219,7 @@ impl SimpleComponent for PostPage {
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()
let create_comment_dialog = EditorDialog::builder()
.transient_for(root)
.launch(EditorType::Comment)
.forward(sender.input_sender(), |msg| match msg {
@ -220,6 +231,10 @@ impl SimpleComponent for PostPage {
let voting_row = VotingRowModel::builder()
.launch(VotingStats::default())
.detach();
let report_post_dialog = ReportDialog::builder()
.transient_for(root)
.launch((None, None))
.detach();
let model = PostPage {
info: init,
@ -227,7 +242,8 @@ impl SimpleComponent for PostPage {
comments,
creator_avatar,
community_avatar,
create_comment_dialog: dialog,
create_comment_dialog,
report_post_dialog,
voting_row,
thumbnail_height: 400,
};
@ -394,6 +410,13 @@ impl SimpleComponent for PostPage {
PostPageInput::PassAppMessage(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);
}
}
}
}

View File

@ -186,7 +186,6 @@ impl FactoryComponent for PostRow {
}
None => unreachable!(),
}
println!("size {}", self.image_size);
let thumbnail = self.thumbnail.widget();
let author_image = self.author_image.widget();
let community_image = self.community_image.widget();

View File

@ -49,6 +49,8 @@ impl SimpleComponent for ReportDialog {
set_margin_top: 10,
set_margin_bottom: 10,
set_label: "Report",
set_hexpand: false,
set_halign: gtk::Align::End,
connect_clicked[report_message] => move |_| {
let reason = report_message.text().to_string();
ReportDialogInput::Report(reason);