mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-20 02:47:34 +03:00
Consolidate logic for rendering contact requests
This commit is contained in:
parent
834c485300
commit
b1a75805cc
@ -101,22 +101,20 @@ impl ContactsPanel {
|
||||
.with_style(theme.header.container)
|
||||
.boxed()
|
||||
}
|
||||
ContactEntry::IncomingRequest(user) => {
|
||||
Self::render_incoming_contact_request(
|
||||
ContactEntry::IncomingRequest(user) => Self::render_contact_request(
|
||||
user.clone(),
|
||||
this.user_store.clone(),
|
||||
theme,
|
||||
true,
|
||||
cx,
|
||||
)
|
||||
}
|
||||
ContactEntry::OutgoingRequest(user) => {
|
||||
Self::render_outgoing_contact_request(
|
||||
),
|
||||
ContactEntry::OutgoingRequest(user) => Self::render_contact_request(
|
||||
user.clone(),
|
||||
this.user_store.clone(),
|
||||
theme,
|
||||
false,
|
||||
cx,
|
||||
)
|
||||
}
|
||||
),
|
||||
ContactEntry::Contact(contact) => Self::render_contact(
|
||||
contact.clone(),
|
||||
current_user_id,
|
||||
@ -311,16 +309,16 @@ impl ContactsPanel {
|
||||
.boxed()
|
||||
}
|
||||
|
||||
fn render_incoming_contact_request(
|
||||
fn render_contact_request(
|
||||
user: Arc<User>,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
theme: &theme::ContactsPanel,
|
||||
is_incoming: bool,
|
||||
cx: &mut LayoutContext,
|
||||
) -> ElementBox {
|
||||
enum Reject {}
|
||||
enum Accept {}
|
||||
|
||||
let user_id = user.id;
|
||||
enum Cancel {}
|
||||
|
||||
let mut row = Flex::row()
|
||||
.with_children(user.avatar.clone().map(|avatar| {
|
||||
@ -342,8 +340,10 @@ impl ContactsPanel {
|
||||
.boxed(),
|
||||
);
|
||||
|
||||
let user_id = user.id;
|
||||
let is_contact_request_pending = user_store.read(cx).is_contact_request_pending(&user);
|
||||
|
||||
if is_incoming {
|
||||
row.add_children([
|
||||
MouseEventHandler::new::<Reject, _, _>(user.id as usize, cx, |mouse_state, _| {
|
||||
let button_style = if is_contact_request_pending {
|
||||
@ -376,54 +376,16 @@ impl ContactsPanel {
|
||||
.flex_float()
|
||||
.boxed()
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(move |_, cx| {
|
||||
cx.dispatch_action(RespondToContactRequest {
|
||||
user_id,
|
||||
accept: true,
|
||||
})
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.boxed(),
|
||||
]);
|
||||
|
||||
row.constrained()
|
||||
.with_height(theme.row_height)
|
||||
.contained()
|
||||
.with_style(theme.row.clone())
|
||||
.boxed()
|
||||
}
|
||||
|
||||
fn render_outgoing_contact_request(
|
||||
user: Arc<User>,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
theme: &theme::ContactsPanel,
|
||||
cx: &mut LayoutContext,
|
||||
) -> ElementBox {
|
||||
enum Cancel {}
|
||||
|
||||
let user_id = user.id;
|
||||
let is_contact_request_pending = user_store.read(cx).is_contact_request_pending(&user);
|
||||
|
||||
let mut row = Flex::row()
|
||||
.with_children(user.avatar.clone().map(|avatar| {
|
||||
Image::new(avatar)
|
||||
.with_style(theme.contact_avatar)
|
||||
.aligned()
|
||||
.left()
|
||||
.boxed()
|
||||
}))
|
||||
.with_child(
|
||||
Label::new(
|
||||
user.github_login.clone(),
|
||||
theme.contact_username.text.clone(),
|
||||
)
|
||||
.contained()
|
||||
.with_style(theme.contact_username.container)
|
||||
.aligned()
|
||||
.left()
|
||||
.boxed(),
|
||||
);
|
||||
|
||||
} else {
|
||||
row.add_child(
|
||||
MouseEventHandler::new::<Cancel, _, _>(user.id as usize, cx, |mouse_state, _| {
|
||||
let button_style = if is_contact_request_pending {
|
||||
@ -431,7 +393,6 @@ impl ContactsPanel {
|
||||
} else {
|
||||
&theme.contact_button.style_for(mouse_state, false)
|
||||
};
|
||||
|
||||
render_icon_button(button_style, "icons/reject.svg")
|
||||
.aligned()
|
||||
.flex_float()
|
||||
@ -443,6 +404,7 @@ impl ContactsPanel {
|
||||
.flex_float()
|
||||
.boxed(),
|
||||
);
|
||||
}
|
||||
|
||||
row.constrained()
|
||||
.with_height(theme.row_height)
|
||||
|
Loading…
Reference in New Issue
Block a user