add workspace

This commit is contained in:
2026-08-05 11:07:12 +07:00
parent 8de6018e28
commit 6b13d8a8f7
5 changed files with 162 additions and 44 deletions
+2
View File
@@ -1,3 +1,5 @@
mod repo_list;
mod sidebar;
pub use repo_list::RepoListView;
pub use sidebar::SidebarPanel;
+23 -2
View File
@@ -1,8 +1,9 @@
use gpui::prelude::*;
use gpui::{
AnyElement, App, Context, Entity, Render, SharedString, Subscription, Window, div, px,
uniform_list,
AnyElement, App, Context, Entity, EventEmitter, FocusHandle, Focusable, Render, SharedString,
Subscription, Window, div, px, uniform_list,
};
use gpui_component::dock::{Panel, PanelEvent};
use gpui_component::{ActiveTheme, StyledExt};
use signed_core::Announcement;
use signed_state::{ProfileStore, RepoListStore};
@@ -10,6 +11,7 @@ use signed_state::{ProfileStore, RepoListStore};
/// Browse all announced repositories (works anonymously).
pub struct RepoListView {
store: Entity<RepoListStore>,
focus_handle: FocusHandle,
_subscription: Subscription,
}
@@ -20,11 +22,30 @@ impl RepoListView {
Self {
store,
focus_handle: cx.focus_handle(),
_subscription: subscription,
}
}
}
impl Panel for RepoListView {
fn panel_name(&self) -> &'static str {
"repo_list"
}
fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
"Explore"
}
}
impl EventEmitter<PanelEvent> for RepoListView {}
impl Focusable for RepoListView {
fn focus_handle(&self, _cx: &App) -> FocusHandle {
self.focus_handle.clone()
}
}
fn render_card(announcement: &Announcement, cx: &mut App) -> AnyElement {
let name = announcement
.name
+77
View File
@@ -0,0 +1,77 @@
use std::sync::Arc;
use gpui::prelude::*;
use gpui::{App, Context, EventEmitter, FocusHandle, Focusable, Render, WeakEntity, Window};
use gpui_component::button::Button;
use gpui_component::dock::{DockArea, DockPlacement, Panel, PanelEvent};
use gpui_component::v_flex;
use crate::views::RepoListView;
/// Left-dock panel with navigation entries. Entries open content panels in
/// the dock area.
pub struct SidebarPanel {
focus_handle: FocusHandle,
dock_area: WeakEntity<DockArea>,
explore: Option<WeakEntity<RepoListView>>,
}
impl SidebarPanel {
pub fn new(dock_area: WeakEntity<DockArea>, cx: &mut Context<Self>) -> Self {
Self {
focus_handle: cx.focus_handle(),
dock_area,
explore: None,
}
}
/// Open the Explore (repository list) panel in the center of the dock
/// area. No-op if it's already open.
pub fn open_explore(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if self.explore.as_ref().and_then(WeakEntity::upgrade).is_some() {
return;
}
let panel = cx.new(|cx| RepoListView::new(window, cx));
self.explore = Some(panel.downgrade());
self.dock_area
.update(cx, |dock_area, cx| {
dock_area.add_panel(Arc::new(panel), DockPlacement::Center, None, window, cx);
})
.ok();
}
}
impl Panel for SidebarPanel {
fn panel_name(&self) -> &'static str {
"sidebar"
}
fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
"Navigation"
}
fn closable(&self, _cx: &App) -> bool {
false
}
}
impl EventEmitter<PanelEvent> for SidebarPanel {}
impl Focusable for SidebarPanel {
fn focus_handle(&self, _cx: &App) -> FocusHandle {
self.focus_handle.clone()
}
}
impl Render for SidebarPanel {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
v_flex().gap_2().p_2().child(
Button::new("explore")
.label("Explore")
.w_full()
.on_click(cx.listener(|this, _, window, cx| this.open_explore(window, cx))),
)
}
}