Pass UserStore to ContactsPanel instead of AppState
This commit is contained in:
parent
de99dcb0c3
commit
9e47e19f4e
2 changed files with 11 additions and 10 deletions
|
@ -23,7 +23,7 @@ use theme::IconButton;
|
||||||
use workspace::{
|
use workspace::{
|
||||||
menu::{Confirm, SelectNext, SelectPrev},
|
menu::{Confirm, SelectNext, SelectPrev},
|
||||||
sidebar::SidebarItem,
|
sidebar::SidebarItem,
|
||||||
AppState, JoinProject, Workspace,
|
JoinProject, Workspace,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl_actions!(
|
impl_actions!(
|
||||||
|
@ -91,7 +91,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
|
|
||||||
impl ContactsPanel {
|
impl ContactsPanel {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
app_state: Arc<AppState>,
|
user_store: ModelHandle<UserStore>,
|
||||||
workspace: WeakViewHandle<Workspace>,
|
workspace: WeakViewHandle<Workspace>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -151,8 +151,8 @@ impl ContactsPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.subscribe(&app_state.user_store, {
|
cx.subscribe(&user_store, {
|
||||||
let user_store = app_state.user_store.downgrade();
|
let user_store = user_store.downgrade();
|
||||||
move |_, _, event, cx| {
|
move |_, _, event, cx| {
|
||||||
if let Some((workspace, user_store)) =
|
if let Some((workspace, user_store)) =
|
||||||
workspace.upgrade(cx).zip(user_store.upgrade(cx))
|
workspace.upgrade(cx).zip(user_store.upgrade(cx))
|
||||||
|
@ -234,9 +234,8 @@ impl ContactsPanel {
|
||||||
entries: Default::default(),
|
entries: Default::default(),
|
||||||
match_candidates: Default::default(),
|
match_candidates: Default::default(),
|
||||||
filter_editor,
|
filter_editor,
|
||||||
_maintain_contacts: cx
|
_maintain_contacts: cx.observe(&user_store, |this, _, cx| this.update_entries(cx)),
|
||||||
.observe(&app_state.user_store, |this, _, cx| this.update_entries(cx)),
|
user_store,
|
||||||
user_store: app_state.user_store.clone(),
|
|
||||||
};
|
};
|
||||||
this.update_entries(cx);
|
this.update_entries(cx);
|
||||||
this
|
this
|
||||||
|
@ -914,6 +913,7 @@ mod tests {
|
||||||
use language::LanguageRegistry;
|
use language::LanguageRegistry;
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use theme::ThemeRegistry;
|
use theme::ThemeRegistry;
|
||||||
|
use workspace::AppState;
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_contact_panel(cx: &mut TestAppContext) {
|
async fn test_contact_panel(cx: &mut TestAppContext) {
|
||||||
|
@ -921,7 +921,7 @@ mod tests {
|
||||||
let project = Project::test(app_state.fs.clone(), [], cx).await;
|
let project = Project::test(app_state.fs.clone(), [], cx).await;
|
||||||
let workspace = cx.add_view(0, |cx| Workspace::new(project, cx));
|
let workspace = cx.add_view(0, |cx| Workspace::new(project, cx));
|
||||||
let panel = cx.add_view(0, |cx| {
|
let panel = cx.add_view(0, |cx| {
|
||||||
ContactsPanel::new(app_state.clone(), workspace.downgrade(), cx)
|
ContactsPanel::new(app_state.user_store.clone(), workspace.downgrade(), cx)
|
||||||
});
|
});
|
||||||
|
|
||||||
let get_users_request = server.receive::<proto::GetUsers>().await.unwrap();
|
let get_users_request = server.receive::<proto::GetUsers>().await.unwrap();
|
||||||
|
|
|
@ -162,8 +162,9 @@ pub fn build_workspace(
|
||||||
});
|
});
|
||||||
|
|
||||||
let project_panel = ProjectPanel::new(project, cx);
|
let project_panel = ProjectPanel::new(project, cx);
|
||||||
let contact_panel =
|
let contact_panel = cx.add_view(|cx| {
|
||||||
cx.add_view(|cx| ContactsPanel::new(app_state.clone(), workspace.weak_handle(), cx));
|
ContactsPanel::new(app_state.user_store.clone(), workspace.weak_handle(), cx)
|
||||||
|
});
|
||||||
|
|
||||||
workspace.left_sidebar().update(cx, |sidebar, cx| {
|
workspace.left_sidebar().update(cx, |sidebar, cx| {
|
||||||
sidebar.add_item("icons/folder-tree-solid-14.svg", project_panel.into(), cx)
|
sidebar.add_item("icons/folder-tree-solid-14.svg", project_panel.into(), cx)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue