One saved-accounts list (account_list) for login and the profile switcher: recent first, 5 shown, find field past 5, avatars and forget in both
Browse files at this commit51655ad3598d5ed6aeb4eac367ca906947af4925Parent: 701aad3- feat
- one saved-accounts list (account_list) for login and the profile switcher: recent first, 5 shown, find field past 5, avatars and forget in both
7 changed files +168 -153
- crates/client/lang/en/auth.txt +1 -0
- crates/client/lang/tr/auth.txt +1 -0
- crates/client/src/accounts.rs +15 -9
- crates/client/src/gui.rs +10 -0
- crates/client/src/gui/account_list.rs +105 -0
- crates/client/src/gui/auth.rs +9 -77
- crates/client/src/gui/profile.rs +27 -67
crates/client/lang/en/auth.txtmodified+1 -0
| @@ -7,3 +7,4 @@ register = Register | |||
| 7 | maintenance = Maintenance | 7 | maintenance = Maintenance |
| 8 | accept_any_cert = Accept any certificate | 8 | accept_any_cert = Accept any certificate |
| 9 | forget = Forget | 9 | forget = Forget |
| 10 | +find_account = Find account… | ||
crates/client/lang/tr/auth.txtmodified+1 -0
| @@ -7,3 +7,4 @@ register = Kayıt ol | |||
| 7 | maintenance = Bakım | 7 | maintenance = Bakım |
| 8 | accept_any_cert = Her sertifikayı kabul et | 8 | accept_any_cert = Her sertifikayı kabul et |
| 9 | forget = Unut | 9 | forget = Unut |
| 10 | +find_account = Hesap bul… | ||
crates/client/src/accounts.rsmodified+15 -9
| @@ -1,6 +1,9 @@ | |||
| 1 | -use std::sync::Arc; | 1 | +use std::{cmp::Reverse, sync::Arc}; |
| 2 | 2 | ||
| 3 | -use common::model::{Id, User}; | 3 | +use common::{ |
| 4 | + model::{Id, User}, | ||
| 5 | + time::now_ms, | ||
| 6 | +}; | ||
| 4 | use gpui_kit::{Image, ImageFormat}; | 7 | use gpui_kit::{Image, ImageFormat}; |
| 5 | 8 | ||
| 6 | use crate::{read_config, read_config_bytes, remove_config, write_config}; | 9 | use crate::{read_config, read_config_bytes, remove_config, write_config}; |
| @@ -11,6 +14,7 @@ pub struct Account { | |||
| 11 | pub username: String, | 14 | pub username: String, |
| 12 | pub token: String, | 15 | pub token: String, |
| 13 | pub picture: Option<Arc<Image>>, | 16 | pub picture: Option<Arc<Image>>, |
| 17 | + pub used_ms: u64, | ||
| 14 | } | 18 | } |
| 15 | 19 | ||
| 16 | #[derive(Debug, Clone, Default)] | 20 | #[derive(Debug, Clone, Default)] |
| @@ -25,10 +29,10 @@ impl Accounts { | |||
| 25 | self.list.iter().find(|account| account.user_id == user_id) | 29 | self.list.iter().find(|account| account.user_id == user_id) |
| 26 | } | 30 | } |
| 27 | 31 | ||
| 28 | - pub fn others(&self) -> impl Iterator<Item = &Account> { | 32 | + pub fn recent(&self) -> Vec<&Account> { |
| 29 | - self.list | 33 | + let mut list: Vec<&Account> = self.list.iter().collect(); |
| 30 | - .iter() | 34 | + list.sort_by_key(|account| Reverse(account.used_ms)); |
| 31 | - .filter(|account| Some(account.user_id) != self.active) | 35 | + list |
| 32 | } | 36 | } |
| 33 | 37 | ||
| 34 | pub fn sign_in(&mut self, user: &User, token: String) { | 38 | pub fn sign_in(&mut self, user: &User, token: String) { |
| @@ -38,6 +42,7 @@ impl Accounts { | |||
| 38 | username: user.username.clone(), | 42 | username: user.username.clone(), |
| 39 | token, | 43 | token, |
| 40 | picture: picture(&self.server, user.id), | 44 | picture: picture(&self.server, user.id), |
| 45 | + used_ms: now_ms(), | ||
| 41 | }); | 46 | }); |
| 42 | self.active = Some(user.id); | 47 | self.active = Some(user.id); |
| 43 | save(self); | 48 | save(self); |
| @@ -128,13 +133,14 @@ pub fn load(server: &str) -> Accounts { | |||
| 128 | for line in content.lines() { | 133 | for line in content.lines() { |
| 129 | match line.split('\t').collect::<Vec<_>>().as_slice() { | 134 | match line.split('\t').collect::<Vec<_>>().as_slice() { |
| 130 | ["active", user_id] => accounts.active = user_id.parse().ok(), | 135 | ["active", user_id] => accounts.active = user_id.parse().ok(), |
| 131 | - [user_id, username, token] => { | 136 | + [user_id, username, token, rest @ ..] => { |
| 132 | if let Ok(user_id) = user_id.parse() { | 137 | if let Ok(user_id) = user_id.parse() { |
| 133 | accounts.list.push(Account { | 138 | accounts.list.push(Account { |
| 134 | user_id, | 139 | user_id, |
| 135 | username: username.to_string(), | 140 | username: username.to_string(), |
| 136 | token: token.to_string(), | 141 | token: token.to_string(), |
| 137 | picture: picture(server, user_id), | 142 | picture: picture(server, user_id), |
| 143 | + used_ms: rest.first().and_then(|used| used.parse().ok()).unwrap_or(0), | ||
| 138 | }); | 144 | }); |
| 139 | } | 145 | } |
| 140 | } | 146 | } |
| @@ -151,8 +157,8 @@ fn save(accounts: &Accounts) { | |||
| 151 | .iter() | 157 | .iter() |
| 152 | .map(|account| { | 158 | .map(|account| { |
| 153 | format!( | 159 | format!( |
| 154 | - "{}\t{}\t{}\n", | 160 | + "{}\t{}\t{}\t{}\n", |
| 155 | - account.user_id, account.username, account.token | 161 | + account.user_id, account.username, account.token, account.used_ms |
| 156 | ) | 162 | ) |
| 157 | }) | 163 | }) |
| 158 | .collect(); | 164 | .collect(); |
crates/client/src/gui.rsmodified+10 -0
| @@ -38,6 +38,7 @@ use crate::{ | |||
| 38 | settings::{Scale, Settings}, | 38 | settings::{Scale, Settings}, |
| 39 | }; | 39 | }; |
| 40 | 40 | ||
| 41 | +mod account_list; | ||
| 41 | mod auth; | 42 | mod auth; |
| 42 | mod builder; | 43 | mod builder; |
| 43 | mod call_bar; | 44 | mod call_bar; |
| @@ -595,6 +596,7 @@ pub struct Yumush { | |||
| 595 | dismissed_announcement: Option<String>, | 596 | dismissed_announcement: Option<String>, |
| 596 | settings: Settings, | 597 | settings: Settings, |
| 597 | accounts: Accounts, | 598 | accounts: Accounts, |
| 599 | + account_filter: Entity<InputState>, | ||
| 598 | voice: VoiceControls, | 600 | voice: VoiceControls, |
| 599 | focus: gpui_kit::FocusHandle, | 601 | focus: gpui_kit::FocusHandle, |
| 600 | window: Option<AnyWindowHandle>, | 602 | window: Option<AnyWindowHandle>, |
| @@ -658,6 +660,13 @@ impl Yumush { | |||
| 658 | let voice = VoiceControls::new(&settings.voice, window, cx); | 660 | let voice = VoiceControls::new(&settings.voice, window, cx); |
| 659 | 661 | ||
| 660 | let server = network.server(); | 662 | let server = network.server(); |
| 663 | + let account_filter = new_input(w().auth.find_account, window, cx); | ||
| 664 | + cx.subscribe(&account_filter, |_, _, event: &InputEvent, cx| { | ||
| 665 | + if matches!(event, InputEvent::Change) { | ||
| 666 | + cx.notify(); | ||
| 667 | + } | ||
| 668 | + }) | ||
| 669 | + .detach(); | ||
| 661 | let mut yumush = Self { | 670 | let mut yumush = Self { |
| 662 | user: None, | 671 | user: None, |
| 663 | focus: cx.focus_handle(), | 672 | focus: cx.focus_handle(), |
| @@ -670,6 +679,7 @@ impl Yumush { | |||
| 670 | dismissed_announcement: None, | 679 | dismissed_announcement: None, |
| 671 | settings, | 680 | settings, |
| 672 | accounts: accounts::load(&server.address), | 681 | accounts: accounts::load(&server.address), |
| 682 | + account_filter, | ||
| 673 | voice, | 683 | voice, |
| 674 | window: None, | 684 | window: None, |
| 675 | deferred: Vec::new(), | 685 | deferred: Vec::new(), |
crates/client/src/gui/account_list.rsadded+105 -0
| @@ -0,0 +1,105 @@ | |||
| 1 | +use gpui_kit::{ | ||
| 2 | + AnyElement, App, Div, Entity, IntoElement, ParentElement, StatefulInteractiveElement, Styled, | ||
| 3 | + assets::IconName, component::popover::PopoverState, div, px, | ||
| 4 | +}; | ||
| 5 | + | ||
| 6 | +use super::{ | ||
| 7 | + Palette, Tooltip as _, Yumush, badge, clickable, hoverable, parts, | ||
| 8 | + sidebar::input_box, | ||
| 9 | + style::{radius, size, space, text}, | ||
| 10 | + text, | ||
| 11 | +}; | ||
| 12 | +use crate::accounts::Account; | ||
| 13 | +use crate::lang::w; | ||
| 14 | + | ||
| 15 | +const CAP: usize = 5; | ||
| 16 | + | ||
| 17 | +pub(super) fn account_list( | ||
| 18 | + yumush: &Yumush, | ||
| 19 | + entity: &Entity<Yumush>, | ||
| 20 | + skip_active: bool, | ||
| 21 | + popover: Option<Entity<PopoverState>>, | ||
| 22 | + palette: Palette, | ||
| 23 | + cx: &App, | ||
| 24 | +) -> Div { | ||
| 25 | + let mut accounts = yumush.accounts.recent(); | ||
| 26 | + if skip_active { | ||
| 27 | + accounts.retain(|account| Some(account.user_id) != yumush.accounts.active); | ||
| 28 | + } | ||
| 29 | + let filtered = accounts.len() > CAP; | ||
| 30 | + let query = super::widget::search_text(&yumush.account_filter, cx); | ||
| 31 | + let rows: Vec<AnyElement> = accounts | ||
| 32 | + .into_iter() | ||
| 33 | + .filter(|account| !filtered || account.username.to_lowercase().contains(query.as_str())) | ||
| 34 | + .take(CAP) | ||
| 35 | + .map(|account| row(account, entity, popover.clone(), palette)) | ||
| 36 | + .collect(); | ||
| 37 | + | ||
| 38 | + div() | ||
| 39 | + .flex() | ||
| 40 | + .flex_col() | ||
| 41 | + .gap(px(space::XXS)) | ||
| 42 | + .children(filtered.then(|| input_box(&yumush.account_filter, palette))) | ||
| 43 | + .children(rows) | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +fn row( | ||
| 47 | + account: &Account, | ||
| 48 | + entity: &Entity<Yumush>, | ||
| 49 | + popover: Option<Entity<PopoverState>>, | ||
| 50 | + palette: Palette, | ||
| 51 | +) -> AnyElement { | ||
| 52 | + let user_id = account.user_id; | ||
| 53 | + let switch_entity = entity.clone(); | ||
| 54 | + let forget_entity = entity.clone(); | ||
| 55 | + | ||
| 56 | + hoverable( | ||
| 57 | + format!("saved_{user_id}"), | ||
| 58 | + div() | ||
| 59 | + .h(px(size::CONTROL)) | ||
| 60 | + .px(px(space::SM)) | ||
| 61 | + .flex() | ||
| 62 | + .items_center() | ||
| 63 | + .gap(px(space::SM)) | ||
| 64 | + .rounded(px(radius::MD)) | ||
| 65 | + .child(match &account.picture { | ||
| 66 | + Some(picture) => div() | ||
| 67 | + .size(px(size::CHIP)) | ||
| 68 | + .flex_shrink_0() | ||
| 69 | + .rounded_full() | ||
| 70 | + .overflow_hidden() | ||
| 71 | + .child(gpui_kit::img(picture.clone()).size_full()), | ||
| 72 | + None => badge( | ||
| 73 | + palette, | ||
| 74 | + user_id, | ||
| 75 | + &account.username, | ||
| 76 | + px(size::CHIP), | ||
| 77 | + text(text::CAPTION), | ||
| 78 | + ) | ||
| 79 | + .rounded_full(), | ||
| 80 | + }) | ||
| 81 | + .child(div().flex_1().truncate().child(account.username.clone())) | ||
| 82 | + .child( | ||
| 83 | + clickable(format!("forget_{user_id}"), palette, move |_, cx| { | ||
| 84 | + cx.stop_propagation(); | ||
| 85 | + forget_entity.update(cx, |yumush, cx| yumush.forget_account(user_id, cx)); | ||
| 86 | + }) | ||
| 87 | + .tip(w().auth.forget) | ||
| 88 | + .size(px(size::CHIP)) | ||
| 89 | + .flex() | ||
| 90 | + .items_center() | ||
| 91 | + .justify_center() | ||
| 92 | + .rounded(px(radius::SM)) | ||
| 93 | + .text_color(palette.muted) | ||
| 94 | + .child(parts::small_icon(IconName::X)), | ||
| 95 | + ), | ||
| 96 | + palette, | ||
| 97 | + ) | ||
| 98 | + .on_click(move |_, window, cx| { | ||
| 99 | + if let Some(popover) = &popover { | ||
| 100 | + popover.update(cx, |state, cx| state.dismiss(window, cx)); | ||
| 101 | + } | ||
| 102 | + switch_entity.update(cx, |yumush, cx| yumush.switch_account(user_id, window, cx)); | ||
| 103 | + }) | ||
| 104 | + .into_any_element() | ||
| 105 | +} | ||
crates/client/src/gui/auth.rsmodified+9 -77
| @@ -1,15 +1,16 @@ | |||
| 1 | use gpui_kit::prelude::FluentBuilder as _; | 1 | use gpui_kit::prelude::FluentBuilder as _; |
| 2 | use gpui_kit::{ | 2 | use gpui_kit::{ |
| 3 | - AnimationExt as _, AnyElement, Context, Div, Entity, FontWeight, IntoElement, ParentElement, | 3 | + AnimationExt as _, App, Context, Div, Entity, FontWeight, IntoElement, ParentElement, Styled, |
| 4 | - StatefulInteractiveElement, Styled, Window, | 4 | + Window, |
| 5 | assets::IconName, | 5 | assets::IconName, |
| 6 | component::input::{Input, InputEvent, InputState}, | 6 | component::input::{Input, InputEvent, InputState}, |
| 7 | div, px, | 7 | div, px, |
| 8 | }; | 8 | }; |
| 9 | 9 | ||
| 10 | use super::{ | 10 | use super::{ |
| 11 | - Palette, Route, Tooltip as _, Yumush, badge, clickable, connection_notice, hoverable, | 11 | + Palette, Route, Yumush, |
| 12 | - new_input, notify_error, palette, parts, | 12 | + account_list::account_list, |
| 13 | + clickable, connection_notice, new_input, notify_error, palette, parts, | ||
| 13 | settings_page::{segment, segment_track}, | 14 | settings_page::{segment, segment_track}, |
| 14 | style::{radius, size, space, text}, | 15 | style::{radius, size, space, text}, |
| 15 | text, | 16 | text, |
| @@ -230,7 +231,7 @@ impl Yumush { | |||
| 230 | .text_color(palette.muted) | 231 | .text_color(palette.muted) |
| 231 | .child(w().auth.maintenance) | 232 | .child(w().auth.maintenance) |
| 232 | })) | 233 | })) |
| 233 | - .children(self.saved_accounts(&entity, palette)) | 234 | + .children(self.saved_accounts(&entity, palette, cx)) |
| 234 | .child(tabs) | 235 | .child(tabs) |
| 235 | .child(field(palette, &self.auth.username_input)) | 236 | .child(field(palette, &self.auth.username_input)) |
| 236 | .child(password_field(palette, &self.auth.password_input)) | 237 | .child(password_field(palette, &self.auth.password_input)) |
| @@ -286,78 +287,9 @@ impl Yumush { | |||
| 286 | ) | 287 | ) |
| 287 | } | 288 | } |
| 288 | 289 | ||
| 289 | - fn saved_accounts(&self, entity: &Entity<Self>, palette: Palette) -> Option<Div> { | 290 | + fn saved_accounts(&self, entity: &Entity<Self>, palette: Palette, cx: &App) -> Option<Div> { |
| 290 | - if self.accounts.list.is_empty() { | 291 | + (!self.accounts.list.is_empty()) |
| 291 | - return None; | 292 | + .then(|| account_list(self, entity, false, None, palette, cx)) |
| 292 | - } | ||
| 293 | - let rows: Vec<AnyElement> = self | ||
| 294 | - .accounts | ||
| 295 | - .list | ||
| 296 | - .iter() | ||
| 297 | - .map(|account| { | ||
| 298 | - let switch_entity = entity.clone(); | ||
| 299 | - let forget_entity = entity.clone(); | ||
| 300 | - let switch_id = account.user_id; | ||
| 301 | - let forget_id = account.user_id; | ||
| 302 | - | ||
| 303 | - hoverable( | ||
| 304 | - format!("saved_{}", account.user_id), | ||
| 305 | - div() | ||
| 306 | - .h(px(size::CONTROL)) | ||
| 307 | - .px(px(space::SM)) | ||
| 308 | - .flex() | ||
| 309 | - .items_center() | ||
| 310 | - .gap(px(space::SM)) | ||
| 311 | - .rounded(px(radius::MD)) | ||
| 312 | - .child(match &account.picture { | ||
| 313 | - Some(picture) => div() | ||
| 314 | - .size(px(size::CHIP)) | ||
| 315 | - .flex_shrink_0() | ||
| 316 | - .rounded_full() | ||
| 317 | - .overflow_hidden() | ||
| 318 | - .child(gpui_kit::img(picture.clone()).size_full()), | ||
| 319 | - None => badge( | ||
| 320 | - palette, | ||
| 321 | - account.user_id, | ||
| 322 | - &account.username, | ||
| 323 | - px(size::CHIP), | ||
| 324 | - text(text::CAPTION), | ||
| 325 | - ) | ||
| 326 | - .rounded_full(), | ||
| 327 | - }) | ||
| 328 | - .child(div().flex_1().truncate().child(account.username.clone())) | ||
| 329 | - .child( | ||
| 330 | - clickable( | ||
| 331 | - format!("forget_{}", account.user_id), | ||
| 332 | - palette, | ||
| 333 | - move |_, cx| { | ||
| 334 | - cx.stop_propagation(); | ||
| 335 | - forget_entity.update(cx, |yumush, cx| { | ||
| 336 | - yumush.forget_account(forget_id, cx) | ||
| 337 | - }); | ||
| 338 | - }, | ||
| 339 | - ) | ||
| 340 | - .tip(w().auth.forget) | ||
| 341 | - .size(px(size::CHIP)) | ||
| 342 | - .flex() | ||
| 343 | - .items_center() | ||
| 344 | - .justify_center() | ||
| 345 | - .rounded(px(radius::SM)) | ||
| 346 | - .text_color(palette.muted) | ||
| 347 | - .child(super::parts::small_icon(IconName::X)), | ||
| 348 | - ), | ||
| 349 | - palette, | ||
| 350 | - ) | ||
| 351 | - .on_click(move |_, window, cx| { | ||
| 352 | - switch_entity.update(cx, |yumush, cx| { | ||
| 353 | - yumush.switch_account(switch_id, window, cx) | ||
| 354 | - }) | ||
| 355 | - }) | ||
| 356 | - .into_any_element() | ||
| 357 | - }) | ||
| 358 | - .collect(); | ||
| 359 | - | ||
| 360 | - Some(div().flex().flex_col().gap(px(space::XXS)).children(rows)) | ||
| 361 | } | 293 | } |
| 362 | } | 294 | } |
| 363 | 295 | ||
crates/client/src/gui/profile.rsmodified+27 -67
| @@ -1,3 +1,4 @@ | |||
| 1 | +use super::account_list::account_list; | ||
| 1 | use crate::gui::glyph::Fill as _; | 2 | use crate::gui::glyph::Fill as _; |
| 2 | use crate::lang::{Label as _, w}; | 3 | use crate::lang::{Label as _, w}; |
| 3 | use common::model::Id; | 4 | use common::model::Id; |
| @@ -11,9 +12,9 @@ use common::{ | |||
| 11 | permission, | 12 | permission, |
| 12 | }; | 13 | }; |
| 13 | use gpui_kit::{ | 14 | use gpui_kit::{ |
| 14 | - Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, Hsla, Image, | 15 | + Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, Hsla, Image, IntoElement, |
| 15 | - InteractiveElement, IntoElement, ParentElement, SharedString, Stateful, | 16 | + ParentElement, SharedString, Stateful, StatefulInteractiveElement, StyleRefinement, Styled, |
| 16 | - StatefulInteractiveElement, StyleRefinement, Styled, Window, | 17 | + Window, |
| 17 | assets::IconName, | 18 | assets::IconName, |
| 18 | component::{ | 19 | component::{ |
| 19 | WindowExt, | 20 | WindowExt, |
| @@ -37,8 +38,6 @@ use super::{ | |||
| 37 | millis_time, notify_error, palette, text, | 38 | millis_time, notify_error, palette, text, |
| 38 | }; | 39 | }; |
| 39 | 40 | ||
| 40 | -const ACCOUNTS_MAX_H: f32 = 180.; | ||
| 41 | - | ||
| 42 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 41 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 43 | enum Removal { | 42 | enum Removal { |
| 44 | Kick, | 43 | Kick, |
| @@ -112,11 +111,6 @@ pub(super) fn profile_popover( | |||
| 112 | reporting: yumush.chat.report == Some(ReportTarget::User(user.id)), | 111 | reporting: yumush.chat.report == Some(ReportTarget::User(user.id)), |
| 113 | reason: yumush.chat.report_reason.clone(), | 112 | reason: yumush.chat.report_reason.clone(), |
| 114 | status: yumush.chat.status_input.clone(), | 113 | status: yumush.chat.status_input.clone(), |
| 115 | - others: yumush | ||
| 116 | - .accounts | ||
| 117 | - .others() | ||
| 118 | - .map(|account| (account.user_id, account.username.clone())) | ||
| 119 | - .collect(), | ||
| 120 | volume: yumush | 114 | volume: yumush |
| 121 | .chat | 115 | .chat |
| 122 | .user_volume | 116 | .user_volume |
| @@ -154,7 +148,6 @@ struct Card { | |||
| 154 | reporting: bool, | 148 | reporting: bool, |
| 155 | reason: Entity<InputState>, | 149 | reason: Entity<InputState>, |
| 156 | status: Entity<InputState>, | 150 | status: Entity<InputState>, |
| 157 | - others: Vec<(Id, String)>, | ||
| 158 | volume: Option<(Entity<SliderState>, f32)>, | 151 | volume: Option<(Entity<SliderState>, f32)>, |
| 159 | } | 152 | } |
| 160 | 153 | ||
| @@ -395,12 +388,7 @@ impl Card { | |||
| 395 | .truncate(), | 388 | .truncate(), |
| 396 | ) | 389 | ) |
| 397 | .when(is_self, |name| { | 390 | .when(is_self, |name| { |
| 398 | - name.child(account_menu( | 391 | + name.child(account_menu(entity, &popover, palette)) |
| 399 | - self.others.clone(), | ||
| 400 | - entity, | ||
| 401 | - &popover, | ||
| 402 | - palette, | ||
| 403 | - )) | ||
| 404 | }), | 392 | }), |
| 405 | ) | 393 | ) |
| 406 | .map(|names| { | 394 | .map(|names| { |
| @@ -639,54 +627,7 @@ fn main_self_rows( | |||
| 639 | rows | 627 | rows |
| 640 | } | 628 | } |
| 641 | 629 | ||
| 642 | -fn accounts_rows( | 630 | +fn account_menu(entity: &Entity<Yumush>, card: &Entity<PopoverState>, palette: Palette) -> Popover { |
| 643 | - others: &[(Id, String)], | ||
| 644 | - entity: &Entity<Yumush>, | ||
| 645 | - popover: &Entity<PopoverState>, | ||
| 646 | - palette: Palette, | ||
| 647 | -) -> Vec<AnyElement> { | ||
| 648 | - let accounts = others.iter().map(|&(user_id, ref username)| { | ||
| 649 | - menu_row( | ||
| 650 | - format!("switch_{user_id}"), | ||
| 651 | - username.clone(), | ||
| 652 | - small_icon(IconName::CircleUser), | ||
| 653 | - palette.text, | ||
| 654 | - palette, | ||
| 655 | - yumush_action(entity, popover, move |yumush, window, cx| { | ||
| 656 | - yumush.switch_account(user_id, window, cx) | ||
| 657 | - }), | ||
| 658 | - ) | ||
| 659 | - }); | ||
| 660 | - | ||
| 661 | - vec![ | ||
| 662 | - div() | ||
| 663 | - .id("profile_accounts") | ||
| 664 | - .max_h(px(ACCOUNTS_MAX_H)) | ||
| 665 | - .overflow_y_scroll() | ||
| 666 | - .flex() | ||
| 667 | - .flex_col() | ||
| 668 | - .children(accounts) | ||
| 669 | - .into_any_element(), | ||
| 670 | - menu_row( | ||
| 671 | - "profile_add_account", | ||
| 672 | - w().profile.add_account, | ||
| 673 | - small_icon(IconName::UserPlus), | ||
| 674 | - palette.text, | ||
| 675 | - palette, | ||
| 676 | - yumush_action(entity, popover, |yumush, window, cx| { | ||
| 677 | - yumush.add_account(window, cx) | ||
| 678 | - }), | ||
| 679 | - ) | ||
| 680 | - .into_any_element(), | ||
| 681 | - ] | ||
| 682 | -} | ||
| 683 | - | ||
| 684 | -fn account_menu( | ||
| 685 | - others: Vec<(Id, String)>, | ||
| 686 | - entity: &Entity<Yumush>, | ||
| 687 | - card: &Entity<PopoverState>, | ||
| 688 | - palette: Palette, | ||
| 689 | -) -> Popover { | ||
| 690 | let entity = entity.clone(); | 631 | let entity = entity.clone(); |
| 691 | let card = card.clone(); | 632 | let card = card.clone(); |
| 692 | Popover::new("account_menu") | 633 | Popover::new("account_menu") |
| @@ -699,10 +640,29 @@ fn account_menu( | |||
| 699 | .flex_shrink_0() | 640 | .flex_shrink_0() |
| 700 | .child(small_icon(IconName::ChevronDown).text_color(palette.muted)), | 641 | .child(small_icon(IconName::ChevronDown).text_color(palette.muted)), |
| 701 | )) | 642 | )) |
| 702 | - .content(move |_, _, _| { | 643 | + .content(move |_, _, cx| { |
| 644 | + let yumush = entity.read(cx); | ||
| 703 | super::parts::popover(palette.tokens) | 645 | super::parts::popover(palette.tokens) |
| 704 | .p(px(space::XS)) | 646 | .p(px(space::XS)) |
| 705 | - .children(accounts_rows(&others, &entity, &card, palette)) | 647 | + .w(px(size::SIDEBAR)) |
| 648 | + .child(account_list( | ||
| 649 | + yumush, | ||
| 650 | + &entity, | ||
| 651 | + true, | ||
| 652 | + Some(card.clone()), | ||
| 653 | + palette, | ||
| 654 | + cx, | ||
| 655 | + )) | ||
| 656 | + .child(menu_row( | ||
| 657 | + "profile_add_account", | ||
| 658 | + w().profile.add_account, | ||
| 659 | + small_icon(IconName::UserPlus), | ||
| 660 | + palette.text, | ||
| 661 | + palette, | ||
| 662 | + yumush_action(&entity, &card, |yumush, window, cx| { | ||
| 663 | + yumush.add_account(window, cx) | ||
| 664 | + }), | ||
| 665 | + )) | ||
| 706 | }) | 666 | }) |
| 707 | } | 667 | } |
| 708 | 668 | ||