diff --git a/src/chat/chat_panel.rs b/src/chat/chat_panel.rs index 8ee8f7e5..9ec9c384 100644 --- a/src/chat/chat_panel.rs +++ b/src/chat/chat_panel.rs @@ -507,19 +507,6 @@ impl WidgetMatchEvent for ChatPanel { _ => {} } - if let ChatPanelAction::UnloadIfActive(file_id) = action.cast() { - if store - .chats - .loaded_model - .as_ref() - .map_or(false, |file| file.id == file_id) - { - store.chats.eject_model().expect("Failed to eject model"); - self.redraw(cx); - //self.unload_model(cx); - } - } - match action.cast() { ChatLineAction::Delete(id) => { store.chats.delete_chat_message(id); @@ -953,7 +940,6 @@ impl ChatPanel { #[derive(Clone, DefaultNone, Debug)] pub enum ChatPanelAction { - UnloadIfActive(FileID), NavigateToDiscover, None, } diff --git a/src/chat/model_selector.rs b/src/chat/model_selector.rs index 0367e22f..f4c6885e 100644 --- a/src/chat/model_selector.rs +++ b/src/chat/model_selector.rs @@ -483,10 +483,6 @@ impl ModelSelector { } } -// fn options_to_display(store: &Store) -> bool { -// !store.downloads.downloaded_files.is_empty() -// } - fn no_active_model(store: &Store) -> bool { let chat_entity = store .chats diff --git a/src/data/chats/mod.rs b/src/data/chats/mod.rs index e6aff2a6..a35ebbc6 100644 --- a/src/data/chats/mod.rs +++ b/src/data/chats/mod.rs @@ -150,6 +150,18 @@ impl Chats { Ok(()) } + pub fn remove_file_from_associated_entity(&mut self, file_id: &FileID) { + for chat in &self.saved_chats { + let mut chat = chat.borrow_mut(); + if let Some(ChatEntity::ModelFile(chat_file_id)) = &chat.associated_entity { + if chat_file_id == file_id { + chat.associated_entity = None; + chat.save(); + } + } + } + } + /// Get the file id to use with this chat, or the loaded file id as a fallback. /// The fallback is used if the chat does not have a file id set, or, if it has /// one but references a no longer existing (deleted) file. diff --git a/src/data/store.rs b/src/data/store.rs index 89cab999..c224e1dd 100644 --- a/src/data/store.rs +++ b/src/data/store.rs @@ -218,18 +218,16 @@ impl Store { .send(TestServer(tx.clone())) .expect("failed to update MoFa server address"); - std::thread::spawn(move || { - match rx.recv() { - Ok(TestServerResponse::Success(server_address)) => { - Cx::post_action(MoFaTestServerAction::Success(server_address)); - } - Ok(TestServerResponse::Failure(server_address)) => { - Cx::post_action(MoFaTestServerAction::Failure(Some(server_address))); - } - Err(e) => { - println!("Error receiving response from MoFa backend: {:?}", e); - Cx::post_action(MoFaTestServerAction::Failure(None)); - } + std::thread::spawn(move || match rx.recv() { + Ok(TestServerResponse::Success(server_address)) => { + Cx::post_action(MoFaTestServerAction::Success(server_address)); + } + Ok(TestServerResponse::Failure(server_address)) => { + Cx::post_action(MoFaTestServerAction::Failure(Some(server_address))); + } + Err(e) => { + println!("Error receiving response from MoFa backend: {:?}", e); + Cx::post_action(MoFaTestServerAction::Failure(None)); } }); } @@ -330,6 +328,16 @@ impl Store { } pub fn delete_file(&mut self, file_id: FileID) -> Result<()> { + if self + .chats + .loaded_model + .as_ref() + .map_or(false, |file| file.id == file_id) + { + self.chats.eject_model().expect("Failed to eject model"); + } + + self.chats.remove_file_from_associated_entity(&file_id); self.downloads.delete_file(file_id.clone())?; self.search .update_downloaded_file_in_search_results(&file_id, false); @@ -408,4 +416,4 @@ impl Store { // support having no chat selected self.init_current_chat(); } -} \ No newline at end of file +} diff --git a/src/my_models/delete_model_modal.rs b/src/my_models/delete_model_modal.rs index 34204c03..8e356939 100644 --- a/src/my_models/delete_model_modal.rs +++ b/src/my_models/delete_model_modal.rs @@ -184,11 +184,7 @@ impl WidgetMatchEvent for DeleteModelModal { .clicked(actions) { let store = scope.data.get_mut::().unwrap(); - cx.widget_action( - widget_uid, - &scope.path, - ChatPanelAction::UnloadIfActive(self.file_id.clone()), - ); + store .delete_file(self.file_id.clone()) .expect("Failed to delete file");