From: Olaf Wintermann Date: Tue, 9 Jun 2026 17:23:26 +0000 (+0200) Subject: simplify note title updates X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=e5cd9889276cb8aa21ca7d5bceeddb37453b0ccf;p=note.git simplify note title updates --- diff --git a/application/src/backend.rs b/application/src/backend.rs index 52f5479..2bf5710 100644 --- a/application/src/backend.rs +++ b/application/src/backend.rs @@ -46,7 +46,7 @@ impl Clone for BackendHandle { #[derive(Clone)] pub enum BroadcastMessage { NotebookStructureUpdate(Vec), - 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, - pub content: bool, -} - -#[derive(Clone, Default)] -pub struct NotesUpdate { +pub struct NoteTitleUpdate { pub collection_id: i32, - pub note_updates: Vec, -} - -impl NotesUpdate { - pub fn new(collection_id: i32, note_updates: Vec) -> Self { - NotesUpdate { - collection_id: collection_id, - note_updates: note_updates, - } - } + pub note_id: NoteId, + pub title: String, } diff --git a/application/src/note.rs b/application/src/note.rs index 9065c7d..65cb9f5 100644 --- a/application/src/note.rs +++ b/application/src/note.rs @@ -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 { diff --git a/application/src/notebook.rs b/application/src/notebook.rs index 6792e36..9d808a1 100644 --- a/application/src/notebook.rs +++ b/application/src/notebook.rs @@ -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 = 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 = 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 diff --git a/application/src/window.rs b/application/src/window.rs index 5e39213..f8ef673 100644 --- a/application/src/window.rs +++ b/application/src/window.rs @@ -248,7 +248,7 @@ pub fn create_window(app: &App, ctx: &AppContext) -> UiObject