]> uap-core.de Git - note.git/commitdiff
simplify note title updates main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 9 Jun 2026 17:23:26 +0000 (19:23 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 9 Jun 2026 17:23:26 +0000 (19:23 +0200)
application/src/backend.rs
application/src/note.rs
application/src/notebook.rs
application/src/window.rs

index 52f54799f9bafb53cf0c512f9826557217294dca..2bf57107f8567621db3a44ab7269a0bebbdfe1ae 100644 (file)
@@ -46,7 +46,7 @@ impl Clone for BackendHandle {
 #[derive(Clone)]
 pub enum BroadcastMessage {
     NotebookStructureUpdate(Vec<Node>),
-    NotesUpdate(NotesUpdate),
+    NoteTitleUpdate(NoteTitleUpdate),
 }
 
 #[derive(Clone, PartialEq, Eq)]
@@ -62,25 +62,10 @@ impl Default for NoteId {
 }
 
 #[derive(Clone, Default)]
-pub struct NoteUpdate {
-    pub note_id: NoteId,
-    pub title: Option<String>,
-    pub content: bool,
-}
-
-#[derive(Clone, Default)]
-pub struct NotesUpdate {
+pub struct NoteTitleUpdate {
     pub collection_id: i32,
-    pub note_updates: Vec<NoteUpdate>,
-}
-
-impl NotesUpdate {
-    pub fn new(collection_id: i32, note_updates: Vec<NoteUpdate>) -> Self {
-        NotesUpdate {
-            collection_id: collection_id,
-            note_updates: note_updates,
-        }
-    }
+    pub note_id: NoteId,
+    pub title: String,
 }
 
 
index 9065c7d1122a9b1ce3aeebc2cbf8e04782b94a42..65cb9f573076df91f17b205e9118c79c11d02bc3 100644 (file)
@@ -5,7 +5,7 @@ use sea_orm::{NotSet, Set};
 use entity::note::NoteType;
 use ui_rs::{action, ui_actions, UiModel};
 use ui_rs::ui::*;
-use crate::backend::{BackendHandle, BroadcastMessage, NoteId, NoteUpdate, NotesUpdate};
+use crate::backend::{BackendHandle, BroadcastMessage, NoteId, NoteTitleUpdate};
 use crate::window::NoteTypeTabView;
 
 static TMP_ID: AtomicU64 = AtomicU64::new(1);
@@ -108,13 +108,12 @@ impl Note {
                 self.title_end = result.1 as i32 + title.len() as i32;
 
                 if notify {
-                    let update = NoteUpdate {
+                    let update = NoteTitleUpdate {
+                        collection_id: self.collection_id,
                         note_id: self.id.clone(),
-                        title: Some(title.to_string()),
-                        ..Default::default()
+                        title: title.to_string(),
                     };
-                    let msg = NotesUpdate::new(self.collection_id, vec![update]);
-                    _ = self.backend.as_ref().send_broadcast(BroadcastMessage::NotesUpdate(msg));
+                    _ = self.backend.as_ref().send_broadcast(BroadcastMessage::NoteTitleUpdate(update));
                 }
             },
             None => {
@@ -141,7 +140,7 @@ impl Note {
         let content = self.text.get();
         let title = match generate_title(content.as_str()) {
             Some(title) => title.0.to_string(),
-            None => "New Note".to_string()
+            None => "New Note".to_string() // TODO: see NoteItem::new()
         };
 
         let (note_id, created) = match &self.id {
index 6792e3663499ac5fd37418484497ed3fa8552ec5..9d808a1d6ef5806499da501d3df0573021981ae6 100644 (file)
@@ -4,7 +4,7 @@ use ui_rs::{action, ui_actions, UiModel};
 use ui_rs::ui::*;
 
 use entity::note::{Model as Note};
-use crate::backend::{BackendHandle, BroadcastMessage, NoteId, NoteUpdate};
+use crate::backend::{BackendHandle, BroadcastMessage, NoteId, NoteTitleUpdate};
 use crate::note::new_note_id;
 use crate::window::NavigationItem;
 
@@ -121,10 +121,7 @@ impl Notebook {
 
         if let Some(mut nb) = self.doc_ref.get_doc() {
             nb.ctx.attach(&doc);
-            //nb.ctx.call_action("textarea_focus");
-            nb.doc_proxy().call_mainthread(move |doc, note|{
-               doc.ctx.call_action("textarea_focus");
-            });
+            nb.ctx.call_action("textarea_focus");
             self.selected_note = Some(doc);
 
             if add_to_nav {
@@ -164,14 +161,14 @@ impl Notebook {
         self.select_note_from(NoteSelectFrom::NavigationItem(nav.clone()));
     }
 
-    pub fn update_note(&mut self, update: &NoteUpdate) {
+    pub fn update_note_title(&mut self, update: &NoteTitleUpdate) {
         // Find the note in the list (or add it if it doesn't exist yet)
         // Start with the currently selected note
         let mut update_row: Option<usize> = None;
         if let Some(index) = self.selected_index {
             if let Some(item) = self.notes.data_mut().get_mut(index) {
                 if item.id == update.note_id {
-                    item.update(&update);
+                    item.data.title = update.title.clone();
                     update_row = Some(index);
                 }
             }
@@ -180,7 +177,7 @@ impl Notebook {
         if update_row.is_none() {
             for (index, item) in self.notes.data_mut().iter_mut().enumerate() {
                 if item.id == update.note_id {
-                    item.update(&update);
+                    item.data.title = update.title.clone();
                     update_row = Some(index);
                     break;
                 }
@@ -196,26 +193,9 @@ impl Notebook {
     pub fn message(&mut self, _event: &ActionEvent) {
         while let Ok(msg) = self.broadcast_rx.try_recv() {
             match msg {
-                BroadcastMessage::NotesUpdate(update) => {
-                    if update.note_updates.len() == 1 {
-                        self.update_note(&update.note_updates[0]);
-                    } else if update.note_updates.len() > 1 {
-                        let mut update_rows: Vec<usize> = Vec::new();
-                        for u in &update.note_updates {
-                            if let NoteId::Id(id) = u.note_id {
-                                let note_data = self.notes.data_mut();
-                                for (i, note) in note_data.iter_mut().enumerate() {
-                                    if note.data.note_id == id {
-                                        note.update(u);
-                                        update_rows.push(i);
-                                    }
-                                }
-                            }
-                        }
-
-                        for i in update_rows {
-                            self.notes.update_row(i);
-                        }
+                BroadcastMessage::NoteTitleUpdate(update) => {
+                    if update.collection_id == self.collection_id {
+                        self.update_note_title(&update);
                     }
                 },
                 _ => {
@@ -330,11 +310,4 @@ impl NoteItem {
     pub fn is_new(&self) -> bool {
         return matches!(self.id, NoteId::TmpId(_))
     }
-
-    pub fn update(&mut self, update: &NoteUpdate) {
-        // update note
-        if let Some(title) = &update.title {
-            self.data.title = title.clone();
-        }
-    }
 }
\ No newline at end of file
index 5e392133f52e579ab688e7a82db31af8d86d6725..f8ef6734d1a9d07c8b1c8ed576677ec4617ff05d 100644 (file)
@@ -248,7 +248,7 @@ pub fn create_window(app: &App, ctx: &AppContext<MainWindow>) -> UiObject<MainWi
                             b.onchange_action("note_text_change");
                             b.ontextchanged_action("note_text_changed");
                         });
-                        obj.ctx.add_action_untyped("textarea_focus", move|event|{
+                        obj.ctx.add_action_untyped("textarea_focus", move|_event|{
                             textarea.focus();
                         });
                     });