update
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
mod helpers;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, Render, SharedString, Styled as _, Subscription, UniformListScrollHandle,
|
||||
WeakEntity, Window, div, px, uniform_list,
|
||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ListAlignment, ListState,
|
||||
ParentElement as _, Render, SharedString, Styled as _, Subscription, WeakEntity, Window, div,
|
||||
list, px,
|
||||
};
|
||||
use helpers::{RepoFilter, render_card};
|
||||
use metadata::ProfileDirectory;
|
||||
@@ -17,7 +16,7 @@ use ui::input::{Input, InputState, InputStateEvent};
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::scrollbar::Scrollbar;
|
||||
use ui::segmented::{Segmented, SegmentedOption};
|
||||
use ui::theme::{ActiveTheme as _, TextRole, Typeset as _};
|
||||
use ui::theme::ActiveTheme as _;
|
||||
|
||||
use crate::shared::panels;
|
||||
use crate::workspace::Workspace;
|
||||
@@ -28,7 +27,7 @@ const CARD_HEIGHT: f32 = 40. + 64. + 48. + 2. + 6.;
|
||||
pub struct ExploreView {
|
||||
store: Entity<RepoListStore>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
scroll_handle: UniformListScrollHandle,
|
||||
scroll_handle: ListState,
|
||||
filter: RepoFilter,
|
||||
/// Indices matching [`Self::filter`] into the store's `announcements`.
|
||||
visible: Vec<usize>,
|
||||
@@ -83,7 +82,7 @@ impl ExploreView {
|
||||
Self {
|
||||
store,
|
||||
workspace,
|
||||
scroll_handle: UniformListScrollHandle::new(),
|
||||
scroll_handle: ListState::new(0, ListAlignment::Top, px(320.)),
|
||||
filter: RepoFilter::default(),
|
||||
visible: Vec::new(),
|
||||
search,
|
||||
@@ -111,129 +110,158 @@ impl ExploreView {
|
||||
directory.track(owners, cx);
|
||||
});
|
||||
|
||||
self.scroll_handle.reset(self.item_count());
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn render_header(&self, count: usize, cx: &mut Context<Self>) -> AnyElement {
|
||||
let muted = cx.theme().colors.muted_foreground;
|
||||
let weak = cx.entity().downgrade();
|
||||
/// Header row, plus one row per card row, or the empty state when nothing matches.
|
||||
fn item_count(&self) -> usize {
|
||||
if self.visible.is_empty() {
|
||||
2
|
||||
} else {
|
||||
self.visible.len().div_ceil(COLUMNS) + 1
|
||||
}
|
||||
}
|
||||
|
||||
h_flex()
|
||||
.px_4()
|
||||
.py_2()
|
||||
fn render_header(
|
||||
search: Entity<InputState>,
|
||||
filter: RepoFilter,
|
||||
weak: WeakEntity<Self>,
|
||||
cx: &App,
|
||||
) -> AnyElement {
|
||||
let muted = cx.theme().colors.muted_foreground;
|
||||
|
||||
div()
|
||||
.relative()
|
||||
.h_96()
|
||||
.w_full()
|
||||
.gap_3()
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_1()
|
||||
.child(div().typeset(TextRole::Caption2, cx).child("Repositories"))
|
||||
div()
|
||||
.absolute()
|
||||
.inset_0()
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.px_4()
|
||||
.child(
|
||||
div()
|
||||
.typeset(TextRole::Caption, cx)
|
||||
.text_color(muted)
|
||||
.child(SharedString::from(format!("Total: {count}"))),
|
||||
div().w_full().max_w(px(480.)).child(
|
||||
Input::new("explore-search", search)
|
||||
.placeholder("Search...")
|
||||
.fully_rounded(true)
|
||||
.prefix(Icon::named(IconRole::Search).small().color(muted)),
|
||||
),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div().w(px(180.)).child(
|
||||
Input::new("explore-search", self.search.clone())
|
||||
.placeholder("Search...")
|
||||
.prefix(Icon::named(IconRole::Search).small().color(muted)),
|
||||
),
|
||||
)
|
||||
.child(div().flex_1())
|
||||
.child(
|
||||
Segmented::new("explore-filter", self.filter)
|
||||
.options(vec![
|
||||
SegmentedOption::new(RepoFilter::All, "All")
|
||||
.icon(Icon::named(IconRole::Grid).small().color(muted)),
|
||||
SegmentedOption::new(RepoFilter::Popular, "Popular")
|
||||
.icon(Icon::named(IconRole::Trending).small().color(muted)),
|
||||
SegmentedOption::new(RepoFilter::Recent, "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(cx);
|
||||
}) {
|
||||
log::warn!("failed to change explore filter: {error}");
|
||||
}
|
||||
}),
|
||||
div()
|
||||
.absolute()
|
||||
.left_0()
|
||||
.bottom_0()
|
||||
.pl_4()
|
||||
.pb_4()
|
||||
.child(
|
||||
Segmented::new("explore-filter", filter)
|
||||
.options(vec![
|
||||
SegmentedOption::new(RepoFilter::All, "All")
|
||||
.icon(Icon::named(IconRole::Grid).small().color(muted)),
|
||||
SegmentedOption::new(RepoFilter::Recent, "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(cx);
|
||||
}) {
|
||||
log::warn!("failed to change explore filter: {error}");
|
||||
}
|
||||
}),
|
||||
),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for ExploreView {}
|
||||
impl Panel for ExploreView {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
SharedString::from("Explore")
|
||||
}
|
||||
|
||||
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||
Some(
|
||||
Icon::named(IconRole::Grid)
|
||||
.small()
|
||||
.color(cx.theme().colors.muted_foreground)
|
||||
.into_any_element(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
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 count = self.visible.len();
|
||||
let visible = self.visible.clone();
|
||||
let directory = self.directory.clone();
|
||||
let workspace = self.workspace.clone();
|
||||
let has_repos = count > 0;
|
||||
let rows = visible.len().div_ceil(COLUMNS);
|
||||
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();
|
||||
|
||||
v_flex()
|
||||
div()
|
||||
.relative()
|
||||
.size_full()
|
||||
.child(self.render_header(count, cx))
|
||||
.when(!has_repos, |this| {
|
||||
this.child(
|
||||
v_flex()
|
||||
.size_full()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child(EmptyState::new("No repositories match your search")),
|
||||
)
|
||||
})
|
||||
.when(has_repos, |this| {
|
||||
this.child(
|
||||
uniform_list("explore-repos", rows, move |range, _, cx| {
|
||||
range
|
||||
.map(|row| {
|
||||
let mut cards = Vec::with_capacity(COLUMNS);
|
||||
.child(
|
||||
list(self.scroll_handle.clone(), move |item, _, cx| {
|
||||
if item == 0 {
|
||||
return Self::render_header(search.clone(), filter, weak.clone(), cx);
|
||||
}
|
||||
|
||||
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(
|
||||
ix,
|
||||
announcement,
|
||||
activity,
|
||||
&announcements,
|
||||
&directory,
|
||||
&workspace,
|
||||
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();
|
||||
}
|
||||
|
||||
h_flex()
|
||||
.id(row)
|
||||
.w_full()
|
||||
.h(px(CARD_HEIGHT))
|
||||
.gap_3()
|
||||
.px_4()
|
||||
.pt_4()
|
||||
.children(cards)
|
||||
.into_any_element()
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.track_scroll(&self.scroll_handle)
|
||||
.size_full(),
|
||||
)
|
||||
})
|
||||
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(
|
||||
ix,
|
||||
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()
|
||||
})
|
||||
.size_full(),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.absolute()
|
||||
@@ -241,10 +269,7 @@ impl Render for ExploreView {
|
||||
.left_0()
|
||||
.right_0()
|
||||
.bottom_0()
|
||||
.child(Scrollbar::vertical(
|
||||
"explore-scroll",
|
||||
self.scroll_handle.clone(),
|
||||
)),
|
||||
.child(Scrollbar::vertical("explore-scroll", scroll_handle)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user