Fetch channel members before constructing channel mgmt modal

This commit is contained in:
Max Brunsfeld 2023-08-03 12:10:53 -07:00
parent 6c4964f071
commit 9a1dd0c6bc
3 changed files with 19 additions and 10 deletions

View File

@ -123,7 +123,7 @@ impl ChannelStore {
pub fn get_channel_members( pub fn get_channel_members(
&self, &self,
channel_id: ChannelId, channel_id: ChannelId,
) -> impl Future<Output = Result<HashMap<UserId, ChannelMemberStatus>>> { ) -> impl 'static + Future<Output = Result<HashMap<UserId, ChannelMemberStatus>>> {
let client = self.client.clone(); let client = self.client.clone();
async move { async move {
let response = client let response = client

View File

@ -1678,20 +1678,28 @@ impl CollabPanel {
} }
fn add_member(&mut self, action: &AddMember, cx: &mut ViewContext<Self>) { fn add_member(&mut self, action: &AddMember, cx: &mut ViewContext<Self>) {
if let Some(workspace) = self.workspace.upgrade(cx) { let channel_id = action.channel_id;
workspace.update(cx, |workspace, cx| { let workspace = self.workspace.clone();
let user_store = self.user_store.clone();
let channel_store = self.channel_store.clone();
let members = self.channel_store.read(cx).get_channel_members(channel_id);
cx.spawn(|_, mut cx| async move {
let members = members.await?;
workspace.update(&mut cx, |workspace, cx| {
workspace.toggle_modal(cx, |_, cx| { workspace.toggle_modal(cx, |_, cx| {
cx.add_view(|cx| { cx.add_view(|cx| {
build_channel_modal( build_channel_modal(
self.user_store.clone(), user_store.clone(),
self.channel_store.clone(), channel_store.clone(),
action.channel_id, channel_id,
members,
cx, cx,
) )
}) })
}) });
}); })
} })
.detach();
} }
fn remove_channel(&mut self, action: &RemoveChannel, cx: &mut ViewContext<Self>) { fn remove_channel(&mut self, action: &RemoveChannel, cx: &mut ViewContext<Self>) {

View File

@ -17,6 +17,7 @@ pub fn build_channel_modal(
user_store: ModelHandle<UserStore>, user_store: ModelHandle<UserStore>,
channel_store: ModelHandle<ChannelStore>, channel_store: ModelHandle<ChannelStore>,
channel: ChannelId, channel: ChannelId,
members: HashMap<UserId, ChannelMemberStatus>,
cx: &mut ViewContext<ChannelModal>, cx: &mut ViewContext<ChannelModal>,
) -> ChannelModal { ) -> ChannelModal {
Picker::new( Picker::new(
@ -26,7 +27,7 @@ pub fn build_channel_modal(
user_store, user_store,
channel_store, channel_store,
channel_id: channel, channel_id: channel,
member_statuses: Default::default(), member_statuses: members,
}, },
cx, cx,
) )