2 cols repo list

This commit is contained in:
2026-08-30 08:46:34 +07:00
parent ae2938112f
commit 8829bc5bc1
2 changed files with 67 additions and 41 deletions
+38 -12
View File
@@ -18,7 +18,8 @@ use utils::relative_time;
use super::RepoDetailView;
use crate::image_cache::{MAX_IMAGES, image_cache};
const CARD_HEIGHT: f32 = 160.;
const COLUMNS: usize = 2;
const CARD_HEIGHT: f32 = 32. + 64. + 48. + 2. + 6.;
/// Browse all announced repositories (works anonymously).
pub struct RepoListView {
@@ -39,10 +40,11 @@ impl RepoListView {
let store = cx.new(|cx| RepoListStore::new(None, cx));
let subscription = cx.observe(&store, |this, store, cx| {
let count = store.read(cx).announcements.len();
// Each virtual list row holds `COLUMNS` repo cards.
let rows = store.read(cx).announcements.len().div_ceil(COLUMNS);
if this.item_sizes.len() != count {
this.item_sizes = Rc::new(vec![size(px(0.), px(CARD_HEIGHT)); count]);
if this.item_sizes.len() != rows {
this.item_sizes = Rc::new(vec![size(px(0.), px(CARD_HEIGHT)); rows]);
}
});
@@ -106,14 +108,17 @@ impl RepoListView {
v_flex()
.id(ix)
.px_4()
.w_full()
.border_b(px(1.))
.flex_1()
.h_full()
.min_w_0()
.px_3()
.rounded(cx.theme().radius)
.border_1()
.border_color(cx.theme().border)
.hover(|this| this.bg(cx.theme().list_hover))
.child(
h_flex()
.h_12()
.h_8()
.text_sm()
.font_semibold()
.whitespace_nowrap()
@@ -123,9 +128,11 @@ impl RepoListView {
.child(
div()
.h_16()
.min_w_0()
.text_sm()
.text_color(cx.theme().muted_foreground)
.line_clamp(2)
.text_ellipsis()
.child(description),
)
.child(
@@ -235,10 +242,29 @@ impl Render for RepoListView {
v_virtual_list(view, "repos", sizes, move |this, range, _window, cx| {
let mut items = vec![];
for ix in range {
let announcement: &Announcement = &announcements[ix];
let activity = last_activity.get(&announcement.addr()).copied();
items.push(this.render_card(ix, announcement, activity, cx));
for row in range {
let mut row_cards = vec![];
for col in 0..COLUMNS {
let ix = row * COLUMNS + col;
let Some(announcement) = announcements.get(ix) else {
break;
};
let activity = last_activity.get(&announcement.addr()).copied();
row_cards.push(this.render_card(ix, announcement, activity, cx));
}
items.push(
h_flex()
.id(row)
.w_full()
.h_full()
.gap_3()
.px_3()
.pb_3()
.children(row_cards)
.into_any_element(),
);
}
items