update issue panel

This commit is contained in:
2026-08-17 11:22:52 +07:00
parent 9f484ea98d
commit 1159252dda
13 changed files with 308 additions and 124 deletions
@@ -0,0 +1,227 @@
//! Issues panel: a bottom panel listing every issue of the repository with
//! its title, event id, author, age and status. Minimal placeholder UI; the
//! presentation is expected to be redesigned later.
use std::rc::Rc;
use assets::CustomIconName;
use gpui::prelude::*;
use gpui::{
AnyElement, App, Context, Entity, EventEmitter, FocusHandle, Focusable, Pixels, Render,
SharedString, Size, Window, div, px, size,
};
use gpui_component::avatar::Avatar;
use gpui_component::dock::{Panel, PanelEvent};
use gpui_component::scroll::Scrollbar;
use gpui_component::tooltip::Tooltip;
use gpui_component::{
ActiveTheme, Icon, Sizable, VirtualListScrollHandle, h_flex, v_flex, v_virtual_list,
};
use nostr::prelude::Event;
use signed_core::{RepoStatus, activity_subject};
use signed_state::{ProfileStore, RepoStore};
use utils::relative_time;
use super::helpers::placeholder;
/// Height of one issue row in the virtual list: two stacked text lines
/// (14px title + 12px meta, ~1.4x line height each) plus a little padding.
const ISSUE_ROW_HEIGHT: f32 = 40.;
/// Panel listing all issues of a repository (no filters). The list stays
/// live by reading the store during `render`.
pub struct IssuesView {
focus_handle: FocusHandle,
/// Repo store holding the issues and their statuses.
store: Entity<RepoStore>,
/// Display name of the repository, for the panel title.
repo_name: SharedString,
/// Per-row heights of the virtual list.
item_sizes: Rc<Vec<Size<Pixels>>>,
/// Issue count [`Self::item_sizes`] was built for; rebuilt on change.
issue_len: usize,
/// Virtual list state of the issues list.
scroll_handle: VirtualListScrollHandle,
}
impl IssuesView {
pub fn new(store: Entity<RepoStore>, repo_name: SharedString, cx: &mut Context<Self>) -> Self {
Self {
focus_handle: cx.focus_handle(),
store,
repo_name,
item_sizes: Rc::new(Vec::new()),
issue_len: 0,
scroll_handle: VirtualListScrollHandle::new(),
}
}
/// One issue row: title, event id, author, age and status.
fn render_row(&self, ix: usize, issue: &Event, cx: &App) -> AnyElement {
let title = activity_subject(issue);
let id_hex = issue.id.to_hex();
let profile = ProfileStore::global(cx).read(cx).get(&issue.pubkey);
let author = profile.name();
let picture = profile.picture();
let age = relative_time(issue.created_at);
let status = self.store.read(cx).status_of(issue);
h_flex()
.id(ix)
.h(px(ISSUE_ROW_HEIGHT))
.w_full()
.gap_4()
.px_3()
.items_start()
.child(Self::render_status(status, cx))
.child(
v_flex()
.flex_1()
.child(
div()
.min_w_0()
.text_ellipsis()
.whitespace_nowrap()
.line_clamp(1)
.text_sm()
.child(title),
)
.child(
h_flex()
.gap_2()
.text_xs()
.child(
h_flex()
.gap_1()
.items_center()
.child(
Avatar::new()
.name(author.clone())
.when_some(picture, |this, url| this.src(url))
.xsmall(),
)
.child(div().child(author)),
)
.child(
div()
.text_color(cx.theme().muted_foreground)
.child(SharedString::from(&id_hex[..8])),
)
.child(div().child(age)),
),
)
.into_any_element()
}
/// Small status tag: open (green), closed (red), applied (blue), draft (yellow).
fn render_status(status: RepoStatus, cx: &App) -> AnyElement {
let (icon, label, tooltip, bg, fg) = match status {
RepoStatus::Open => (
CustomIconName::GitIssueOpen,
"open",
"Issue is open",
cx.theme().secondary,
cx.theme().secondary_foreground,
),
RepoStatus::Closed => (
CustomIconName::GitIssueClosed,
"closed",
"Issue is closed",
cx.theme().warning,
cx.theme().warning_foreground,
),
RepoStatus::Draft => (
CustomIconName::GitIssueOngoing,
"draft",
"Issue is draft",
cx.theme().accent,
cx.theme().accent_foreground,
),
RepoStatus::Applied => (
CustomIconName::GitIssueOpen,
"applied",
"Issue is completed",
cx.theme().primary,
cx.theme().primary_foreground,
),
};
v_flex()
.id(label)
.flex_shrink_0()
.size_6()
.items_center()
.justify_center()
.rounded(cx.theme().radius)
.bg(bg)
.child(Icon::new(icon).xsmall().text_color(fg))
.tooltip(move |window, cx| Tooltip::new(tooltip).build(window, cx))
.into_any_element()
}
}
impl Panel for IssuesView {
fn panel_name(&self) -> &'static str {
"issues"
}
fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
div()
.text_sm()
.child(SharedString::from(format!("{}/issues", self.repo_name)))
}
}
impl EventEmitter<PanelEvent> for IssuesView {}
impl Focusable for IssuesView {
fn focus_handle(&self, _cx: &App) -> FocusHandle {
self.focus_handle.clone()
}
}
impl Render for IssuesView {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let store = self.store.read(cx);
let count = store.issues.len();
if count == 0 {
return placeholder("No issues", cx).into_any_element();
}
// The virtual list's item count comes from `item_sizes`; rebuild it
// whenever the store's issue count changes.
if count != self.issue_len {
self.issue_len = count;
self.item_sizes = Rc::new(vec![size(px(0.), px(ISSUE_ROW_HEIGHT)); count]);
}
let sizes = self.item_sizes.clone();
let scroll_handle = self.scroll_handle.clone();
let view = cx.entity().clone();
v_flex()
.relative()
.size_full()
.child(
v_virtual_list(view, "issues", sizes, move |this, range, _window, cx| {
let issues = &this.store.read(cx).issues;
range
.map(|ix| this.render_row(ix, &issues[ix], cx))
.collect()
})
.track_scroll(&scroll_handle)
.size_full(),
)
.child(
div()
.absolute()
.top_0()
.left_0()
.right_0()
.bottom_0()
.child(Scrollbar::vertical(&scroll_handle)),
)
.into_any_element()
}
}