Add remove channel method
Move test client fields into appstate and fix tests Co-authored-by: max <max@zed.dev>
This commit is contained in:
parent
56d4d5d1a8
commit
74437b3988
15 changed files with 534 additions and 256 deletions
|
@ -3,9 +3,9 @@ mod contact_notification;
|
|||
mod face_pile;
|
||||
mod incoming_call_notification;
|
||||
mod notifications;
|
||||
pub mod panel;
|
||||
mod project_shared_notification;
|
||||
mod sharing_status_indicator;
|
||||
pub mod panel;
|
||||
|
||||
use call::{ActiveCall, Room};
|
||||
pub use collab_titlebar_item::CollabTitlebarItem;
|
||||
|
|
|
@ -6,7 +6,7 @@ use anyhow::Result;
|
|||
use call::ActiveCall;
|
||||
use client::{proto::PeerId, Channel, ChannelStore, Client, Contact, User, UserStore};
|
||||
use contact_finder::build_contact_finder;
|
||||
use context_menu::ContextMenu;
|
||||
use context_menu::{ContextMenu, ContextMenuItem};
|
||||
use db::kvp::KEY_VALUE_STORE;
|
||||
use editor::{Cancel, Editor};
|
||||
use futures::StreamExt;
|
||||
|
@ -18,6 +18,7 @@ use gpui::{
|
|||
MouseEventHandler, Orientation, Padding, ParentElement, Stack, Svg,
|
||||
},
|
||||
geometry::{rect::RectF, vector::vec2f},
|
||||
impl_actions,
|
||||
platform::{CursorStyle, MouseButton, PromptLevel},
|
||||
serde_json, AnyElement, AppContext, AsyncAppContext, Element, Entity, ModelHandle,
|
||||
Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
|
@ -36,8 +37,15 @@ use workspace::{
|
|||
Workspace,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
struct RemoveChannel {
|
||||
channel_id: u64,
|
||||
}
|
||||
|
||||
actions!(collab_panel, [ToggleFocus]);
|
||||
|
||||
impl_actions!(collab_panel, [RemoveChannel]);
|
||||
|
||||
const CHANNELS_PANEL_KEY: &'static str = "ChannelsPanel";
|
||||
|
||||
pub fn init(_client: Arc<Client>, cx: &mut AppContext) {
|
||||
|
@ -49,6 +57,7 @@ pub fn init(_client: Arc<Client>, cx: &mut AppContext) {
|
|||
cx.add_action(CollabPanel::select_next);
|
||||
cx.add_action(CollabPanel::select_prev);
|
||||
cx.add_action(CollabPanel::confirm);
|
||||
cx.add_action(CollabPanel::remove_channel);
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
@ -305,6 +314,8 @@ impl CollabPanel {
|
|||
let active_call = ActiveCall::global(cx);
|
||||
this.subscriptions
|
||||
.push(cx.observe(&this.user_store, |this, _, cx| this.update_entries(cx)));
|
||||
this.subscriptions
|
||||
.push(cx.observe(&this.channel_store, |this, _, cx| this.update_entries(cx)));
|
||||
this.subscriptions
|
||||
.push(cx.observe(&active_call, |this, _, cx| this.update_entries(cx)));
|
||||
|
||||
|
@ -1278,6 +1289,19 @@ impl CollabPanel {
|
|||
.on_click(MouseButton::Left, move |_, this, cx| {
|
||||
this.join_channel(channel_id, cx);
|
||||
})
|
||||
.on_click(MouseButton::Right, move |e, this, cx| {
|
||||
this.context_menu.update(cx, |context_menu, cx| {
|
||||
context_menu.show(
|
||||
e.position,
|
||||
gpui::elements::AnchorCorner::BottomLeft,
|
||||
vec![ContextMenuItem::action(
|
||||
"Remove Channel",
|
||||
RemoveChannel { channel_id },
|
||||
)],
|
||||
cx,
|
||||
);
|
||||
});
|
||||
})
|
||||
.into_any()
|
||||
}
|
||||
|
||||
|
@ -1564,14 +1588,13 @@ impl CollabPanel {
|
|||
}
|
||||
}
|
||||
} else if let Some((_editing_state, channel_name)) = self.take_editing_state(cx) {
|
||||
dbg!(&channel_name);
|
||||
let create_channel = self.channel_store.update(cx, |channel_store, cx| {
|
||||
channel_store.create_channel(&channel_name, None)
|
||||
});
|
||||
|
||||
cx.foreground()
|
||||
.spawn(async move {
|
||||
dbg!(create_channel.await).ok();
|
||||
create_channel.await.ok();
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
@ -1600,6 +1623,36 @@ impl CollabPanel {
|
|||
}
|
||||
}
|
||||
|
||||
fn remove_channel(&mut self, action: &RemoveChannel, cx: &mut ViewContext<Self>) {
|
||||
let channel_id = action.channel_id;
|
||||
let channel_store = self.channel_store.clone();
|
||||
if let Some(channel) = channel_store.read(cx).channel_for_id(channel_id) {
|
||||
let prompt_message = format!(
|
||||
"Are you sure you want to remove the channel \"{}\"?",
|
||||
channel.name
|
||||
);
|
||||
let mut answer =
|
||||
cx.prompt(PromptLevel::Warning, &prompt_message, &["Remove", "Cancel"]);
|
||||
let window_id = cx.window_id();
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
if answer.next().await == Some(0) {
|
||||
if let Err(e) = channel_store
|
||||
.update(&mut cx, |channels, cx| channels.remove_channel(channel_id))
|
||||
.await
|
||||
{
|
||||
cx.prompt(
|
||||
window_id,
|
||||
PromptLevel::Info,
|
||||
&format!("Failed to remove channel: {}", e),
|
||||
&["Ok"],
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_contact(&mut self, user_id: u64, github_login: &str, cx: &mut ViewContext<Self>) {
|
||||
let user_store = self.user_store.clone();
|
||||
let prompt_message = format!(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use editor::Editor;
|
||||
use gpui::{elements::*, AnyViewHandle, Entity, View, ViewContext, ViewHandle, AppContext};
|
||||
use gpui::{elements::*, AnyViewHandle, AppContext, Entity, View, ViewContext, ViewHandle};
|
||||
use menu::Cancel;
|
||||
use workspace::{item::ItemHandle, Modal};
|
||||
|
||||
|
@ -62,12 +62,10 @@ impl View for ChannelModal {
|
|||
.constrained()
|
||||
.with_max_width(540.)
|
||||
.with_max_height(420.)
|
||||
|
||||
})
|
||||
.on_click(gpui::platform::MouseButton::Left, |_, _, _| {}) // Capture click and down events
|
||||
.on_down_out(gpui::platform::MouseButton::Left, |_, v, cx| {
|
||||
v.dismiss(cx)
|
||||
}).into_any_named("channel modal")
|
||||
.on_down_out(gpui::platform::MouseButton::Left, |_, v, cx| v.dismiss(cx))
|
||||
.into_any_named("channel modal")
|
||||
}
|
||||
|
||||
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue