add basic repo browser
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
mod repo_list;
|
||||
|
||||
pub use repo_list::RepoListView;
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user