add repo detail view

This commit is contained in:
2026-08-10 08:33:19 +07:00
parent e36d96bf50
commit 831a89dd11
12 changed files with 1060 additions and 7 deletions
+36 -4
View File
@@ -1,12 +1,13 @@
use std::rc::Rc;
use std::sync::Arc;
use gpui::prelude::*;
use gpui::{
AnyElement, App, Context, Entity, EventEmitter, FocusHandle, Focusable, Pixels, Render,
SharedString, Size, Subscription, Window, div, px, size,
AnyElement, App, Context, ElementId, Entity, EventEmitter, FocusHandle, Focusable, Pixels,
Render, SharedString, Size, Subscription, WeakEntity, Window, div, px, size,
};
use gpui_component::avatar::Avatar;
use gpui_component::dock::{Panel, PanelEvent};
use gpui_component::dock::{DockArea, DockPlacement, Panel, PanelEvent};
use gpui_component::scroll::Scrollbar;
use gpui_component::{
ActiveTheme, Sizable, StyledExt, VirtualListScrollHandle, h_flex, v_flex, v_virtual_list,
@@ -15,11 +16,14 @@ use signed_core::Announcement;
use signed_state::{ProfileStore, RepoListStore, Timestamp};
use utils::relative_time;
use super::RepoDetailView;
const CARD_HEIGHT: f32 = 160.;
/// Browse all announced repositories (works anonymously).
pub struct RepoListView {
store: Entity<RepoListStore>,
dock_area: WeakEntity<DockArea>,
focus_handle: FocusHandle,
scroll_handle: VirtualListScrollHandle,
item_sizes: Rc<Vec<Size<Pixels>>>,
@@ -27,7 +31,11 @@ pub struct RepoListView {
}
impl RepoListView {
pub fn new(_window: &mut Window, cx: &mut Context<Self>) -> Self {
pub fn new(
dock_area: WeakEntity<DockArea>,
_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| {
@@ -40,6 +48,7 @@ impl RepoListView {
Self {
store,
dock_area,
focus_handle: cx.focus_handle(),
scroll_handle: VirtualListScrollHandle::new(),
item_sizes: Rc::new(vec![]),
@@ -70,11 +79,34 @@ impl RepoListView {
.map(|label| SharedString::from(format!("Updated {label}")))
.unwrap_or_default();
// Open the repository in a new center tab when the card is clicked.
let dock_area = self.dock_area.clone();
let announcement = announcement.clone();
v_flex()
.id(ElementId::from(format!(
"repo-card-{}",
announcement.addr()
)))
.px_4()
.w_full()
.border_b(px(1.))
.border_color(cx.theme().border)
.cursor_pointer()
.on_click(move |_event, window, cx| {
let detail = cx.new(|cx| RepoDetailView::new(announcement.clone(), window, cx));
if let Some(dock_area) = dock_area.upgrade() {
dock_area.update(cx, |dock_area, cx| {
dock_area.add_panel(
Arc::new(detail),
DockPlacement::Center,
None,
window,
cx,
);
});
}
})
.child(
h_flex()
.h_12()