migrate ui components to gpui-kit
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
use gpui_kit::assets::IconName;
|
||||
use gpui_kit::component::avatar::Avatar;
|
||||
use gpui_kit::component::button::{Button, ButtonVariants};
|
||||
use gpui_kit::component::spinner::Spinner;
|
||||
use gpui_kit::component::{ActiveTheme, Disableable, Icon, Sizable, WindowExt, h_flex, v_flex};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::Error;
|
||||
@@ -12,11 +17,7 @@ use nostr_sdk::prelude::*;
|
||||
use person::{Directory, Person, PersonRegistry, shorten_pubkey};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use state::{BOOTSTRAP_RELAYS, NostrAddress, NostrRegistry, TIMEOUT};
|
||||
use theme::{ActiveTheme, TextStyle, Typeset as _, button_radius};
|
||||
use ui::avatar::Avatar;
|
||||
use ui::button::{Button, ButtonVariants};
|
||||
use ui::indicator::Indicator;
|
||||
use ui::{Disableable, Icon, IconName, Sizable, StyledExt, WindowExtension, h_flex, v_flex};
|
||||
use ui::{TextStyle, Typeset as _, button_radius};
|
||||
|
||||
pub fn init(public_key: PublicKey, window: &mut Window, cx: &mut App) -> Entity<Screening> {
|
||||
cx.new(|cx| Screening::new(public_key, window, cx))
|
||||
@@ -312,8 +313,13 @@ impl Screening {
|
||||
.gap_1p5()
|
||||
.rounded(px(button_radius()))
|
||||
.text_style(TextStyle::Callout)
|
||||
.hover(|this| this.bg(cx.theme().element_hover))
|
||||
.child(Avatar::new(profile.avatar()).small())
|
||||
.hover(|this| this.bg(cx.theme().primary))
|
||||
.child(match profile.avatar() {
|
||||
Some(picture) => {
|
||||
Avatar::new().src(picture).small().into_any_element()
|
||||
}
|
||||
None => Avatar::new().small().into_any_element(),
|
||||
})
|
||||
.child(profile.name()),
|
||||
);
|
||||
}
|
||||
@@ -365,10 +371,13 @@ impl Render for Screening {
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.text_center()
|
||||
.child(Avatar::new(profile.avatar()).large())
|
||||
.child(match profile.avatar() {
|
||||
Some(picture) => Avatar::new().src(picture).large().into_any_element(),
|
||||
None => Avatar::new().large().into_any_element(),
|
||||
})
|
||||
.child(
|
||||
div()
|
||||
.font_semibold()
|
||||
.font_weight(gpui::FontWeight::SEMIBOLD)
|
||||
.line_height(relative(1.25))
|
||||
.child(profile.name()),
|
||||
),
|
||||
@@ -383,7 +392,7 @@ impl Render for Screening {
|
||||
.h_7()
|
||||
.justify_center()
|
||||
.rounded_full()
|
||||
.bg(cx.theme().surface_raised)
|
||||
.bg(cx.theme().secondary)
|
||||
.text_style(TextStyle::Callout)
|
||||
.truncate()
|
||||
.text_ellipsis()
|
||||
@@ -398,9 +407,8 @@ impl Render for Screening {
|
||||
Button::new("njump")
|
||||
.icon(IconName::Link)
|
||||
.label("njump.me")
|
||||
.ghost_alt()
|
||||
.ghost()
|
||||
.small()
|
||||
.rounded()
|
||||
.on_click(cx.listener(move |this, _e, window, cx| {
|
||||
this.open_njump(window, cx);
|
||||
})),
|
||||
@@ -408,9 +416,8 @@ impl Render for Screening {
|
||||
.child(
|
||||
Button::new("report")
|
||||
.tooltip("Report as a scam or impostor")
|
||||
.icon(IconName::Warning)
|
||||
.icon(IconName::TriangleAlert)
|
||||
.warning()
|
||||
.rounded()
|
||||
.on_click(cx.listener(move |this, _e, window, cx| {
|
||||
this.report(window, cx);
|
||||
})),
|
||||
@@ -423,7 +430,7 @@ impl Render for Screening {
|
||||
.child(
|
||||
h_flex()
|
||||
.items_start()
|
||||
.gap(px(theme::SPACE))
|
||||
.gap(px(ui::SPACE))
|
||||
.text_style(TextStyle::Callout)
|
||||
.child(status_badge(Some(self.followed), cx))
|
||||
.child(
|
||||
@@ -433,7 +440,7 @@ impl Render for Screening {
|
||||
.child(
|
||||
div()
|
||||
.line_clamp(1)
|
||||
.text_color(cx.theme().text_muted)
|
||||
.text_color(cx.theme().muted_foreground)
|
||||
.child({
|
||||
if self.followed {
|
||||
SharedString::from(CONTACT)
|
||||
@@ -447,7 +454,7 @@ impl Render for Screening {
|
||||
.child(
|
||||
h_flex()
|
||||
.items_start()
|
||||
.gap(px(theme::SPACE))
|
||||
.gap(px(ui::SPACE))
|
||||
.text_style(TextStyle::Callout)
|
||||
.child(status_badge(last_active, cx))
|
||||
.child(
|
||||
@@ -462,7 +469,6 @@ impl Render for Screening {
|
||||
.icon(IconName::Info)
|
||||
.xsmall()
|
||||
.ghost()
|
||||
.rounded()
|
||||
.tooltip(RELAY_INFO),
|
||||
),
|
||||
)
|
||||
@@ -470,7 +476,7 @@ impl Render for Screening {
|
||||
div()
|
||||
.w_full()
|
||||
.line_clamp(1)
|
||||
.text_color(cx.theme().text_muted)
|
||||
.text_color(cx.theme().muted_foreground)
|
||||
.map(|this| {
|
||||
if let Some(t) = self.last_active {
|
||||
this.child(SharedString::from(format!(
|
||||
@@ -487,7 +493,7 @@ impl Render for Screening {
|
||||
.child(
|
||||
h_flex()
|
||||
.items_start()
|
||||
.gap(px(theme::SPACE))
|
||||
.gap(px(ui::SPACE))
|
||||
.child(status_badge(Some(self.verified), cx))
|
||||
.child(
|
||||
v_flex()
|
||||
@@ -504,7 +510,7 @@ impl Render for Screening {
|
||||
.child(
|
||||
div()
|
||||
.line_clamp(1)
|
||||
.text_color(cx.theme().text_muted)
|
||||
.text_color(cx.theme().muted_foreground)
|
||||
.child({
|
||||
if self.address(cx).is_some() {
|
||||
if self.verified {
|
||||
@@ -522,7 +528,7 @@ impl Render for Screening {
|
||||
.child(
|
||||
h_flex()
|
||||
.items_start()
|
||||
.gap(px(theme::SPACE))
|
||||
.gap(px(ui::SPACE))
|
||||
.child(status_badge(Some(mutuals > 0), cx))
|
||||
.child(
|
||||
h_flex()
|
||||
@@ -530,7 +536,7 @@ impl Render for Screening {
|
||||
.child(
|
||||
div()
|
||||
.line_clamp(1)
|
||||
.text_color(cx.theme().text_muted)
|
||||
.text_color(cx.theme().muted_foreground)
|
||||
.child({
|
||||
if mutuals > 0 {
|
||||
SharedString::from(mutuals_str)
|
||||
@@ -544,7 +550,6 @@ impl Render for Screening {
|
||||
.icon(IconName::Info)
|
||||
.xsmall()
|
||||
.ghost()
|
||||
.rounded()
|
||||
.disabled(mutuals == 0)
|
||||
.on_click(cx.listener(move |this, _, window, cx| {
|
||||
this.mutual_contacts(
|
||||
@@ -567,15 +572,15 @@ fn status_badge(status: Option<bool>, cx: &App) -> Div {
|
||||
.flex_shrink_0()
|
||||
.map(|this| {
|
||||
if let Some(status) = status {
|
||||
this.child(Icon::new(IconName::CheckCircle).small().text_color({
|
||||
this.child(Icon::new(IconName::CircleCheck).small().text_color({
|
||||
if status {
|
||||
cx.theme().accent
|
||||
cx.theme().primary
|
||||
} else {
|
||||
cx.theme().text_faint
|
||||
cx.theme().muted_foreground
|
||||
}
|
||||
}))
|
||||
} else {
|
||||
this.child(Indicator::new().small())
|
||||
this.child(Spinner::new().small())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user