summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-22 18:30:14 +0300
committerVika <vika@fireburn.ru>2024-08-22 18:30:14 +0300
commit2bd15a7d832bb49c9a5a43eb9475dde1cb4696b3 (patch)
tree9e5eb3ba98a261ff446f79e83f31105e06f0e147 /src/lib.rs
parent7a1b818d1edf5347d8215e164edf77e4210fa4dd (diff)
downloadbowl-2bd15a7d832bb49c9a5a43eb9475dde1cb4696b3.tar.zst
SmartSummaryButton: un-asyncify and move summarization to a command
What this command should do is construct a summarization request and
return a future which would return chunks from the LLM.

Perhaps this component will be asyncified in the future.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 244c09f..8e73a33 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,7 +2,7 @@ use std::sync::Arc;
 
 use adw::prelude::*;
 use gtk::GridLayoutChild;
-use relm4::{gtk, prelude::{AsyncComponent, AsyncComponentController, AsyncComponentParts, AsyncController}, AsyncComponentSender, RelmWidgetExt};
+use relm4::{gtk, prelude::{AsyncComponent, AsyncComponentController, AsyncComponentParts, AsyncController, ComponentController, Controller}, AsyncComponentSender, Component, RelmWidgetExt};
 
 pub mod components {
     pub(crate) mod smart_summary;
@@ -35,7 +35,7 @@ pub struct PostComposerModel {
 
     #[do_not_track] micropub: Arc<micropub::Client>,
 
-    #[do_not_track] smart_summary: AsyncController<components::SmartSummaryButton>,
+    #[do_not_track] smart_summary: Controller<components::SmartSummaryButton>,
 }
 
 impl PostComposerModel {
@@ -342,18 +342,28 @@ impl AsyncComponent for PostComposerModel {
 
         match message {
             PostComposerInput::SmartSummary(components::SmartSummaryOutput::Start) => {
-                self.set_smart_summary_busy_guard(
-                    Some(relm4::main_adw_application().mark_busy())
-                );
-                if self.smart_summary.sender().send(components::SmartSummaryInput::Text(
-                    self.content_buffer.text(
+                widgets.content_textarea.set_sensitive(false);
+                if self.content_buffer.char_count() == 0 {
+                    let _ = self.smart_summary.sender().send(
+                        components::SmartSummaryInput::Cancel
+                    );
+                } else {
+                    let text = self.content_buffer.text(
                         &self.content_buffer.start_iter(),
                         &self.content_buffer.end_iter(),
                         false
-                    ).into()
-                )).is_ok() {
-                    self.summary_buffer.set_text("");
+                    );
+
+                    self.set_smart_summary_busy_guard(
+                        Some(relm4::main_adw_application().mark_busy())
+                    );
+                    if self.smart_summary.sender().send(
+                        components::SmartSummaryInput::Text(text.into())
+                    ).is_ok() {
+                        self.summary_buffer.set_text("");
+                    }
                 }
+                widgets.content_textarea.set_sensitive(true);
             },
             PostComposerInput::SmartSummary(components::SmartSummaryOutput::Chunk(text)) => {
                 self.summary_buffer.insert_text(self.summary_buffer.length(), text);