update repo list

This commit is contained in:
2026-08-05 09:24:46 +07:00
parent f497279886
commit fdf74327bb
4 changed files with 102 additions and 56 deletions
+72 -50
View File
@@ -1,11 +1,13 @@
use gpui::prelude::*;
use gpui::{Context, Entity, Render, SharedString, Subscription, Window, div, px};
use gpui_component::scroll::ScrollableElement;
use gpui::{
AnyElement, App, Context, Entity, Render, SharedString, Subscription, Window, div, px,
uniform_list,
};
use gpui_component::{ActiveTheme, StyledExt};
use signed_core::Announcement;
use signed_state::{ProfileStore, RepoListStore};
/// Browse all announced repositories.
/// Browse all announced repositories (works anonymously).
pub struct RepoListView {
store: Entity<RepoListStore>,
_subscription: Subscription,
@@ -21,44 +23,58 @@ impl RepoListView {
_subscription: subscription,
}
}
}
fn render_card(&self, announcement: &Announcement, cx: &mut Context<Self>) -> impl IntoElement {
let name = announcement
.name
.clone()
.unwrap_or_else(|| announcement.id.clone());
fn render_card(announcement: &Announcement, cx: &mut App) -> AnyElement {
let name = announcement
.name
.clone()
.unwrap_or_else(|| announcement.id.clone());
let owner = ProfileStore::global(cx)
.update(cx, |store, cx| store.get(announcement.owner, cx))
.name();
let owner = ProfileStore::global(cx)
.update(cx, |store, cx| store.get(announcement.owner, cx))
.name();
div()
.v_flex()
.gap_1()
.px_4()
.py_3()
.border_b(px(1.))
.border_color(cx.theme().border)
.child(
div()
.h_flex()
.gap_2()
.items_center()
.child(div().text_sm().font_semibold().child(name))
.child(
div()
.text_xs()
.text_color(cx.theme().muted_foreground)
.child(owner),
),
)
.children(announcement.description.as_ref().map(|description| {
div()
.text_xs()
.text_color(cx.theme().muted_foreground)
.child(description.clone())
}))
}
let description = announcement.description.clone().unwrap_or_default();
div()
.v_flex()
.h(px(60.))
.justify_center()
.gap_1()
.px_4()
.border_b(px(1.))
.border_color(cx.theme().border)
.child(
div()
.h_flex()
.gap_2()
.items_center()
.child(
div()
.text_sm()
.font_semibold()
.whitespace_nowrap()
.text_ellipsis()
.child(name),
)
.child(
div()
.text_xs()
.text_color(cx.theme().muted_foreground)
.whitespace_nowrap()
.child(owner),
),
)
.child(
div()
.text_xs()
.text_color(cx.theme().muted_foreground)
.whitespace_nowrap()
.text_ellipsis()
.child(description),
)
.into_any_element()
}
impl Render for RepoListView {
@@ -66,22 +82,28 @@ impl Render for RepoListView {
let announcements = self.store.read(cx).announcements.clone();
let count = announcements.len();
let mut list = div().v_flex().flex_1().overflow_y_scrollbar();
if announcements.is_empty() {
list = list.child(
div().size_full().items_center().justify_center().child(
let body = if announcements.is_empty() {
div()
.size_full()
.v_flex()
.items_center()
.justify_center()
.child(
div()
.text_sm()
.text_color(cx.theme().muted_foreground)
.child("No repositories found. Waiting for relays..."),
),
);
)
.into_any_element()
} else {
for announcement in &announcements {
list = list.child(self.render_card(announcement, cx));
}
}
uniform_list("repo-list", count, move |range, _window, cx| {
range
.map(|index| render_card(&announcements[index], cx))
.collect()
})
.size_full()
.into_any_element()
};
div()
.v_flex()
@@ -100,6 +122,6 @@ impl Render for RepoListView {
.child(SharedString::from(format!(" ({count})"))),
),
)
.child(list)
.child(body)
}
}
+9 -2
View File
@@ -14,9 +14,12 @@ pub struct Workspace {
impl Workspace {
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
let backend = Backend::global(cx);
let repo_list = cx.new(|cx| RepoListView::new(window, cx));
let subscription = cx.subscribe(&Backend::global(cx), |this, _backend, event, cx| {
let connected = backend.read(cx).is_connected();
let subscription = cx.subscribe(&backend, |this, _backend, event, cx| {
match event {
BackendEvent::Connected => this.status = "Connected".into(),
BackendEvent::Error(error) => this.status = error.clone().into(),
@@ -27,7 +30,11 @@ impl Workspace {
Self {
active_screen: repo_list.into(),
status: SharedString::from("Connecting..."),
status: if connected {
"Connected".into()
} else {
"Connecting...".into()
},
_subscription: subscription,
}
}