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>,
}
}
}
+
+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