1use client::User;
2use gpui::{
3 actions, ElementBox, Entity, ModelHandle, MutableAppContext, RenderContext, View, ViewContext,
4};
5use project::Project;
6use std::sync::Arc;
7use workspace::Notification;
8
9use crate::notifications::render_user_notification;
10
11pub fn init(cx: &mut MutableAppContext) {
12 cx.add_action(JoinProjectNotification::decline);
13 cx.add_action(JoinProjectNotification::accept);
14}
15
16pub enum Event {
17 Dismiss,
18}
19
20actions!(contacts_panel, [Accept, Decline]);
21
22pub struct JoinProjectNotification {
23 project: ModelHandle<Project>,
24 user: Arc<User>,
25}
26
27impl JoinProjectNotification {
28 pub fn new(project: ModelHandle<Project>, user: Arc<User>) -> Self {
29 Self { project, user }
30 }
31
32 fn decline(&mut self, _: &Decline, cx: &mut ViewContext<Self>) {
33 self.project.update(cx, |project, cx| {
34 project.respond_to_join_request(self.user.id, false, cx)
35 });
36 cx.emit(Event::Dismiss)
37 }
38
39 fn accept(&mut self, _: &Accept, cx: &mut ViewContext<Self>) {
40 self.project.update(cx, |project, cx| {
41 project.respond_to_join_request(self.user.id, true, cx)
42 });
43 cx.emit(Event::Dismiss)
44 }
45}
46
47impl Entity for JoinProjectNotification {
48 type Event = Event;
49}
50
51impl View for JoinProjectNotification {
52 fn ui_name() -> &'static str {
53 "JoinProjectNotification"
54 }
55
56 fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
57 render_user_notification(
58 self.user.clone(),
59 "wants to join your project",
60 None,
61 Decline,
62 vec![("Decline", Box::new(Decline)), ("Accept", Box::new(Accept))],
63 cx,
64 )
65 }
66}
67
68impl Notification for JoinProjectNotification {
69 fn should_dismiss_notification_on_event(&self, event: &<Self as Entity>::Event) -> bool {
70 matches!(event, Event::Dismiss)
71 }
72}