migrate to gpui-component

This commit is contained in:
2026-06-02 18:15:54 +07:00
parent 5d4c8634ef
commit bac04ab4da
116 changed files with 1165 additions and 24445 deletions

View File

@@ -4,26 +4,27 @@ use std::time::Duration;
use anyhow::{Context as AnyhowContext, Error};
use chat::{ChatEvent, ChatRegistry, Room, RoomKind};
use common::{DebouncedDelay, TimestampExt, coop_cache};
use common::{CoopIcon, DebouncedDelay, TimestampExt, coop_cache};
use entry::RoomEntry;
use gpui::prelude::FluentBuilder;
use gpui::{
App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable, IntoElement,
ParentElement, Render, SharedString, Styled, Subscription, Task, UniformListScrollHandle,
Window, div, uniform_list,
Window, div, px, uniform_list,
};
use gpui_component::button::{Button, ButtonVariants};
use gpui_component::dock::{Panel, PanelEvent};
use gpui_component::input::{Input, InputEvent, InputState};
use gpui_component::notification::Notification;
use gpui_component::scroll::Scrollbar;
use gpui_component::spinner::Spinner;
use gpui_component::{
ActiveTheme, Icon, Selectable, Sizable, StyledExt, WindowExt, h_flex, v_flex,
};
use nostr_sdk::prelude::*;
use person::PersonRegistry;
use smallvec::{SmallVec, smallvec};
use state::{FIND_DELAY, IMAGE_CACHE_SIZE, NostrRegistry};
use theme::{ActiveTheme, SIDEBAR_WIDTH, TABBAR_HEIGHT};
use ui::button::{Button, ButtonVariants};
use ui::dock::{Panel, PanelEvent};
use ui::indicator::Indicator;
use ui::input::{InputEvent, InputState, TextInput};
use ui::notification::Notification;
use ui::scroll::Scrollbar;
use ui::{Icon, IconName, Selectable, Sizable, StyledExt, WindowExtension, h_flex, v_flex};
mod entry;
@@ -35,7 +36,6 @@ pub fn init(window: &mut Window, cx: &mut App) -> Entity<Sidebar> {
/// Sidebar.
pub struct Sidebar {
name: SharedString,
focus_handle: FocusHandle,
scroll_handle: UniformListScrollHandle,
@@ -135,7 +135,6 @@ impl Sidebar {
);
Self {
name: "Sidebar".into(),
focus_handle: cx.focus_handle(),
scroll_handle: UniformListScrollHandle::new(),
find_input,
@@ -249,11 +248,10 @@ impl Sidebar {
}
/// Set the finding status
fn set_finding(&mut self, status: bool, _window: &mut Window, cx: &mut Context<Self>) {
fn set_finding(&mut self, status: bool, window: &mut Window, cx: &mut Context<Self>) {
// Disable the input to prevent duplicate requests
self.find_input.update(cx, |this, cx| {
this.set_disabled(status, cx);
this.set_loading(status, cx);
this.set_loading(status, window, cx);
});
// Set the search status
self.finding = status;
@@ -473,8 +471,8 @@ impl Sidebar {
}
impl Panel for Sidebar {
fn panel_id(&self) -> SharedString {
self.name.clone()
fn panel_name(&self) -> &'static str {
"Sidebar"
}
}
@@ -508,25 +506,27 @@ impl Render for Sidebar {
.gap_2()
.child(
h_flex()
.h(TABBAR_HEIGHT)
.h(px(28.0))
.border_b_1()
.border_color(cx.theme().border)
.bg(cx.theme().tab_background)
.bg(cx.theme().tab_bar)
.child(
TextInput::new(&self.find_input)
Input::new(&self.find_input)
.appearance(false)
.bordered(false)
.small()
.text_xs()
.when(!self.find_input.read(cx).loading, |this| {
this.suffix(
Button::new("find-icon")
.icon(IconName::Search)
.tooltip("Press Enter to search")
.transparent()
.small(),
)
}),
.text_xs(),
/*
.when(!self.find_input.read(cx).loading, |this| {
this.suffix(
Button::new("find-icon")
.icon(CoopIcon::Search)
.tooltip("Press Enter to search")
.transparent()
.small(),
)
})
*/
),
)
.child(
@@ -537,11 +537,10 @@ impl Render for Sidebar {
.when(show_find_panel, |this| {
this.child(
Button::new("search-results")
.icon(IconName::Search)
.icon(CoopIcon::Search)
.tooltip("All search results")
.small()
.ghost_alt()
.font_semibold()
.ghost()
.flex_1()
.selected(true),
)
@@ -550,16 +549,15 @@ impl Render for Sidebar {
Button::new("all")
.map(|this| {
if self.current_filter(&RoomKind::Ongoing, cx) {
this.icon(IconName::InboxFill)
this.icon(CoopIcon::InboxFill)
} else {
this.icon(IconName::Inbox)
this.icon(CoopIcon::Inbox)
}
})
.when(!show_find_panel, |this| this.label("Inbox"))
.tooltip("All ongoing conversations")
.small()
.ghost_alt()
.font_semibold()
.ghost()
.flex_1()
.selected(
!show_find_panel && self.current_filter(&RoomKind::Ongoing, cx),
@@ -572,22 +570,21 @@ impl Render for Sidebar {
Button::new("requests")
.map(|this| {
if self.current_filter(&RoomKind::Request, cx) {
this.icon(IconName::FistbumpFill)
this.icon(CoopIcon::FistbumpFill)
} else {
this.icon(IconName::Fistbump)
this.icon(CoopIcon::Fistbump)
}
})
.when(!show_find_panel, |this| this.label("Requests"))
.tooltip("Incoming new conversations")
.small()
.ghost_alt()
.font_semibold()
.ghost()
.flex_1()
.selected(
!show_find_panel && !self.current_filter(&RoomKind::Ongoing, cx),
)
.when(self.new_requests, |this| {
this.child(div().size_1().rounded_full().bg(cx.theme().cursor))
this.child(div().size_1().rounded_full().bg(cx.theme().caret))
})
.on_click(cx.listener(|this, _ev, window, cx| {
this.set_filter(RoomKind::default(), window, cx);
@@ -596,14 +593,14 @@ impl Render for Sidebar {
)
.when(!show_find_panel && !loading && total_rooms == 0, |this| {
this.child(
div().w(SIDEBAR_WIDTH).px_2().child(
div().w(px(240.)).px_2().child(
v_flex()
.p_3()
.h_24()
.w_full()
.border_2()
.border_dashed()
.border_color(cx.theme().border_variant)
.border_color(cx.theme().border)
.rounded(cx.theme().radius_lg)
.items_center()
.justify_center()
@@ -614,11 +611,14 @@ impl Render for Sidebar {
.font_semibold()
.child(SharedString::from("No conversations")),
)
.child(div().text_xs().text_color(cx.theme().text_muted).child(
SharedString::from(
"Start a conversation with someone to get started.",
),
)),
.child(
div()
.text_xs()
.text_color(cx.theme().muted_foreground)
.child(SharedString::from(
"Start a conversation with someone to get started.",
)),
),
),
)
})
@@ -635,14 +635,14 @@ impl Render for Sidebar {
.gap_1()
.flex_1()
.border_b_1()
.border_color(cx.theme().border_variant)
.border_color(cx.theme().border)
.child(
h_flex()
.gap_0p5()
.text_xs()
.font_semibold()
.text_color(cx.theme().text_muted)
.child(Icon::new(IconName::ChevronDown))
.text_color(cx.theme().muted_foreground)
.child(Icon::new(CoopIcon::ChevronDown))
.child(SharedString::from("Results")),
)
.child(
@@ -668,8 +668,8 @@ impl Render for Sidebar {
.gap_0p5()
.text_xs()
.font_semibold()
.text_color(cx.theme().text_muted)
.child(Icon::new(IconName::ChevronDown).small())
.text_color(cx.theme().muted_foreground)
.child(Icon::new(CoopIcon::ChevronDown).small())
.child(SharedString::from("Suggestions")),
)
.child(
@@ -740,14 +740,14 @@ impl Render for Sidebar {
.h_9()
.justify_center()
.bg(cx.theme().background.opacity(0.85))
.border_color(cx.theme().border_disabled)
.border_color(cx.theme().border)
.border_1()
.when(cx.theme().shadow, |this| this.shadow_xs())
.rounded_full()
.text_xs()
.font_semibold()
.text_color(cx.theme().text_muted)
.child(Indicator::new().small().color(cx.theme().icon_accent))
.text_color(cx.theme().muted_foreground)
.child(Spinner::new().small().color(cx.theme().primary_active))
.child(SharedString::from("Getting messages...")),
),
)