From 81205f1ec52aac1f80d177ac860861b8e7029391 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sun, 17 May 2026 13:03:05 +0200 Subject: [PATCH] add reload_collections command --- application/src/backend.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) 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 -- 2.47.3