Present a blank notification upon receipt of a contact request
This commit is contained in:
parent
bd2ae304fa
commit
3bca1c29e2
5 changed files with 90 additions and 21 deletions
|
@ -1,4 +1,5 @@
|
|||
mod contact_finder;
|
||||
mod notifications;
|
||||
|
||||
use client::{Contact, User, UserStore};
|
||||
use editor::{Cancel, Editor};
|
||||
|
@ -9,13 +10,14 @@ use gpui::{
|
|||
impl_actions,
|
||||
platform::CursorStyle,
|
||||
Element, ElementBox, Entity, LayoutContext, ModelHandle, MutableAppContext, RenderContext,
|
||||
Subscription, View, ViewContext, ViewHandle,
|
||||
Subscription, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use notifications::IncomingRequestNotification;
|
||||
use serde::Deserialize;
|
||||
use settings::Settings;
|
||||
use std::sync::Arc;
|
||||
use theme::IconButton;
|
||||
use workspace::{AppState, JoinProject};
|
||||
use workspace::{AppState, JoinProject, Workspace};
|
||||
|
||||
impl_actions!(
|
||||
contacts_panel,
|
||||
|
@ -60,7 +62,11 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||
}
|
||||
|
||||
impl ContactsPanel {
|
||||
pub fn new(app_state: Arc<AppState>, cx: &mut ViewContext<Self>) -> Self {
|
||||
pub fn new(
|
||||
app_state: Arc<AppState>,
|
||||
workspace: WeakViewHandle<Workspace>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
let user_query_editor = cx.add_view(|cx| {
|
||||
let mut editor = Editor::single_line(
|
||||
Some(|theme| theme.contacts_panel.user_query_editor.clone()),
|
||||
|
@ -77,6 +83,28 @@ impl ContactsPanel {
|
|||
})
|
||||
.detach();
|
||||
|
||||
cx.subscribe(&app_state.user_store, {
|
||||
let user_store = app_state.user_store.clone();
|
||||
move |_, _, event, cx| match event {
|
||||
client::Event::NotifyIncomingRequest(user) => {
|
||||
if let Some(workspace) = workspace.upgrade(cx) {
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
workspace.show_notification(
|
||||
cx.add_view(|_| {
|
||||
IncomingRequestNotification::new(
|
||||
user.clone(),
|
||||
user_store.clone(),
|
||||
)
|
||||
}),
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
let mut this = Self {
|
||||
list_state: ListState::new(0, Orientation::Top, 1000., {
|
||||
let this = cx.weak_handle();
|
||||
|
|
36
crates/contacts_panel/src/notifications.rs
Normal file
36
crates/contacts_panel/src/notifications.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use client::{User, UserStore};
|
||||
use gpui::{color::Color, elements::*, Entity, ModelHandle, View};
|
||||
use std::sync::Arc;
|
||||
use workspace::Notification;
|
||||
|
||||
pub struct IncomingRequestNotification {
|
||||
user: Arc<User>,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
}
|
||||
|
||||
impl Entity for IncomingRequestNotification {
|
||||
type Event = ();
|
||||
}
|
||||
|
||||
impl View for IncomingRequestNotification {
|
||||
fn ui_name() -> &'static str {
|
||||
"IncomingRequestNotification"
|
||||
}
|
||||
|
||||
fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> ElementBox {
|
||||
Empty::new()
|
||||
.constrained()
|
||||
.with_height(200.)
|
||||
.contained()
|
||||
.with_background_color(Color::red())
|
||||
.boxed()
|
||||
}
|
||||
}
|
||||
|
||||
impl Notification for IncomingRequestNotification {}
|
||||
|
||||
impl IncomingRequestNotification {
|
||||
pub fn new(user: Arc<User>, user_store: ModelHandle<UserStore>) -> Self {
|
||||
Self { user, user_store }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue