From: Olaf Wintermann Date: Sun, 17 May 2026 11:03:05 +0000 (+0200) Subject: add reload_collections command X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=HEAD;p=note.git add reload_collections command --- diff --git a/application/src/backend.rs b/application/src/backend.rs index 7318c05..a2bf39d 100644 --- a/application/src/backend.rs +++ b/application/src/backend.rs @@ -9,7 +9,7 @@ use ui_rs::ui; use entity::{collection, profile}; use entity::profile::Entity as Profile; -use entity::collection::{CollectionType, Entity as Collection, Node}; +use entity::collection::{create_notebook_hierarchy, CollectionType, Entity as Collection, Node}; pub struct Backend { rt: Arc, @@ -193,3 +193,36 @@ impl Backend { } } } + +impl BackendHandle { + pub fn reload_collections(&self) { + let cmd: DynCmd = Box::new(ReloadCollectionsCmd); + let _ = self.tx.send(cmd); + } +} + + +struct ReloadCollectionsCmd; + +impl Cmd for ReloadCollectionsCmd { + fn run(self: Box, backend: Arc) -> CmdFuture { + Box::pin(async move { + println!("reloading collections..."); + + let profile_id = backend.current_profile.as_ref().unwrap().id; + + let result = Collection::find() + .filter(collection::Column::ProfileId.eq(profile_id)) + .order_by_asc(collection::Column::Parent) + .all(&backend.db).await; + + if let Ok(collection) = result { + let nodes = create_notebook_hierarchy(collection); + if let Some(tx) = backend.broadcast.as_ref() { + let _ = tx.send(BroadcastMessage::NotebookStructureUpdate(nodes)); + ui::broadcast_action("message"); + } + } + }) + } +} \ No newline at end of file