1use gpui::{App, Context, DismissEvent, EventEmitter, FocusHandle, Focusable, Render, Window};
2use ui::{IconPosition, prelude::*};
3use workspace::{ModalView, Workspace};
4use zed_actions::feedback::GiveFeedback;
5
6use crate::{EmailZed, FileBugReport, OpenZedRepo, RequestFeature};
7
8pub struct FeedbackModal {
9 focus_handle: FocusHandle,
10}
11
12impl Focusable for FeedbackModal {
13 fn focus_handle(&self, _: &App) -> FocusHandle {
14 self.focus_handle.clone()
15 }
16}
17impl EventEmitter<DismissEvent> for FeedbackModal {}
18
19impl ModalView for FeedbackModal {}
20
21impl FeedbackModal {
22 pub fn register(workspace: &mut Workspace, _: &mut Window, cx: &mut Context<Workspace>) {
23 let _handle = cx.entity().downgrade();
24 workspace.register_action(move |workspace, _: &GiveFeedback, window, cx| {
25 workspace.toggle_modal(window, cx, move |_, cx| FeedbackModal::new(cx));
26 });
27 }
28
29 pub fn new(cx: &mut Context<Self>) -> Self {
30 Self {
31 focus_handle: cx.focus_handle(),
32 }
33 }
34
35 fn cancel(&mut self, _: &menu::Cancel, _: &mut Window, cx: &mut Context<Self>) {
36 cx.emit(DismissEvent)
37 }
38}
39
40impl Render for FeedbackModal {
41 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
42 let open_zed_repo =
43 cx.listener(|_, _, window, cx| window.dispatch_action(Box::new(OpenZedRepo), cx));
44
45 v_flex()
46 .key_context("GiveFeedback")
47 .on_action(cx.listener(Self::cancel))
48 .elevation_3(cx)
49 .w_96()
50 .h_auto()
51 .p_4()
52 .gap_2()
53 .child(
54 h_flex()
55 .w_full()
56 .justify_between()
57 .child(Headline::new("Give Feedback"))
58 .child(
59 IconButton::new("close-btn", IconName::Close)
60 .icon_color(Color::Muted)
61 .on_click(cx.listener(move |_, _, window, cx| {
62 cx.spawn_in(window, async move |this, cx| {
63 this.update(cx, |_, cx| cx.emit(DismissEvent)).ok();
64 })
65 .detach();
66 })),
67 ),
68 )
69 .child(Label::new("Thanks for using Zed! To share your experience with us, reach for the channel that's the most appropriate:"))
70 .child(
71 Button::new("file-a-bug-report", "File a Bug Report")
72 .full_width()
73 .icon(IconName::Debug)
74 .icon_size(IconSize::XSmall)
75 .icon_color(Color::Muted)
76 .icon_position(IconPosition::Start)
77 .on_click(cx.listener(|_, _, window, cx| {
78 window.dispatch_action(Box::new(FileBugReport), cx);
79 })),
80 )
81 .child(
82 Button::new("request-a-feature", "Request a Feature")
83 .full_width()
84 .icon(IconName::Sparkle)
85 .icon_size(IconSize::XSmall)
86 .icon_color(Color::Muted)
87 .icon_position(IconPosition::Start)
88 .on_click(cx.listener(|_, _, window, cx| {
89 window.dispatch_action(Box::new(RequestFeature), cx);
90 })),
91 )
92 .child(
93 Button::new("send-us_an-email", "Send an Email")
94 .full_width()
95 .icon(IconName::Envelope)
96 .icon_size(IconSize::XSmall)
97 .icon_color(Color::Muted)
98 .icon_position(IconPosition::Start)
99 .on_click(cx.listener(|_, _, window, cx| {
100 window.dispatch_action(Box::new(EmailZed), cx);
101 })),
102 )
103 .child(
104 Button::new("zed_repository", "GitHub Repository")
105 .full_width()
106 .icon(IconName::Github)
107 .icon_size(IconSize::XSmall)
108 .icon_color(Color::Muted)
109 .icon_position(IconPosition::Start)
110 .on_click(open_zed_repo),
111 )
112 }
113}