-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete Chat Modal #137
Merged
Merged
Delete Chat Modal #137
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = <RoundedView> { | ||
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 | ||
} | ||
|
||
<View> { | ||
width: Fill, | ||
height: Fit, | ||
flow: Right | ||
|
||
padding: {top: 8, bottom: 20} | ||
|
||
title = <View> { | ||
width: Fit, | ||
height: Fit, | ||
|
||
<Label> { | ||
text: "Delete Chat" | ||
draw_text: { | ||
text_style: <BOLD_FONT>{font_size: 13}, | ||
color: #000 | ||
} | ||
} | ||
} | ||
|
||
filler_x = <View> {width: Fill, height: Fit} | ||
|
||
close_button = <MoxinButton> { | ||
width: Fit, | ||
height: Fit, | ||
|
||
margin: {top: -8} | ||
|
||
draw_icon: { | ||
svg_file: (ICON_CLOSE), | ||
fn get_color(self) -> vec4 { | ||
return #000; | ||
} | ||
} | ||
icon_walk: {width: 12, height: 12} | ||
} | ||
} | ||
|
||
body = <View> { | ||
width: Fill, | ||
height: Fit, | ||
flow: Down, | ||
spacing: 40, | ||
|
||
delete_prompt = <Label> { | ||
width: Fill | ||
draw_text: { | ||
text_style: <REGULAR_FONT>{ | ||
font_size: 10, | ||
height_factor: 1.3 | ||
}, | ||
color: #000 | ||
wrap: Word | ||
} | ||
} | ||
|
||
actions = <View> { | ||
width: Fill, height: Fit | ||
flow: Right, | ||
align: {x: 1.0, y: 0.5} | ||
spacing: 20 | ||
|
||
cancel_button = <MoxinButton> { | ||
width: Fit, | ||
height: Fit, | ||
padding: {top: 10, bottom: 10, left: 14, right: 14} | ||
|
||
draw_bg: { | ||
instance radius: 2.0, | ||
border_color: #D0D5DD, | ||
border_width: 1.2, | ||
color: #fff, | ||
} | ||
|
||
text: "Cancel" | ||
draw_text:{ | ||
text_style: <REGULAR_FONT>{font_size: 10}, | ||
color: #x0 | ||
} | ||
} | ||
|
||
delete_button = <MoxinButton> { | ||
width: Fit, | ||
height: Fit, | ||
padding: {top: 10, bottom: 10, left: 14, right: 14} | ||
|
||
draw_bg: { | ||
instance radius: 2.0, | ||
color: #D92D20, | ||
} | ||
|
||
text: "Delete" | ||
draw_text:{ | ||
text_style: <REGULAR_FONT>{font_size: 10}, | ||
color: #fff | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, DefaultNone, Debug)] | ||
pub enum DeleteChatAction { | ||
ChatSelected(ChatID), | ||
None, | ||
} | ||
|
||
#[derive(Live, LiveHook, Widget)] | ||
pub struct DeleteChatModal { | ||
#[deref] | ||
view: View, | ||
#[rust] | ||
chat_id: ChatID, | ||
} | ||
|
||
impl Widget for DeleteChatModal { | ||
fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) { | ||
self.view.handle_event(cx, event, scope); | ||
self.widget_match_event(cx, event, scope); | ||
} | ||
|
||
fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep { | ||
let chat_title = scope | ||
.data | ||
.get::<Store>() | ||
.unwrap() | ||
.chats | ||
.saved_chats | ||
.iter() | ||
.map(|chat| chat.borrow()) | ||
.find(|chat| chat.id == self.chat_id) | ||
.unwrap() | ||
.get_title() | ||
.to_string(); | ||
|
||
let prompt_text = format!( | ||
"Are you sure you want to delete {}?\nThis action cannot be undone.", | ||
chat_title | ||
); | ||
self.label(id!(wrapper.body.delete_prompt)) | ||
.set_text(&prompt_text); | ||
|
||
self.view | ||
.draw_walk(cx, scope, walk.with_abs_pos(DVec2 { x: 0., y: 0. })) | ||
} | ||
} | ||
|
||
impl WidgetMatchEvent for DeleteChatModal { | ||
fn handle_actions(&mut self, cx: &mut Cx, actions: &Actions, scope: &mut Scope) { | ||
let widget_uid = self.widget_uid(); | ||
|
||
if self.button(id!(close_button)).clicked(actions) { | ||
cx.widget_action(widget_uid, &scope.path, PortalAction::Close); | ||
} | ||
|
||
if self | ||
.button(id!(wrapper.body.actions.delete_button)) | ||
.clicked(actions) | ||
{ | ||
let store = scope.data.get_mut::<Store>().unwrap(); | ||
store.delete_chat(self.chat_id); | ||
cx.widget_action(widget_uid, &scope.path, PortalAction::Close); | ||
cx.redraw_all(); | ||
} | ||
|
||
if self | ||
.button(id!(wrapper.body.actions.cancel_button)) | ||
.clicked(actions) | ||
{ | ||
cx.widget_action(widget_uid, &scope.path, PortalAction::Close); | ||
} | ||
} | ||
} | ||
|
||
impl DeleteChatModalRef { | ||
pub fn set_chat_id(&mut self, chat_id: ChatID) { | ||
if let Some(mut inner) = self.borrow_mut() { | ||
inner.chat_id = chat_id; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tell makepad to fully redraw to incorporate the changes from the store.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love this (because it's very rare you need to redraw the entire visible application, e.g. resizing), but I get that you're avoiding the creation of some kind of action to listen to and redraw in the relevant parts of the UI.
I think is fine for now, eventually we could add metadata to the
PortalAction::Close
action (so we listen to the right one) and redraw based on that.