]> uap-core.de Git - note.git/commitdiff
add reload_collections command
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 17 May 2026 11:03:05 +0000 (13:03 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 17 May 2026 11:03:05 +0000 (13:03 +0200)
application/src/backend.rs

index 7318c0585693ab00280c6368a4859595ade5cd16..a2bf39df3bcdb9d731aa29f0d7e84340194c93ed 100644 (file)
@@ -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<Runtime>,
@@ -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<Self>, backend: Arc<Backend>) -> 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