summary refs log tree commit diff
path: root/src/components/post_editor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/post_editor.rs')
-rw-r--r--src/components/post_editor.rs45
1 files changed, 30 insertions, 15 deletions
diff --git a/src/components/post_editor.rs b/src/components/post_editor.rs
index f2268ad..c42b06a 100644
--- a/src/components/post_editor.rs
+++ b/src/components/post_editor.rs
@@ -1,11 +1,12 @@
 use gettextrs::*;
-use crate::components;
 use crate::components::tag_pill::*;
 use adw::prelude::*;
 
 use glib::translate::IntoGlib;
 use gtk::GridLayoutChild;
-use relm4::{gtk, prelude::{ComponentController, Controller, DynamicIndex}, factory::FactoryVecDeque, Component, ComponentParts, ComponentSender, RelmWidgetExt};
+use relm4::{factory::FactoryVecDeque, gtk, prelude::{Controller, DynamicIndex}, Component, ComponentParts, ComponentSender, RelmWidgetExt};
+#[cfg(feature = "smart-summary")]
+use relm4::prelude::ComponentController;
 
 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, glib::Enum)]
 #[enum_type(name = "MicropubVisibility")]
@@ -87,7 +88,8 @@ pub(crate) struct PostEditor<E> {
 
     #[do_not_track] wide_layout: gtk::GridLayout,
 
-    #[do_not_track] smart_summary: Controller<components::SmartSummaryButton>,
+    #[cfg(feature = "smart-summary")]
+    #[do_not_track] smart_summary: Controller<crate::components::SmartSummaryButton>,
     _err: std::marker::PhantomData<E>
 }
 
@@ -104,7 +106,8 @@ impl<E> PostEditor<E> {
 #[allow(private_interfaces)] // intentional
 #[allow(clippy::manual_non_exhaustive)] // false positive
 pub enum Input<E: std::error::Error + std::fmt::Debug + Send + 'static> {
-    #[doc(hidden)] SmartSummary(components::smart_summary::Output),
+    #[cfg(feature = "smart-summary")]
+    #[doc(hidden)] SmartSummary(crate::components::smart_summary::Output),
     #[doc(hidden)] VisibilitySelected(Visibility),
     #[doc(hidden)] AddTagFromBuffer,
     #[doc(hidden)] RemoveTag(DynamicIndex),
@@ -115,7 +118,10 @@ pub enum Input<E: std::error::Error + std::fmt::Debug + Send + 'static> {
 
 #[relm4::component(pub)]
 impl<E: std::error::Error + std::fmt::Debug + Send + 'static> Component for PostEditor<E> {
-    type Init = (<components::SmartSummaryButton as relm4::Component>::Init, Option<Post>);
+    #[cfg(feature = "smart-summary")]
+    type Init = (soup::Session, Option<Post>);
+    #[cfg(not(feature = "smart-summary"))]
+    type Init = Option<Post>;
     type Output = Option<Post>;
     type Input = Input<E>;
     type CommandOutput = ();
@@ -169,8 +175,6 @@ impl<E: std::error::Error + std::fmt::Debug + Send + 'static> Component for Post
                                 #[track = "model.busy_changed()"]
                                 set_sensitive: !model.busy(),
                             },
-
-                            model.smart_summary.widget(),
                         },
 
                         #[name = "tag_label"]
@@ -331,10 +335,13 @@ impl<E: std::error::Error + std::fmt::Debug + Send + 'static> Component for Post
     }
 
     fn init(
-        (http, init): Self::Init,
+        init: Self::Init,
         root: Self::Root,
         sender: ComponentSender<Self>
     ) -> ComponentParts<Self> {
+        #[cfg(feature = "smart-summary")]
+        let (http, init) = init;
+
         let mut model = Self {
             smart_summary_busy_guard: None,
             sending: false,
@@ -359,7 +366,8 @@ impl<E: std::error::Error + std::fmt::Debug + Send + 'static> Component for Post
 
             wide_layout: gtk::GridLayout::new(),
 
-            smart_summary: components::SmartSummaryButton::builder()
+            #[cfg(feature = "smart-summary")]
+            smart_summary: crate::components::SmartSummaryButton::builder()
                 .launch(http)
                 .forward(sender.input_sender(), Input::SmartSummary),
 
@@ -371,6 +379,9 @@ impl<E: std::error::Error + std::fmt::Debug + Send + 'static> Component for Post
 
         let widgets = view_output!();
 
+        #[cfg(feature = "smart-summary")]
+        widgets.summary_field.append(model.smart_summary.widget());
+
         widgets.visibility_selector.set_expression(Some(
             gtk::ClosureExpression::new::<String>(
                 [] as [gtk::Expression; 0],
@@ -459,11 +470,12 @@ impl<E: std::error::Error + std::fmt::Debug + Send + 'static> Component for Post
     fn update_with_view(&mut self, widgets: &mut Self::Widgets, msg: Self::Input, sender: ComponentSender<Self>, root: &Self::Root) {
         self.reset();
         match msg {
-            Input::SmartSummary(components::SmartSummaryOutput::Start) => {
+            #[cfg(feature = "smart-summary")]
+            Input::SmartSummary(crate::components::SmartSummaryOutput::Start) => {
                 widgets.content_textarea.set_sensitive(false);
                 if self.content_buffer.char_count() == 0 {
                     let _ = self.smart_summary.sender().send(
-                        components::SmartSummaryInput::Cancel
+                        crate::components::SmartSummaryInput::Cancel
                     );
                 } else {
                     let text = self.content_buffer.text(
@@ -476,20 +488,23 @@ impl<E: std::error::Error + std::fmt::Debug + Send + 'static> Component for Post
                         Some(relm4::main_adw_application().mark_busy())
                     );
                     if self.smart_summary.sender().send(
-                        components::SmartSummaryInput::Text(text.into())
+                        crate::components::SmartSummaryInput::Text(text.into())
                     ).is_ok() {
                         self.summary_buffer.set_text("");
                     }
                 }
                 widgets.content_textarea.set_sensitive(true);
             },
-            Input::SmartSummary(components::SmartSummaryOutput::Chunk(text)) => {
+            #[cfg(feature = "smart-summary")]
+            Input::SmartSummary(crate::components::SmartSummaryOutput::Chunk(text)) => {
                 self.summary_buffer.insert_text(self.summary_buffer.length(), text);
             },
-            Input::SmartSummary(components::SmartSummaryOutput::Done) => {
+            #[cfg(feature = "smart-summary")]
+            Input::SmartSummary(crate::components::SmartSummaryOutput::Done) => {
                 self.set_smart_summary_busy_guard(None);
             },
-            Input::SmartSummary(components::SmartSummaryOutput::Error(err)) => {
+            #[cfg(feature = "smart-summary")]
+            Input::SmartSummary(crate::components::SmartSummaryOutput::Error(err)) => {
                 self.set_smart_summary_busy_guard(None);
 
                 let toast = adw::Toast::new(&gettext!("Smart Summary error: {}", err));