forge
Explore
Log in

Don't you dare go Hollow

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 commit

51655ad3598d5ed6aeb4eac367ca906947af4925Ahmet Kaan GümüşParent: 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
Show full message
✨ 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
crates/client/lang/en/auth.txtmodified+1 -0
@@ -7,3 +7,4 @@ register = Register
77 maintenance = Maintenance
88 accept_any_cert = Accept any certificate
99 forget = Forget
10+find_account = Find account…
crates/client/lang/tr/auth.txtmodified+1 -0
@@ -7,3 +7,4 @@ register = Kayıt ol
77 maintenance = Bakım
88 accept_any_cert = Her sertifikayı kabul et
99 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};
22
3-use common::model::{Id, User};
3+use common::{
4+ model::{Id, User},
5+ time::now_ms,
6+};
47 use gpui_kit::{Image, ImageFormat};
58
69 use crate::{read_config, read_config_bytes, remove_config, write_config};
@@ -11,6 +14,7 @@ pub struct Account {
1114 pub username: String,
1215 pub token: String,
1316 pub picture: Option<Arc<Image>>,
17+ pub used_ms: u64,
1418 }
1519
1620 #[derive(Debug, Clone, Default)]
@@ -25,10 +29,10 @@ impl Accounts {
2529 self.list.iter().find(|account| account.user_id == user_id)
2630 }
2731
28- pub fn others(&self) -> impl Iterator<Item = &Account> {
29- self.list
30- .iter()
31- .filter(|account| Some(account.user_id) != self.active)
32+ pub fn recent(&self) -> Vec<&Account> {
33+ let mut list: Vec<&Account> = self.list.iter().collect();
34+ list.sort_by_key(|account| Reverse(account.used_ms));
35+ list
3236 }
3337
3438 pub fn sign_in(&mut self, user: &User, token: String) {
@@ -38,6 +42,7 @@ impl Accounts {
3842 username: user.username.clone(),
3943 token,
4044 picture: picture(&self.server, user.id),
45+ used_ms: now_ms(),
4146 });
4247 self.active = Some(user.id);
4348 save(self);
@@ -128,13 +133,14 @@ pub fn load(server: &str) -> Accounts {
128133 for line in content.lines() {
129134 match line.split('\t').collect::<Vec<_>>().as_slice() {
130135 ["active", user_id] => accounts.active = user_id.parse().ok(),
131- [user_id, username, token] => {
136+ [user_id, username, token, rest @ ..] => {
132137 if let Ok(user_id) = user_id.parse() {
133138 accounts.list.push(Account {
134139 user_id,
135140 username: username.to_string(),
136141 token: token.to_string(),
137142 picture: picture(server, user_id),
143+ used_ms: rest.first().and_then(|used| used.parse().ok()).unwrap_or(0),
138144 });
139145 }
140146 }
@@ -151,8 +157,8 @@ fn save(accounts: &Accounts) {
151157 .iter()
152158 .map(|account| {
153159 format!(
154- "{}\t{}\t{}\n",
155- account.user_id, account.username, account.token
160+ "{}\t{}\t{}\t{}\n",
161+ account.user_id, account.username, account.token, account.used_ms
156162 )
157163 })
158164 .collect();
crates/client/src/gui.rsmodified+10 -0
@@ -38,6 +38,7 @@ use crate::{
3838 settings::{Scale, Settings},
3939 };
4040
41+mod account_list;
4142 mod auth;
4243 mod builder;
4344 mod call_bar;
@@ -595,6 +596,7 @@ pub struct Yumush {
595596 dismissed_announcement: Option<String>,
596597 settings: Settings,
597598 accounts: Accounts,
599+ account_filter: Entity<InputState>,
598600 voice: VoiceControls,
599601 focus: gpui_kit::FocusHandle,
600602 window: Option<AnyWindowHandle>,
@@ -658,6 +660,13 @@ impl Yumush {
658660 let voice = VoiceControls::new(&settings.voice, window, cx);
659661
660662 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();
661670 let mut yumush = Self {
662671 user: None,
663672 focus: cx.focus_handle(),
@@ -670,6 +679,7 @@ impl Yumush {
670679 dismissed_announcement: None,
671680 settings,
672681 accounts: accounts::load(&server.address),
682+ account_filter,
673683 voice,
674684 window: None,
675685 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 @@
11 use gpui_kit::prelude::FluentBuilder as _;
22 use gpui_kit::{
3- AnimationExt as _, AnyElement, Context, Div, Entity, FontWeight, IntoElement, ParentElement,
4- StatefulInteractiveElement, Styled, Window,
3+ AnimationExt as _, App, Context, Div, Entity, FontWeight, IntoElement, ParentElement, Styled,
4+ Window,
55 assets::IconName,
66 component::input::{Input, InputEvent, InputState},
77 div, px,
88 };
99
1010 use super::{
11- Palette, Route, Tooltip as _, Yumush, badge, clickable, connection_notice, hoverable,
12- new_input, notify_error, palette, parts,
11+ Palette, Route, Yumush,
12+ account_list::account_list,
13+ clickable, connection_notice, new_input, notify_error, palette, parts,
1314 settings_page::{segment, segment_track},
1415 style::{radius, size, space, text},
1516 text,
@@ -230,7 +231,7 @@ impl Yumush {
230231 .text_color(palette.muted)
231232 .child(w().auth.maintenance)
232233 }))
233- .children(self.saved_accounts(&entity, palette))
234+ .children(self.saved_accounts(&entity, palette, cx))
234235 .child(tabs)
235236 .child(field(palette, &self.auth.username_input))
236237 .child(password_field(palette, &self.auth.password_input))
@@ -286,78 +287,9 @@ impl Yumush {
286287 )
287288 }
288289
289- fn saved_accounts(&self, entity: &Entity<Self>, palette: Palette) -> Option<Div> {
290- if self.accounts.list.is_empty() {
291- return None;
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))
290+ fn saved_accounts(&self, entity: &Entity<Self>, palette: Palette, cx: &App) -> Option<Div> {
291+ (!self.accounts.list.is_empty())
292+ .then(|| account_list(self, entity, false, None, palette, cx))
361293 }
362294 }
363295
crates/client/src/gui/profile.rsmodified+27 -67
@@ -1,3 +1,4 @@
1+use super::account_list::account_list;
12 use crate::gui::glyph::Fill as _;
23 use crate::lang::{Label as _, w};
34 use common::model::Id;
@@ -11,9 +12,9 @@ use common::{
1112 permission,
1213 };
1314 use gpui_kit::{
14- Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, Hsla, Image,
15- InteractiveElement, IntoElement, ParentElement, SharedString, Stateful,
16- StatefulInteractiveElement, StyleRefinement, Styled, Window,
15+ Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, Hsla, Image, IntoElement,
16+ ParentElement, SharedString, Stateful, StatefulInteractiveElement, StyleRefinement, Styled,
17+ Window,
1718 assets::IconName,
1819 component::{
1920 WindowExt,
@@ -37,8 +38,6 @@ use super::{
3738 millis_time, notify_error, palette, text,
3839 };
3940
40-const ACCOUNTS_MAX_H: f32 = 180.;
41-
4241 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
4342 enum Removal {
4443 Kick,
@@ -112,11 +111,6 @@ pub(super) fn profile_popover(
112111 reporting: yumush.chat.report == Some(ReportTarget::User(user.id)),
113112 reason: yumush.chat.report_reason.clone(),
114113 status: yumush.chat.status_input.clone(),
115- others: yumush
116- .accounts
117- .others()
118- .map(|account| (account.user_id, account.username.clone()))
119- .collect(),
120114 volume: yumush
121115 .chat
122116 .user_volume
@@ -154,7 +148,6 @@ struct Card {
154148 reporting: bool,
155149 reason: Entity<InputState>,
156150 status: Entity<InputState>,
157- others: Vec<(Id, String)>,
158151 volume: Option<(Entity<SliderState>, f32)>,
159152 }
160153
@@ -395,12 +388,7 @@ impl Card {
395388 .truncate(),
396389 )
397390 .when(is_self, |name| {
398- name.child(account_menu(
399- self.others.clone(),
400- entity,
401- &popover,
402- palette,
403- ))
391+ name.child(account_menu(entity, &popover, palette))
404392 }),
405393 )
406394 .map(|names| {
@@ -639,54 +627,7 @@ fn main_self_rows(
639627 rows
640628 }
641629
642-fn accounts_rows(
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 {
630+fn account_menu(entity: &Entity<Yumush>, card: &Entity<PopoverState>, palette: Palette) -> Popover {
690631 let entity = entity.clone();
691632 let card = card.clone();
692633 Popover::new("account_menu")
@@ -699,10 +640,29 @@ fn account_menu(
699640 .flex_shrink_0()
700641 .child(small_icon(IconName::ChevronDown).text_color(palette.muted)),
701642 ))
702- .content(move |_, _, _| {
643+ .content(move |_, _, cx| {
644+ let yumush = entity.read(cx);
703645 super::parts::popover(palette.tokens)
704646 .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+ ))
706666 })
707667 }
708668