use auto_update::AutoUpdater; use gpui::prelude::FluentBuilder; use gpui::{ AnyElement, App, Context, Div, Entity, InteractiveElement, IntoElement, ParentElement, Stateful, Styled, div, px, }; use gpui_kit::assets::IconName; use gpui_kit::component::button::{Button, ButtonVariants}; use gpui_kit::component::menu::DropdownMenu; use gpui_kit::component::{Disableable, Selectable, Sizable, h_flex}; use nostr_sdk::prelude::*; use ui::Avatar; use super::Sidebar; use crate::Command; use crate::dock::TAB_BAR_HEIGHT; impl Sidebar { pub(super) fn render_user( &self, current_user: &PublicKey, cx: &mut Context, ) -> Stateful
{ let updater = AutoUpdater::try_global(cx); let profile = self.directory.read(cx).person(current_user, cx); let avatar = profile.avatar(); h_flex() .id("sidebar-user") .w_full() .h(TAB_BAR_HEIGHT) .flex_shrink_0() .items_center() .gap_2() .px_2() .when(cfg!(target_os = "macos"), |this| this.pl(px(80.))) .child( Button::new("current-user") .child( Avatar::new(avatar.clone()) .seed(profile.avatar_seed()) .small(), ) .small() .dropdown_caret(true) .compact() .text() .dropdown_menu(move |this, _window, _cx| { this.menu_with_icon( "Profile", IconName::UserRound, Box::new(Command::ShowProfile), ) .menu_with_icon( "Relays", IconName::RadioTower, Box::new(Command::ShowRelayList), ) .separator() .menu_with_icon( "Settings", IconName::Settings, Box::new(Command::ShowSettings), ) }), ) .child(div().flex_1()) .when_some(updater, |this, updater| { this.child(self.render_updater(updater, cx)) }) .child( Button::new("sidebar-search") .icon(IconName::Search) .tooltip("Search") .selected(self.search_open) .ghost() .small() .on_click(cx.listener(|this, _event, window, cx| { this.toggle_search(window, cx); })), ) .child( Button::new("sidebar-new") .icon(IconName::MessageSquarePlus) .tooltip("New") .ghost() .small() .dropdown_menu(|menu, _window, _cx| { menu.label("Public Group") .menu_with_icon( "New Group", IconName::Users, Box::new(Command::NewGroup), ) .menu_with_icon( "Join Group", IconName::DoorOpen, Box::new(Command::JoinGroup), ) .separator() .menu_with_icon( "New Chat", IconName::MessageSquare, Box::new(Command::NewChat), ) }), ) .when(self.group_open, |this| { this.child( Button::new("sidebar-back") .icon(IconName::ArrowLeft) .tooltip("Back") .ghost() .small() .on_click(cx.listener(|this, _event, _window, cx| { this.hide_group(cx); })), ) }) } fn render_updater(&self, updater: Entity, cx: &mut App) -> AnyElement { let status = updater.read(cx).status(); let up_to_date = updater.read(cx).up_to_date(); let staged = updater.read(cx).staged(); h_flex() .gap_2() .when(!up_to_date, |this| { this.child( Button::new("update") .icon(IconName::CircleArrowDown) .tooltip(status) .small() .ghost() .disabled(true), ) }) .when(staged, |this| { this.child( Button::new("restart") .icon(IconName::CircleArrowDown) .tooltip("Quit and relaunch into the installed update") .small() .ghost() .on_click(move |_, _window, cx| { updater.update(cx, |this, cx| { this.restart(cx); }); }), ) }) .into_any_element() } }