chore: restructure ui components
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
use std::sync::LazyLock;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, Entity, InteractiveElement as _, IntoElement, ParentElement as _, SharedString,
|
||||
Entity, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, SharedString,
|
||||
StatefulInteractiveElement as _, Styled as _, WeakEntity, div, px,
|
||||
};
|
||||
use metadata::ProfileDirectory;
|
||||
@@ -16,23 +13,11 @@ use ui::theme::ActiveTheme as _;
|
||||
use utils::relative_time;
|
||||
|
||||
use crate::app::AppRoot;
|
||||
use crate::repo::actions::open_repo_panel;
|
||||
use crate::repo::helpers::{announcement_display_name, upstream_display_name};
|
||||
use crate::shared::labels::{AnnouncementExt as _, AnnouncementsExt as _};
|
||||
use crate::shared::log_dropped;
|
||||
|
||||
const RECENT_COUNT: usize = 10;
|
||||
|
||||
/// One of the three banner photos, picked per process launch.
|
||||
pub fn pick_banner() -> SharedString {
|
||||
static BANNER: LazyLock<SharedString> = LazyLock::new(|| {
|
||||
let nanos = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.map(|now| now.subsec_nanos())
|
||||
.unwrap_or(0);
|
||||
SharedString::from(format!("backgrounds/banner{}.jpg", nanos % 3 + 1))
|
||||
});
|
||||
BANNER.clone()
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub(super) enum RepoFilter {
|
||||
#[default]
|
||||
@@ -64,127 +49,187 @@ impl RepoFilter {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn render_card(
|
||||
announcement: &Announcement,
|
||||
last_activity: Option<Timestamp>,
|
||||
announcements: &[Announcement],
|
||||
directory: &Entity<ProfileDirectory>,
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
cx: &mut gpui::App,
|
||||
) -> AnyElement {
|
||||
let owner = directory.read(cx).profile(&announcement.owner, cx);
|
||||
let owner_name = owner.name();
|
||||
let workspace = workspace.clone();
|
||||
let announcement = announcement.clone();
|
||||
/// One explore card's display strings, built when the row list is rebuilt.
|
||||
#[derive(Clone)]
|
||||
pub(super) struct CardData {
|
||||
/// Index into the store's `announcements`.
|
||||
pub(super) ix: usize,
|
||||
/// The announcement's element id.
|
||||
pub(super) id: SharedString,
|
||||
pub(super) name: SharedString,
|
||||
pub(super) description: SharedString,
|
||||
pub(super) activity: SharedString,
|
||||
pub(super) fork_label: Option<SharedString>,
|
||||
}
|
||||
|
||||
let name = announcement_display_name(&announcement);
|
||||
impl CardData {
|
||||
pub(super) fn new(
|
||||
ix: usize,
|
||||
announcement: &Announcement,
|
||||
announcements: &[Announcement],
|
||||
last_activity: Option<Timestamp>,
|
||||
) -> Self {
|
||||
let activity = last_activity
|
||||
.map(relative_time)
|
||||
.map(|label| SharedString::from(format!("Updated {label}")))
|
||||
.unwrap_or_default();
|
||||
|
||||
let description = announcement
|
||||
.description
|
||||
.as_deref()
|
||||
.map(SharedString::from)
|
||||
.unwrap_or_else(|| SharedString::from("No description"));
|
||||
let fork_label = announcement.upstream.as_ref().and_then(|upstream| {
|
||||
let addr = upstream.addr.as_ref()?;
|
||||
let name = announcements.upstream_display_name(addr);
|
||||
Some(SharedString::from(format!("forked from {name}")))
|
||||
});
|
||||
|
||||
let activity = last_activity
|
||||
.map(relative_time)
|
||||
.map(|label| SharedString::from(format!("Updated {label}")))
|
||||
.unwrap_or_default();
|
||||
Self {
|
||||
ix,
|
||||
id: SharedString::from(format!("repo-card:{}", announcement.id)),
|
||||
name: announcement.display_name(),
|
||||
description: announcement
|
||||
.description
|
||||
.as_deref()
|
||||
.map(SharedString::from)
|
||||
.unwrap_or_else(|| SharedString::from("No description")),
|
||||
activity,
|
||||
fork_label,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let fork_label: Option<SharedString> = announcement.upstream.as_ref().and_then(|upstream| {
|
||||
let addr = upstream.addr.as_ref()?;
|
||||
let name = upstream_display_name(addr, announcements);
|
||||
Some(SharedString::from(format!("forked from {name}")))
|
||||
});
|
||||
/// One repository card in the explore grid.
|
||||
#[derive(IntoElement)]
|
||||
pub(super) struct RepoCard {
|
||||
data: CardData,
|
||||
announcement: Announcement,
|
||||
directory: Entity<ProfileDirectory>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
}
|
||||
|
||||
v_flex()
|
||||
.id(SharedString::from(format!("repo-card:{}", announcement.id)))
|
||||
.flex_1()
|
||||
.h_full()
|
||||
.min_w_0()
|
||||
.px_3()
|
||||
.rounded(cx.theme().radius.control)
|
||||
.border_1()
|
||||
.border_color(cx.theme().colors.border)
|
||||
.hover(|this| this.bg(cx.theme().colors.muted_hover))
|
||||
.child(
|
||||
h_flex()
|
||||
.h_10()
|
||||
.gap_2()
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.text_sm()
|
||||
.font_semibold()
|
||||
.whitespace_nowrap()
|
||||
.text_ellipsis()
|
||||
.child(name),
|
||||
)
|
||||
.when_some(fork_label, |this, label| {
|
||||
this.child(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.text_xs()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
impl RepoCard {
|
||||
pub(super) fn new(
|
||||
data: &CardData,
|
||||
announcement: &Announcement,
|
||||
directory: &Entity<ProfileDirectory>,
|
||||
workspace: &WeakEntity<AppRoot>,
|
||||
) -> Self {
|
||||
Self {
|
||||
data: data.clone(),
|
||||
announcement: announcement.clone(),
|
||||
directory: directory.clone(),
|
||||
workspace: workspace.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for RepoCard {
|
||||
fn render(self, _window: &mut gpui::Window, cx: &mut gpui::App) -> impl IntoElement {
|
||||
let Self {
|
||||
data,
|
||||
announcement,
|
||||
directory,
|
||||
workspace,
|
||||
} = self;
|
||||
|
||||
let CardData {
|
||||
id,
|
||||
name,
|
||||
description,
|
||||
activity,
|
||||
fork_label,
|
||||
..
|
||||
} = &data;
|
||||
|
||||
let owner = directory.read(cx).profile(&announcement.owner, cx);
|
||||
let owner_name = owner.name();
|
||||
|
||||
v_flex()
|
||||
.id(id.clone())
|
||||
.flex_1()
|
||||
.h_full()
|
||||
.min_w_0()
|
||||
.px_3()
|
||||
.rounded(cx.theme().radius.control)
|
||||
.border_1()
|
||||
.border_color(cx.theme().colors.border)
|
||||
.hover(|this| this.bg(cx.theme().colors.muted_hover))
|
||||
.child(
|
||||
h_flex()
|
||||
.h_10()
|
||||
.gap_2()
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.text_sm()
|
||||
.font_semibold()
|
||||
.whitespace_nowrap()
|
||||
.child(
|
||||
Icon::named(IconRole::GitBranch)
|
||||
.size(px(12.))
|
||||
.color(cx.theme().colors.muted_foreground),
|
||||
)
|
||||
.child(label),
|
||||
.text_ellipsis()
|
||||
.child(name.clone()),
|
||||
)
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.h_16()
|
||||
.min_w_0()
|
||||
.text_xs()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.line_clamp(2)
|
||||
.child(description),
|
||||
)
|
||||
.child(
|
||||
h_flex()
|
||||
.h_12()
|
||||
.gap_2()
|
||||
.overflow_hidden()
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.child(
|
||||
Avatar::new(announcement.owner)
|
||||
.name(owner_name.clone())
|
||||
.picture(owner.picture())
|
||||
.small(),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.when_some(fork_label.clone(), |this, label| {
|
||||
this.child(
|
||||
h_flex()
|
||||
.flex_shrink_0()
|
||||
.gap_1()
|
||||
.text_xs()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.whitespace_nowrap()
|
||||
.child(owner_name),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
h_flex()
|
||||
.flex_1()
|
||||
.justify_end()
|
||||
.text_xs()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.whitespace_nowrap()
|
||||
.child(activity),
|
||||
),
|
||||
)
|
||||
.on_click(move |_, window, cx| {
|
||||
open_repo_panel(
|
||||
&workspace,
|
||||
&announcement.addr(),
|
||||
Some(&announcement),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
.into_any_element()
|
||||
.child(
|
||||
Icon::named(IconRole::GitBranch)
|
||||
.size(px(12.))
|
||||
.color(cx.theme().colors.muted_foreground),
|
||||
)
|
||||
.child(label),
|
||||
)
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.h_16()
|
||||
.min_w_0()
|
||||
.text_xs()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.line_clamp(2)
|
||||
.child(description.clone()),
|
||||
)
|
||||
.child(
|
||||
h_flex()
|
||||
.h_12()
|
||||
.gap_2()
|
||||
.overflow_hidden()
|
||||
.child(
|
||||
h_flex()
|
||||
.min_w_0()
|
||||
.gap_2()
|
||||
.child(
|
||||
Avatar::new(announcement.owner)
|
||||
.name(owner_name.clone())
|
||||
.picture(owner.picture())
|
||||
.small(),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.min_w_0()
|
||||
.truncate()
|
||||
.text_xs()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child(owner_name),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
h_flex()
|
||||
.flex_1()
|
||||
.justify_end()
|
||||
.text_xs()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.whitespace_nowrap()
|
||||
.child(activity.clone()),
|
||||
),
|
||||
)
|
||||
.on_click(move |_, window, cx| {
|
||||
let result = workspace.update(cx, |root, cx| {
|
||||
root.open_repo_panel(&announcement.addr(), Some(&announcement), window, cx);
|
||||
});
|
||||
log_dropped(result);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
mod helpers;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::{
|
||||
@@ -5,7 +8,7 @@ use gpui::{
|
||||
ObjectFit, ParentElement as _, Pixels, Render, SharedString, Styled as _, StyledImage as _,
|
||||
Subscription, WeakEntity, Window, div, img, list, px,
|
||||
};
|
||||
use helpers::{RepoFilter, render_card};
|
||||
use helpers::{CardData, RepoCard, RepoFilter};
|
||||
use metadata::ProfileDirectory;
|
||||
use nostr::prelude::PublicKey;
|
||||
use signed_state::{Backend, RepoListStore};
|
||||
@@ -14,24 +17,21 @@ use ui::common::{h_flex, v_flex};
|
||||
use ui::empty_state::EmptyState;
|
||||
use ui::icons::{Icon, IconRole};
|
||||
use ui::input::{Input, InputState, InputStateEvent};
|
||||
use ui::layout::panel::{Panel, PanelSlot, SplitSide};
|
||||
use ui::layout::root::RootContext as _;
|
||||
use ui::layout::panel::{Panel, PanelSlot, PanelStack, SplitSide};
|
||||
use ui::scrollbar::Scrollbar;
|
||||
use ui::segmented::{Segmented, SegmentedOption};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
|
||||
use crate::app::AppRoot;
|
||||
use crate::explore::helpers::pick_banner;
|
||||
use crate::identity::import::ImportDialog;
|
||||
use crate::identity::onboarding::OnboardingDialog;
|
||||
use crate::shared::log_dropped;
|
||||
|
||||
mod helpers;
|
||||
|
||||
const COLUMNS: usize = 2;
|
||||
// Name row, avatar strip, meta row, and their borders and gaps, in px.
|
||||
const CARD_HEIGHT: f32 = 40. + 64. + 48. + 2. + 6.;
|
||||
|
||||
/// Applies a new explore filter.
|
||||
type FilterHandler = Rc<dyn Fn(RepoFilter, &mut Window, &mut App)>;
|
||||
|
||||
pub struct ExploreView {
|
||||
store: Entity<RepoListStore>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
@@ -39,6 +39,8 @@ pub struct ExploreView {
|
||||
filter: RepoFilter,
|
||||
/// Indices matching [`Self::filter`] into the store's `announcements`.
|
||||
visible: Vec<usize>,
|
||||
/// The visible cards' display strings, rebuilt with `visible`.
|
||||
cards: Arc<Vec<CardData>>,
|
||||
search: Entity<InputState>,
|
||||
/// Profiles for the card owners.
|
||||
directory: Entity<ProfileDirectory>,
|
||||
@@ -53,28 +55,28 @@ impl ExploreView {
|
||||
pub(crate) const PANEL_ID: &'static str = "Explore";
|
||||
|
||||
/// Opens the explore panel in the main panel, reusing it when it is already cached.
|
||||
pub(crate) fn open(workspace: &WeakEntity<AppRoot>, window: &mut Window, cx: &mut App) {
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.panels().clone().update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Main,
|
||||
Self::PANEL_ID,
|
||||
{
|
||||
let workspace = workspace.clone();
|
||||
move |_, cx| cx.new(|cx| Self::new(workspace.clone(), cx))
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}));
|
||||
pub(crate) fn open(
|
||||
panels: &Entity<PanelStack>,
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) {
|
||||
panels.update(cx, |panels, cx| {
|
||||
panels.open(
|
||||
PanelSlot::Main,
|
||||
Self::PANEL_ID,
|
||||
move |_, cx| cx.new(|cx| Self::new(workspace.clone(), cx)),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn new(workspace: WeakEntity<AppRoot>, cx: &mut Context<Self>) -> Self {
|
||||
let store = RepoListStore::global(cx);
|
||||
let directory = ProfileDirectory::new(cx);
|
||||
|
||||
let weak = cx.entity().downgrade();
|
||||
let weak = cx.weak_entity();
|
||||
let search = InputState::new(cx);
|
||||
|
||||
let search_subscription = cx.subscribe(&search, |this, _search, event, cx| {
|
||||
@@ -103,6 +105,7 @@ impl ExploreView {
|
||||
scroll_handle: ListState::new(1, ListAlignment::Top, px(320.)),
|
||||
filter: RepoFilter::default(),
|
||||
visible: Vec::new(),
|
||||
cards: Arc::new(Vec::new()),
|
||||
search,
|
||||
directory,
|
||||
_search_subscription: search_subscription,
|
||||
@@ -118,6 +121,21 @@ impl ExploreView {
|
||||
let store = self.store.read(cx);
|
||||
|
||||
self.visible = filter.visible(store, &query);
|
||||
self.cards = Arc::new(
|
||||
self.visible
|
||||
.iter()
|
||||
.filter_map(|ix| {
|
||||
let announcement = store.announcements.get(*ix)?;
|
||||
let activity = store.last_activity.get(&announcement.addr()).copied();
|
||||
Some(CardData::new(
|
||||
*ix,
|
||||
announcement,
|
||||
&store.announcements,
|
||||
activity,
|
||||
))
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
|
||||
let owners: Vec<PublicKey> = self
|
||||
.visible
|
||||
@@ -156,8 +174,10 @@ impl ExploreView {
|
||||
log::warn!("failed to watch the panel stack: the app root is gone");
|
||||
return;
|
||||
};
|
||||
self._stack_subscription =
|
||||
Some(cx.observe(&stack, |this, _stack, cx| this.sync_sidebar(cx)));
|
||||
|
||||
self._stack_subscription = Some(cx.observe(&stack, |this, _stack, cx| {
|
||||
this.sync_sidebar(cx);
|
||||
}));
|
||||
self.sync_sidebar(cx);
|
||||
}
|
||||
|
||||
@@ -172,7 +192,9 @@ impl ExploreView {
|
||||
let shown = signed_out && stack.is_active(PanelSlot::Main, &explore);
|
||||
|
||||
if shown && !stack.is_open(PanelSlot::Split, &sidebar) {
|
||||
let view = Arc::new(cx.new(|_| OnboardingSidebar));
|
||||
let view = Arc::new(cx.new(|_| OnboardingSidebar {
|
||||
workspace: self.workspace.clone(),
|
||||
}));
|
||||
stack.insert_split_at(
|
||||
sidebar.clone(),
|
||||
OnboardingSidebar::WIDTH,
|
||||
@@ -180,7 +202,7 @@ impl ExploreView {
|
||||
view,
|
||||
cx,
|
||||
);
|
||||
} else if !shown {
|
||||
} else if !shown && stack.is_open(PanelSlot::Split, &sidebar) {
|
||||
stack.close(PanelSlot::Split, &sidebar, cx);
|
||||
}
|
||||
})
|
||||
@@ -191,12 +213,63 @@ impl ExploreView {
|
||||
}
|
||||
}
|
||||
|
||||
/// One list row: the search header, or one strip of repository cards.
|
||||
fn render_list_item(&mut self, item: usize, cx: &mut Context<Self>) -> AnyElement {
|
||||
if item == 0 {
|
||||
let on_filter: FilterHandler =
|
||||
Rc::new(cx.processor(|this, filter: RepoFilter, _, cx| {
|
||||
this.filter = filter;
|
||||
this.rebuild_rows(false, cx);
|
||||
}));
|
||||
return Self::render_header(self.search.clone(), self.filter, on_filter, cx)
|
||||
.into_any_element();
|
||||
}
|
||||
|
||||
if self.visible.is_empty() {
|
||||
return v_flex()
|
||||
.w_full()
|
||||
.h(px(320.))
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child(EmptyState::new("No repositories match your search"))
|
||||
.into_any_element();
|
||||
}
|
||||
|
||||
let store = self.store.read(cx);
|
||||
let row = item - 1;
|
||||
let mut rendered = Vec::with_capacity(COLUMNS);
|
||||
|
||||
for col in 0..COLUMNS {
|
||||
let Some(data) = self.cards.get(row * COLUMNS + col) else {
|
||||
break;
|
||||
};
|
||||
let Some(announcement) = store.announcements.get(data.ix) else {
|
||||
break;
|
||||
};
|
||||
rendered.push(RepoCard::new(
|
||||
data,
|
||||
announcement,
|
||||
&self.directory,
|
||||
&self.workspace,
|
||||
));
|
||||
}
|
||||
|
||||
h_flex()
|
||||
.w_full()
|
||||
.h(px(CARD_HEIGHT))
|
||||
.gap_3()
|
||||
.px_4()
|
||||
.pt_4()
|
||||
.children(rendered)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
fn render_header(
|
||||
search: Entity<InputState>,
|
||||
filter: RepoFilter,
|
||||
weak: WeakEntity<Self>,
|
||||
on_filter: FilterHandler,
|
||||
cx: &App,
|
||||
) -> AnyElement {
|
||||
) -> impl IntoElement {
|
||||
let muted = cx.theme().colors.muted_foreground;
|
||||
|
||||
div()
|
||||
@@ -231,17 +304,11 @@ impl ExploreView {
|
||||
.label("Recent")
|
||||
.icon(Icon::named(IconRole::Clock).small().color(muted)),
|
||||
])
|
||||
.on_change(move |filter, _, cx| {
|
||||
if let Err(error) = weak.update(cx, |this, cx| {
|
||||
this.filter = filter;
|
||||
this.rebuild_rows(false, cx);
|
||||
}) {
|
||||
log::warn!("failed to change explore filter: {error}");
|
||||
}
|
||||
.on_change(move |filter, window, cx| {
|
||||
on_filter(filter, window, cx);
|
||||
}),
|
||||
),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,67 +329,16 @@ impl Panel for ExploreView {
|
||||
|
||||
impl Render for ExploreView {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let store = self.store.read(cx);
|
||||
let announcements = store.announcements.clone();
|
||||
let last_activity = store.last_activity.clone();
|
||||
let visible = self.visible.clone();
|
||||
let directory = self.directory.clone();
|
||||
let workspace = self.workspace.clone();
|
||||
let has_repos = !visible.is_empty();
|
||||
let search = self.search.clone();
|
||||
let filter = self.filter;
|
||||
let weak = cx.entity().downgrade();
|
||||
let scroll_handle = self.scroll_handle.clone();
|
||||
|
||||
div()
|
||||
.relative()
|
||||
.size_full()
|
||||
.child(
|
||||
list(self.scroll_handle.clone(), move |item, _, cx| {
|
||||
if item == 0 {
|
||||
return Self::render_header(search.clone(), filter, weak.clone(), cx);
|
||||
}
|
||||
|
||||
if !has_repos {
|
||||
return v_flex()
|
||||
.w_full()
|
||||
.h(px(320.))
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child(EmptyState::new("No repositories match your search"))
|
||||
.into_any_element();
|
||||
}
|
||||
|
||||
let row = item - 1;
|
||||
let mut cards = Vec::with_capacity(COLUMNS);
|
||||
|
||||
for col in 0..COLUMNS {
|
||||
let Some(&ix) = visible.get(row * COLUMNS + col) else {
|
||||
break;
|
||||
};
|
||||
let Some(announcement) = announcements.get(ix) else {
|
||||
break;
|
||||
};
|
||||
let activity = last_activity.get(&announcement.addr()).copied();
|
||||
cards.push(render_card(
|
||||
announcement,
|
||||
activity,
|
||||
&announcements,
|
||||
&directory,
|
||||
&workspace,
|
||||
cx,
|
||||
));
|
||||
}
|
||||
|
||||
h_flex()
|
||||
.w_full()
|
||||
.h(px(CARD_HEIGHT))
|
||||
.gap_3()
|
||||
.px_4()
|
||||
.pt_4()
|
||||
.children(cards)
|
||||
.into_any_element()
|
||||
})
|
||||
list(
|
||||
self.scroll_handle.clone(),
|
||||
cx.processor(|this, item: usize, _window, cx| this.render_list_item(item, cx)),
|
||||
)
|
||||
.size_full(),
|
||||
)
|
||||
.child(Scrollbar::vertical("explore-scroll", scroll_handle))
|
||||
@@ -330,13 +346,27 @@ impl Render for ExploreView {
|
||||
}
|
||||
|
||||
/// The onboarding sidebar shown beside the explore panel while signed out.
|
||||
struct OnboardingSidebar;
|
||||
struct OnboardingSidebar {
|
||||
workspace: WeakEntity<AppRoot>,
|
||||
}
|
||||
|
||||
impl OnboardingSidebar {
|
||||
/// The identifier of the sidebar in the panel stack; shown as its tab label.
|
||||
const PANEL_ID: &'static str = "Onboarding";
|
||||
/// The width the sidebar opens at.
|
||||
const WIDTH: Pixels = px(300.);
|
||||
|
||||
/// One of the three banner photos, picked per process launch.
|
||||
fn banner() -> SharedString {
|
||||
static BANNER: std::sync::LazyLock<SharedString> = std::sync::LazyLock::new(|| {
|
||||
let nanos = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map(|now| now.subsec_nanos())
|
||||
.unwrap_or(0);
|
||||
SharedString::from(format!("backgrounds/banner{}.jpg", nanos % 3 + 1))
|
||||
});
|
||||
BANNER.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for OnboardingSidebar {
|
||||
@@ -349,6 +379,7 @@ impl Render for OnboardingSidebar {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let colors = theme.colors;
|
||||
let workspace = self.workspace.clone();
|
||||
|
||||
v_flex()
|
||||
.size_full()
|
||||
@@ -358,7 +389,7 @@ impl Render for OnboardingSidebar {
|
||||
.overflow_hidden()
|
||||
.child(
|
||||
div().absolute().inset_0().child(
|
||||
img(pick_banner())
|
||||
img(OnboardingSidebar::banner())
|
||||
.size_full()
|
||||
.object_fit(ObjectFit::Cover)
|
||||
.rounded(theme.radius.overlay),
|
||||
@@ -379,18 +410,26 @@ impl Render for OnboardingSidebar {
|
||||
Button::new("join")
|
||||
.label("Join now")
|
||||
.variant(ButtonVariant::Primary)
|
||||
.on_click(|_, _, cx| {
|
||||
let dialog = OnboardingDialog::new(cx);
|
||||
cx.open_dialog(dialog)
|
||||
.on_click({
|
||||
let workspace = workspace.clone();
|
||||
move |_, _, cx| {
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.open_onboarding_dialog(cx)
|
||||
}));
|
||||
}
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
Button::new("import")
|
||||
.label("Import identity")
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.on_click(|_, _, cx| {
|
||||
let dialog = ImportDialog::new(cx);
|
||||
cx.open_dialog(dialog)
|
||||
.on_click({
|
||||
let workspace = workspace.clone();
|
||||
move |_, window, cx| {
|
||||
log_dropped(workspace.update(cx, |root, cx| {
|
||||
root.open_import_dialog(window, cx)
|
||||
}));
|
||||
}
|
||||
}),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user