diff --git a/src/app.rs b/src/app.rs index c17f5ac1..637597d0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,4 +1,5 @@ use crate::chat::chat_panel::ChatPanelAction; +use crate::chat::delete_chat_modal::{DeleteChatAction, DeleteChatModalWidgetRefExt}; use crate::data::downloads::DownloadPendingNotification; use crate::data::store::*; use crate::landing::model_card::{ModelCardViewAllModalWidgetRefExt, ViewAllModalAction}; @@ -27,6 +28,7 @@ live_design! { import crate::chat::chat_screen::ChatScreen; import crate::my_models::my_models_screen::MyModelsScreen; import crate::my_models::delete_model_modal::DeleteModelModal; + import crate::chat::delete_chat_modal::DeleteChatModal; import crate::my_models::model_info_modal::ModelInfoModal; @@ -116,6 +118,14 @@ live_design! { } } + modal_delete_chat_portal_view = { + modal = { + content = { + delete_chat_modal = {} + } + } + } + modal_model_info_portal_view = { modal = { content = { @@ -250,6 +260,15 @@ impl MatchEvent for App { self.ui.redraw(cx); } + // Set modal viewall model id + if let DeleteChatAction::ChatSelected(chat_id) = action.as_widget_action().cast() { + let mut modal = self.ui.delete_chat_modal(id!(delete_chat_modal)); + modal.set_chat_id(chat_id); + // TODO: Hack for error that when you first open the modal, doesnt draw until an event + // this forces the entire ui to rerender, still weird that only happens the first time. + self.ui.redraw(cx); + } + if let ModelInfoAction::FileSelected(file_id) = action.as_widget_action().cast() { let mut modal = self.ui.model_info_modal(id!(model_info_modal)); modal.set_file_id(file_id); diff --git a/src/chat/chat_history_card.rs b/src/chat/chat_history_card.rs index f0709643..90312d6b 100644 --- a/src/chat/chat_history_card.rs +++ b/src/chat/chat_history_card.rs @@ -1,8 +1,13 @@ -use crate::data::{chats::chat::ChatID, store::Store}; +use crate::{ + data::{chats::chat::ChatID, store::Store}, + shared::portal::PortalAction, +}; use chrono::{DateTime, Local, NaiveDateTime, TimeZone}; use makepad_widgets::*; +use super::delete_chat_modal::DeleteChatAction; + live_design! { import makepad_widgets::base::*; import makepad_widgets::theme_desktop_dark::*; @@ -177,8 +182,16 @@ impl WidgetMatchEvent for ChatHistoryCard { let widget_uid = self.widget_uid(); if self.button(id!(delete_chat)).clicked(actions) { - store.delete_chat(self.chat_id); - self.redraw(cx); + cx.widget_action( + widget_uid, + &scope.path, + DeleteChatAction::ChatSelected(self.chat_id), + ); + cx.widget_action( + widget_uid, + &scope.path, + PortalAction::ShowPortalView(live_id!(modal_delete_chat_portal_view)), + ); return; } diff --git a/src/chat/delete_chat_modal.rs b/src/chat/delete_chat_modal.rs new file mode 100644 index 00000000..76ad1a95 --- /dev/null +++ b/src/chat/delete_chat_modal.rs @@ -0,0 +1,217 @@ +use makepad_widgets::*; + +use crate::{ + chat::chat_panel::ChatPanelAction, + data::{chats::chat::ChatID, store::Store}, + shared::portal::PortalAction, +}; + +live_design! { + import makepad_widgets::base::*; + import makepad_widgets::theme_desktop_dark::*; + import makepad_draw::shader::std::*; + + import crate::shared::styles::*; + import crate::shared::widgets::MoxinButton; + import crate::shared::resource_imports::*; + + DeleteChatModal = {{DeleteChatModal}} { + width: Fit + height: Fit + + wrapper = { + flow: Down + width: 600 + height: Fit + padding: {top: 44, right: 30 bottom: 30 left: 50} + spacing: 10 + + show_bg: true + draw_bg: { + color: #fff + radius: 3 + } + + { + width: Fill, + height: Fit, + flow: Right + + padding: {top: 8, bottom: 20} + + title = { + width: Fit, + height: Fit, + +