diff --git a/crates/client/src/gui.rs b/crates/client/src/gui.rs index a393323..5cacb31 100644 --- a/crates/client/src/gui.rs +++ b/crates/client/src/gui.rs @@ -904,7 +904,7 @@ impl Yumush { } fn show_view(&mut self, view: View, window: &mut Window, cx: &mut Context) { - self.chat.section = 0; + self.chat.section = None; if self.chat.view == View::Settings && view != View::Settings { self.leave_settings(); } diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index d616da8..8485989 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -173,7 +173,7 @@ pub struct Chat { highlight: Option<(Id, Instant)>, glide: Option<(Id, gpui_kit::Pixels, Instant)>, pub(super) view: View, - pub(super) section: usize, + pub(super) section: Option<&'static str>, pub(super) username_input: Entity, pub(super) community_name_input: Entity, pub(super) status_input: Entity, @@ -449,7 +449,7 @@ impl Chat { sidebar_collapsed: false, sidebar_toggled: None, view: View::Chat, - section: 0, + section: None, username_input: editable_input(w().chat.username, Yumush::save_username, window, cx), community_name_input: editable_input( w().chat.community_name, diff --git a/crates/client/src/gui/community_settings.rs b/crates/client/src/gui/community_settings.rs index 683126c..d29bbce 100644 --- a/crates/client/src/gui/community_settings.rs +++ b/crates/client/src/gui/community_settings.rs @@ -95,7 +95,8 @@ impl Yumush { let mut sections = Vec::new(); if let Some(community) = community.filter(|_| permission::can_rename_community(actor)) { - sections.push(Section( + sections.push(Section::new( + "profile", w().community_settings.profile, picture_card( Picture { @@ -121,6 +122,7 @@ impl Yumush { } if permission::can_rename_community(actor) { sections.push(section( + "general", w().community_settings.general, palette, vec![text_row( @@ -139,6 +141,7 @@ impl Yumush { } if let Some(community) = community.filter(|_| permission::can_manage_voice(actor)) { sections.push(section( + "voice", w().community_settings.voice, palette, vec![row( @@ -177,13 +180,14 @@ impl Yumush { } if !moderation.is_empty() { sections.push(section( + "moderation", w().community_settings.moderation, palette, moderation, )); } if permission::can_delete_community(actor) { - sections.push(danger(vec![ + sections.push(danger("danger_zone", vec![ delete_control( "delete_community_button", w().community_settings.delete_community, @@ -196,7 +200,12 @@ impl Yumush { ])); } if sections.is_empty() { - sections.push(section(w().community_settings.general, palette, Vec::new())); + sections.push(section( + "general", + w().community_settings.general, + palette, + Vec::new(), + )); } page( diff --git a/crates/client/src/gui/jump.rs b/crates/client/src/gui/jump.rs index 02777ed..4099a19 100644 --- a/crates/client/src/gui/jump.rs +++ b/crates/client/src/gui/jump.rs @@ -18,7 +18,7 @@ use super::{ community_icon, community_name, parts::{Ink, Text, band, words}, presence_avatar, - settings_page::{SETTINGS_IDS, setting_rows, settings_titles}, + settings_page::{SettingsSection, setting_rows}, style::{Theme, Tokens, my_hue, radius, size, space, stroke, text}, voice_settings::modes, widget::bare_input, @@ -32,7 +32,7 @@ pub(super) enum Place { Person(Id), Notes, Friends, - Settings(usize), + Settings(SettingsSection), Setting(usize), Builder(BuilderTab), NewCommunity, @@ -96,7 +96,7 @@ impl Place { Place::Person(id) => format!("person:{id}"), Place::Notes => "notes".into(), Place::Friends => "friends".into(), - Place::Settings(index) => format!("settings:{}", SETTINGS_IDS[index]), + Place::Settings(section) => format!("settings:{}", section.id()), Place::Setting(index) => format!("setting:{index}"), Place::Builder(tab) => format!("builder:{}", tab.id()), Place::NewCommunity => "new_community".into(), @@ -181,13 +181,12 @@ impl Yumush { ] .into_iter() .chain( - settings_titles() + SettingsSection::ALL .into_iter() - .enumerate() - .map(|(index, title)| { + .map(|section| { Row::new( - Place::Settings(index), - title.to_string(), + Place::Settings(section), + section.label().to_string(), Glyph::Icon(IconName::Settings2), ) .hinted(w().jump.hint_settings) @@ -203,7 +202,7 @@ impl Yumush { label.to_string(), Glyph::Icon(IconName::Settings2), ) - .hinted(settings_titles()[section]) + .hinted(section.label()) }), ) .chain( @@ -414,13 +413,13 @@ impl Yumush { } Place::Notes => self.open_notes(window, cx), Place::Friends => self.open_friends(window, cx), - Place::Settings(index) => { + Place::Settings(section) => { self.show_view(View::Settings, window, cx); - self.chat.section = index; + self.chat.section = Some(section.id()); } Place::Setting(index) => { self.show_view(View::Settings, window, cx); - self.chat.section = setting_rows()[index].0; + self.chat.section = Some(setting_rows()[index].0.id()); } Place::Builder(tab) => { self.show_view(View::Builder, window, cx); diff --git a/crates/client/src/gui/settings_page.rs b/crates/client/src/gui/settings_page.rs index 67b5f59..43737ed 100644 --- a/crates/client/src/gui/settings_page.rs +++ b/crates/client/src/gui/settings_page.rs @@ -29,54 +29,75 @@ use crate::{ share::encode::capabilities, }; -pub(super) const SETTINGS_IDS: [&str; 5] = [ - "profile", - "voice", - "camera_share", - "appearance", - "danger_zone", -]; - -pub(super) fn settings_titles() -> [&'static str; SETTINGS_IDS.len()] { - let w = &w().settings_page; - [ - w.profile, - w.voice, - w.camera_share, - w.appearance, - w.danger_zone, - ] +#[derive(Clone, Copy, PartialEq)] +pub(super) enum SettingsSection { + Profile, + Voice, + CameraShare, + Appearance, + DangerZone, } -pub(super) fn setting_rows() -> [(usize, &'static str); 25] { +impl SettingsSection { + pub(super) const ALL: [Self; 5] = [ + Self::Profile, + Self::Voice, + Self::CameraShare, + Self::Appearance, + Self::DangerZone, + ]; + + pub(super) fn id(self) -> &'static str { + match self { + Self::Profile => "profile", + Self::Voice => "voice", + Self::CameraShare => "camera_share", + Self::Appearance => "appearance", + Self::DangerZone => "danger_zone", + } + } + + pub(super) fn label(self) -> &'static str { + let w = &w().settings_page; + match self { + Self::Profile => w.profile, + Self::Voice => w.voice, + Self::CameraShare => w.camera_share, + Self::Appearance => w.appearance, + Self::DangerZone => w.danger_zone, + } + } +} + +pub(super) fn setting_rows() -> [(SettingsSection, &'static str); 25] { let s = &w().settings_page; let v = &w().voice_settings; [ - (0, s.name), - (0, s.status), - (0, s.presence), - (0, s.change_picture), - (4, s.delete_account), - (1, v.input_device), - (1, v.output_device), - (1, v.input_volume), - (1, v.output_volume), - (1, v.mode), - (1, v.hear_yourself), - (1, v.play_sound), - (1, v.sensitivity), - (1, v.key), - (2, s.camera), - (2, s.screen_share), - (2, s.codec), - (2, s.share_audio), - (3, s.theme), - (3, s.font_size), - (3, s.language), - (3, s.close_to_tray), - (3, s.launch), - (3, s.clock_seconds), - (3, s.your_hue), + (SettingsSection::Profile, s.name), + (SettingsSection::Profile, s.status), + (SettingsSection::Profile, s.presence), + (SettingsSection::Profile, s.change_picture), + (SettingsSection::DangerZone, s.delete_account), + (SettingsSection::Voice, v.input_device), + (SettingsSection::Voice, v.output_device), + (SettingsSection::Voice, v.input_volume), + (SettingsSection::Voice, v.output_volume), + (SettingsSection::Voice, v.mode), + (SettingsSection::Voice, v.hear_yourself), + (SettingsSection::Voice, v.play_sound), + (SettingsSection::Voice, v.sensitivity), + (SettingsSection::Voice, v.key), + (SettingsSection::CameraShare, s.camera), + (SettingsSection::CameraShare, s.screen_share), + (SettingsSection::CameraShare, s.codec), + (SettingsSection::CameraShare, s.share_audio), + (SettingsSection::Appearance, s.theme), + (SettingsSection::Appearance, s.font_size), + (SettingsSection::Appearance, s.language), + (SettingsSection::Appearance, s.close_to_tray), + (SettingsSection::Appearance, s.launch), + (SettingsSection::Appearance, s.clock_seconds), + (SettingsSection::Appearance, s.your_hue), ] } @@ -90,8 +111,9 @@ impl Yumush { let mut sections = Vec::new(); if let Some(user) = self.user.as_ref() { let presence_entity = entity.clone(); - sections.push(Section( - settings_titles()[0], + sections.push(Section::new( + SettingsSection::Profile.id(), + SettingsSection::Profile.label(), div() .flex() .flex_col() @@ -166,12 +188,14 @@ impl Yumush { )); } sections.push(section( - settings_titles()[1], + SettingsSection::Voice.id(), + SettingsSection::Voice.label(), palette, self.voice_rows(entity, palette, cx), )); - sections.push(Section( - settings_titles()[2], + sections.push(Section::new( + SettingsSection::CameraShare.id(), + SettingsSection::CameraShare.label(), camera_share(self, entity, palette), )); let mut appearance = vec![ @@ -246,9 +270,14 @@ impl Yumush { hue_picker(Some(style::hue_of(user.id)), entity, palette), )); } - sections.push(section(settings_titles()[3], palette, appearance)); + sections.push(section( + SettingsSection::Appearance.id(), + SettingsSection::Appearance.label(), + palette, + appearance, + )); if self.user.is_some() { - sections.push(danger(vec![ + sections.push(danger(SettingsSection::DangerZone.id(), vec![ delete_control( "delete_account_button", w().settings_page.delete_account, @@ -603,7 +632,17 @@ pub(super) fn picked_avatar( } } -pub(super) struct Section(pub &'static str, pub AnyElement); +pub(super) struct Section { + id: &'static str, + title: &'static str, + body: AnyElement, +} + +impl Section { + pub(super) fn new(id: &'static str, title: &'static str, body: AnyElement) -> Self { + Self { id, title, body } + } +} pub(super) fn page( id: &'static str, @@ -611,22 +650,26 @@ pub(super) fn page( palette: Palette, title: impl IntoElement, sections: Vec
, - selected: usize, + selected: Option<&'static str>, ) -> impl IntoElement { - let selected = selected.min(sections.len().saturating_sub(1)); + let selected = sections + .iter() + .position(|section| Some(section.id) == selected) + .unwrap_or(0); let index: Vec<_> = sections .iter() .enumerate() - .map(|(position, Section(name, _))| { + .map(|(position, section)| { let entity = entity.clone(); + let key = section.id; super::parts::index_item( - gpui_kit::ElementId::Name(format!("{id}_index_{name}").into()), - *name, + gpui_kit::ElementId::Name(format!("{id}_index_{key}").into()), + section.title, position == selected, palette.tokens, move |_, cx| { entity.update(cx, |yumush, cx| { - yumush.chat.section = position; + yumush.chat.section = Some(key); yumush.chat.armed = None; cx.notify(); }) @@ -635,7 +678,7 @@ pub(super) fn page( .into_any_element() }) .collect(); - let Some(Section(name, body)) = sections.into_iter().nth(selected) else { + let Some(Section { title: name, body, .. }) = sections.into_iter().nth(selected) else { return frame(id, entity, palette, title, index, Vec::new(), Vec::new()); }; @@ -744,12 +787,18 @@ pub(super) fn frame( ) } -pub(super) fn section(title: &'static str, palette: Palette, rows: Vec
) -> Section { - Section(title, rows_column(palette, rows)) +pub(super) fn section( + id: &'static str, + title: &'static str, + palette: Palette, + rows: Vec
, +) -> Section { + Section::new(id, title, rows_column(palette, rows).into_any_element()) } -pub(super) fn danger(actions: Vec) -> Section { - Section( +pub(super) fn danger(id: &'static str, actions: Vec) -> Section { + Section::new( + id, w().settings_page.danger_zone, div() .ml(px(-space::SM))