add basic repo browser

This commit is contained in:
2026-08-05 09:03:42 +07:00
parent 7249a323f8
commit f497279886
10 changed files with 411 additions and 27 deletions
+15
View File
@@ -0,0 +1,15 @@
mod views;
mod workspace;
pub use views::RepoListView;
pub use workspace::Workspace;
use gpui::{App, AppContext, Entity, Window};
use gpui_component::Root;
/// Build the root view tree. Requires `signed_state::init` and
/// `gpui_component::init` to have been called first.
pub fn root(window: &mut Window, cx: &mut App) -> Entity<Root> {
let view = cx.new(|cx| Workspace::new(window, cx));
cx.new(|cx| Root::new(view, window, cx))
}
+3
View File
@@ -0,0 +1,3 @@
mod repo_list;
pub use repo_list::RepoListView;
+105
View File
@@ -0,0 +1,105 @@
use gpui::prelude::*;
use gpui::{Context, Entity, Render, SharedString, Subscription, Window, div, px};
use gpui_component::scroll::ScrollableElement;
use gpui_component::{ActiveTheme, StyledExt};
use signed_core::Announcement;
use signed_state::{ProfileStore, RepoListStore};
/// Browse all announced repositories.
pub struct RepoListView {
store: Entity<RepoListStore>,
_subscription: Subscription,
}
impl RepoListView {
pub fn new(_window: &mut Window, cx: &mut Context<Self>) -> Self {
let store = cx.new(|cx| RepoListStore::new(None, cx));
let subscription = cx.observe(&store, |_this, _store, cx| cx.notify());
Self {
store,
_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());
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())
}))
}
}
impl Render for RepoListView {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
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(
div()
.text_sm()
.text_color(cx.theme().muted_foreground)
.child("No repositories found. Waiting for relays..."),
),
);
} else {
for announcement in &announcements {
list = list.child(self.render_card(announcement, cx));
}
}
div()
.v_flex()
.size_full()
.child(
div()
.h_flex()
.px_4()
.py_2()
.items_center()
.child(div().text_sm().font_semibold().child("Repositories"))
.child(
div()
.text_xs()
.text_color(cx.theme().muted_foreground)
.child(SharedString::from(format!(" ({count})"))),
),
)
.child(list)
}
}
+73
View File
@@ -0,0 +1,73 @@
use gpui::prelude::*;
use gpui::{AnyView, Context, Render, SharedString, Subscription, Window, div, px};
use gpui_component::{ActiveTheme, StyledExt};
use signed_state::{Backend, BackendEvent};
use crate::views::RepoListView;
/// Root view of the app: header, active screen, status bar.
pub struct Workspace {
active_screen: AnyView,
status: SharedString,
_subscription: Subscription,
}
impl Workspace {
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
let repo_list = cx.new(|cx| RepoListView::new(window, cx));
let subscription = cx.subscribe(&Backend::global(cx), |this, _backend, event, cx| {
match event {
BackendEvent::Connected => this.status = "Connected".into(),
BackendEvent::Error(error) => this.status = error.clone().into(),
_ => return,
}
cx.notify();
});
Self {
active_screen: repo_list.into(),
status: SharedString::from("Connecting..."),
_subscription: subscription,
}
}
}
impl Render for Workspace {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
div()
.v_flex()
.size_full()
.bg(cx.theme().background)
.text_color(cx.theme().foreground)
.child(
div()
.h_flex()
.px_4()
.py_2()
.border_b(px(1.))
.border_color(cx.theme().border)
.child(div().text_lg().font_semibold().child("Signed")),
)
.child(
div()
.flex_1()
.overflow_hidden()
.child(self.active_screen.clone()),
)
.child(
div()
.h_flex()
.px_4()
.py_1()
.border_t(px(1.))
.border_color(cx.theme().border)
.child(
div()
.text_xs()
.text_color(cx.theme().muted_foreground)
.child(self.status.clone()),
),
)
}
}