use super::{child_id, text};
use crate::{
Avatar, AvatarGroup, AvatarGroupMember, AvatarSize, Badge, BadgeTone, Button, ButtonSize,
ButtonVariant, DropdownItem, DropdownMenu, Progress,
};
use arc_motion::{
ArcPresence, ArcPresenceConfig, LayoutSnapshot, arc_spring, arc_spring_with_options,
layout::layout_scope_key, motion_now, sample_shared_layout, spring::SpringOptions,
};
use arc_tokens::{ActiveArcTheme as _, BlockTokens, Radii, Spacing, Typography};
use gpui_kit::base::{ElementExt as _, StyledExt as _};
use gpui_kit::{
App, BorderStyle, Bounds, Edges, ElementId, InteractiveElement as _, IntoElement,
ParentElement, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled,
TestSupportExt as _, Window, assets::IconName, bounds, canvas, div, point, prelude::*, px,
quad, svg,
};
use std::{cell::RefCell, rc::Rc, time::Duration};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum PageSection {
#[default]
Overview,
Issues,
Updates,
Files,
}
impl PageSection {
fn order(self) -> usize {
match self {
Self::Overview => 0,
Self::Issues => 1,
Self::Updates => 2,
Self::Files => 3,
}
}
fn label(self) -> &'static str {
match self {
Self::Overview => "Overview",
Self::Issues => "Issues",
Self::Updates => "Updates",
Self::Files => "Files",
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum MilestoneState {
Done,
#[default]
Active,
Planned,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PagePerson {
pub name: SharedString,
pub photo: Option<SharedString>,
}
impl PagePerson {
pub fn new(name: impl Into<SharedString>) -> Self {
Self {
name: name.into(),
photo: None,
}
}
pub fn photo(mut self, photo: impl Into<SharedString>) -> Self {
self.photo = Some(photo.into());
self
}
}
impl From<&str> for PagePerson {
fn from(name: &str) -> Self {
Self::new(name)
}
}
impl From<String> for PagePerson {
fn from(name: String) -> Self {
Self::new(name)
}
}
impl From<SharedString> for PagePerson {
fn from(name: SharedString) -> Self {
Self::new(name)
}
}
#[derive(Clone, Debug)]
pub struct PageIssue {
pub id: SharedString,
pub title: SharedString,
pub done: bool,
pub label: Option<SharedString>,
pub owner: Option<PagePerson>,
}
impl PageIssue {
pub fn new(id: impl Into<SharedString>, title: impl Into<SharedString>) -> Self {
Self {
id: id.into(),
title: title.into(),
done: false,
label: None,
owner: None,
}
}
pub fn label(mut self, label: impl Into<SharedString>) -> Self {
self.label = Some(label.into());
self
}
pub fn owner(mut self, owner: impl Into<SharedString>) -> Self {
self.owner = Some(PagePerson::new(owner));
self
}
pub fn owner_with(mut self, owner: PagePerson) -> Self {
self.owner = Some(owner);
self
}
}
#[derive(Clone, Debug)]
pub struct PageMilestone {
pub id: SharedString,
pub name: SharedString,
pub note: SharedString,
pub state: MilestoneState,
}
impl PageMilestone {
pub fn new(
name: impl Into<SharedString>,
note: impl Into<SharedString>,
state: MilestoneState,
) -> Self {
let name = name.into();
Self {
id: name.clone(),
name,
note: note.into(),
state,
}
}
}
#[derive(Clone, Debug)]
pub struct PageActivity {
pub id: SharedString,
pub person: PagePerson,
pub text: SharedString,
pub time: SharedString,
}
impl PageActivity {
pub fn new(
id: impl Into<SharedString>,
person: impl Into<SharedString>,
text: impl Into<SharedString>,
time: impl Into<SharedString>,
) -> Self {
Self {
id: id.into(),
person: PagePerson::new(person),
text: text.into(),
time: time.into(),
}
}
}
#[derive(Clone, Debug)]
pub struct PageUpdate {
pub id: SharedString,
pub author: PagePerson,
pub date: SharedString,
pub body: SharedString,
pub status: Option<SharedString>,
pub tone: BadgeTone,
}
impl PageUpdate {
pub fn new(
id: impl Into<SharedString>,
author: impl Into<PagePerson>,
date: impl Into<SharedString>,
body: impl Into<SharedString>,
) -> Self {
Self {
id: id.into(),
author: author.into(),
date: date.into(),
body: body.into(),
status: None,
tone: BadgeTone::Success,
}
}
pub fn status(mut self, status: impl Into<SharedString>, tone: BadgeTone) -> Self {
self.status = Some(status.into());
self.tone = tone;
self
}
}
#[derive(Clone, Debug)]
pub struct PageFile {
pub id: SharedString,
pub name: SharedString,
pub kind: SharedString,
pub size: SharedString,
pub owner: Option<PagePerson>,
pub date: Option<SharedString>,
}
impl PageFile {
pub fn new(
id: impl Into<SharedString>,
name: impl Into<SharedString>,
kind: impl Into<SharedString>,
size: impl Into<SharedString>,
) -> Self {
Self {
id: id.into(),
name: name.into(),
kind: kind.into(),
size: size.into(),
owner: None,
date: None,
}
}
pub fn owner(mut self, owner: impl Into<SharedString>) -> Self {
self.owner = Some(PagePerson::new(owner));
self
}
pub fn owner_with(mut self, owner: PagePerson) -> Self {
self.owner = Some(owner);
self
}
pub fn date(mut self, date: impl Into<SharedString>) -> Self {
self.date = Some(date.into());
self
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum SharePhase {
Idle,
Sending,
Sent,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum NoticeTone {
Success,
Neutral,
}
impl NoticeTone {
fn glyph(self) -> &'static str {
match self {
Self::Success => "✓",
Self::Neutral => "•",
}
}
}
type Notice = Rc<dyn Fn(SharedString, &mut Window, &mut App)>;
#[derive(IntoElement)]
pub struct PageHeader {
id: ElementId,
title: SharedString,
description: SharedString,
issues: Vec<PageIssue>,
milestones: Vec<PageMilestone>,
activity: Vec<PageActivity>,
members: Vec<PagePerson>,
updates: Vec<PageUpdate>,
files: Vec<PageFile>,
project_url: Option<SharedString>,
section: PageSection,
archived: bool,
on_notice: Option<Notice>,
}
#[derive(Clone)]
struct State {
section: PageSection,
archived: bool,
issues: Vec<PageIssue>,
scroll: gpui_kit::ScrollHandle,
condensed: bool,
notice: SharedString,
notice_tone: NoticeTone,
notice_at: f64,
following: bool,
sharing: SharePhase,
serial: u64,
updates: Vec<PageUpdate>,
collapsed: bool,
width: f32,
direction: f32,
closing: Vec<SharedString>,
done_count: u32,
sample: Vec<PageIssue>,
tab_bounds: Rc<RefCell<[Option<Bounds<Pixels>>; 4]>>,
}
impl State {
fn notify(&mut self, message: impl Into<SharedString>, tone: NoticeTone, now: f64) {
self.notice = message.into();
self.notice_tone = tone;
self.notice_at = now;
}
}
impl PageHeader {
pub fn new(id: impl Into<ElementId>) -> Self {
Self {
id: id.into(),
title: "Checkout redesign".into(),
description:
"Rebuilding mobile checkout around saved payment methods and a single review step."
.into(),
issues: vec![],
milestones: sample_milestones(),
activity: sample_activity(),
members: sample_members(),
updates: vec![],
files: vec![],
project_url: None,
section: PageSection::Overview,
archived: false,
on_notice: None,
}
}
pub fn title(mut self, v: impl Into<SharedString>) -> Self {
self.title = v.into();
self
}
pub fn description(mut self, v: impl Into<SharedString>) -> Self {
self.description = v.into();
self
}
pub fn issues(mut self, v: impl IntoIterator<Item = PageIssue>) -> Self {
self.issues = v.into_iter().collect();
self
}
pub fn milestones(mut self, v: impl IntoIterator<Item = PageMilestone>) -> Self {
self.milestones = v.into_iter().collect();
self
}
pub fn activity(mut self, v: impl IntoIterator<Item = PageActivity>) -> Self {
self.activity = v.into_iter().collect();
self
}
pub fn members(mut self, v: impl IntoIterator<Item = PagePerson>) -> Self {
self.members = v.into_iter().collect();
self
}
pub fn updates(mut self, v: impl IntoIterator<Item = PageUpdate>) -> Self {
self.updates = v.into_iter().collect();
self
}
pub fn files(mut self, v: impl IntoIterator<Item = PageFile>) -> Self {
self.files = v.into_iter().collect();
self
}
pub fn project_url(mut self, v: impl Into<SharedString>) -> Self {
self.project_url = Some(v.into());
self
}
pub fn section(mut self, v: PageSection) -> Self {
self.section = v;
self
}
pub fn archived(mut self, v: bool) -> Self {
self.archived = v;
self
}
pub fn on_notice(mut self, f: impl Fn(SharedString, &mut Window, &mut App) + 'static) -> Self {
self.on_notice = Some(Rc::new(f));
self
}
}
fn sample_members() -> Vec<PagePerson> {
[
"Emma Collins",
"Marcus Johnson",
"Ava Mitchell",
"Sofia Ramirez",
"Jasmine Brooks",
]
.into_iter()
.map(PagePerson::new)
.collect()
}
fn sample_milestones() -> Vec<PageMilestone> {
vec![
PageMilestone::new(
"Saved payment methods",
"Shipped Sep 18",
MilestoneState::Done,
),
PageMilestone::new(
"Single review step",
"In progress, due Oct 1",
MilestoneState::Active,
),
PageMilestone::new(
"Staged rollout",
"Planned for Oct 14",
MilestoneState::Planned,
),
]
}
fn sample_activity() -> Vec<PageActivity> {
vec![
PageActivity::new("a1", "Ava Mitchell", "moved CHK-131 to review", "1h ago"),
PageActivity::new(
"a2",
"Marcus Johnson",
"merged the saved cards endpoint",
"3h ago",
),
PageActivity::new(
"a3",
"Emma Collins",
"shared Checkout flows v3",
"Yesterday",
),
PageActivity::new(
"a4",
"Sofia Ramirez",
"closed CHK-119, a double charge on retry",
"Yesterday",
),
PageActivity::new(
"a5",
"Jasmine Brooks",
"set the rollout date to October 14",
"Sep 17",
),
]
}
fn avatar(id: ElementId, person: &PagePerson) -> Avatar {
let a = Avatar::new(id, person.name.clone());
match &person.photo {
Some(photo) => a.src(photo.clone()),
None => a,
}
}
impl RenderOnce for PageHeader {
fn render(self, w: &mut Window, cx: &mut App) -> impl IntoElement {
let colors = cx.arc_theme().colors;
let motion = cx.arc_theme().motion;
let now = motion_now(cx);
let sample = self.issues.clone();
let opening: Vec<PageIssue> = sample.iter().filter(|i| !i.done).cloned().collect();
let initial_done = sample.iter().filter(|i| i.done).count() as u32;
let state = w.use_keyed_state(child_id(&self.id, "state"), cx, |_, _| State {
section: self.section,
archived: self.archived,
issues: opening,
scroll: gpui_kit::ScrollHandle::new(),
condensed: false,
notice: "".into(),
notice_tone: NoticeTone::Success,
notice_at: f64::NEG_INFINITY,
following: false,
sharing: SharePhase::Idle,
serial: 0,
updates: self.updates.clone(),
collapsed: false,
width: 0.0,
direction: 1.0,
closing: vec![],
done_count: initial_done,
sample,
tab_bounds: Rc::new(RefCell::new([None; 4])),
});
let snap = state.read(cx).clone();
let open = snap.issues.len() as u32;
let done = snap.done_count;
let mut root = div()
.id(self.id.clone())
.role(Role::Region)
.aria_label(self.title.clone())
.relative()
.w_full()
.flex()
.flex_col()
.h(BlockTokens::PAGE_HEIGHT)
.overflow_hidden()
.rounded(Radii::PANEL)
.border_1()
.border_color(colors.border)
.bg(colors.surface)
.text_color(colors.foreground);
let measure = state.clone();
root = root.on_prepaint(move |bounds, window, cx| {
let width = f32::from(bounds.size.width);
if width <= 0.0 {
return;
}
let mut changed = false;
measure.update(cx, |s, _| {
if (s.width - width).abs() > 0.5 {
s.width = width;
let collapsed = if s.collapsed {
width < BlockTokens::ACTIONS_RETURN
} else {
width < BlockTokens::ACTIONS_COLLAPSE
};
if collapsed != s.collapsed {
s.collapsed = collapsed;
changed = true;
}
}
});
if changed {
window.refresh();
}
});
let condensed = arc_spring(
(self.id.clone(), "header"),
if snap.condensed { 1.0 } else { 0.0 },
motion.spring.smooth,
w,
cx,
)
.clamp(0.0, 1.0);
let notice = self.on_notice.clone();
let archived = snap.archived;
let collapsed = snap.collapsed;
let following = snap.following;
let chevron = || {
svg()
.path(IconName::ChevronRight.path())
.size(px(14.0))
.text_color(colors.border_strong)
};
let lead = if condensed < 0.5 {
div()
.flex()
.min_w(px(0.0))
.items_center()
.gap(Spacing::S1)
.opacity((1.0 - condensed * 2.0).clamp(0.0, 1.0))
.child(text("Northline", cx).text_color(colors.text_muted))
.child(chevron())
.child(text("Projects", cx).text_color(colors.text_muted))
.child(chevron())
.child(
text(self.title.clone(), cx)
.text_color(colors.text_secondary)
.truncate(),
)
} else {
div()
.flex()
.min_w(px(0.0))
.items_center()
.gap(Spacing::S2)
.opacity(((condensed - 0.5) * 2.0).clamp(0.0, 1.0))
.child(
Button::new(child_id(&self.id, "compact"))
.label(self.title.clone())
.accessibility_label(format!("{}, back to top", self.title))
.size(ButtonSize::Sm)
.variant(ButtonVariant::Ghost)
.on_click({
let st = state.clone();
move |_, w, cx| {
st.update(cx, |s, _| {
s.scroll.set_offset(gpui_kit::point(px(0.0), px(0.0)));
s.condensed = false;
});
w.refresh();
}
}),
)
.child(
Badge::new(
child_id(&self.id, "compact-status"),
if archived { "Archived" } else { "On track" },
)
.tone(if archived {
BadgeTone::Neutral
} else {
BadgeTone::Success
}),
)
};
let mut actions = div().flex().flex_wrap().gap(Spacing::S2).items_center();
if !collapsed {
let follow_state = state.clone();
actions = actions.child(
Button::new(child_id(&self.id, "follow"))
.label(if following { "Following" } else { "Follow" })
.accessibility_label(if following {
"Unfollow project"
} else {
"Follow project"
})
.selected(following)
.size(ButtonSize::Sm)
.variant(ButtonVariant::Secondary)
.on_click(move |_, w, cx| toggle_follow(&follow_state, w, cx)),
);
let share_state = state.clone();
let sharing = snap.sharing;
actions = actions.child(
Button::new(child_id(&self.id, "share"))
.label(match sharing {
SharePhase::Sending => "Sharing…",
SharePhase::Sent => "Shared",
SharePhase::Idle => "Share update",
})
.loading(sharing == SharePhase::Sending)
.disabled(archived || sharing != SharePhase::Idle)
.size(ButtonSize::Sm)
.variant(ButtonVariant::Secondary)
.on_click(move |_, w, cx| share_update(&share_state, w, cx)),
);
}
let add_state = state.clone();
actions = actions.child(
Button::new(child_id(&self.id, "add-issue"))
.label("New issue")
.disabled(archived)
.size(ButtonSize::Sm)
.on_click(move |_, w, cx| create_issue(&add_state, w, cx)),
);
let copy_state = state.clone();
let project_url = self.project_url.clone();
let mut menu = DropdownMenu::new(child_id(&self.id, "more"), "More actions");
if collapsed {
let follow_state = state.clone();
menu = menu.item(
DropdownItem::new(if following { "Unfollow" } else { "Follow" })
.on_select(move |_, w, cx| toggle_follow(&follow_state, w, cx)),
);
let share_state = state.clone();
menu = menu.item(
DropdownItem::new(match snap.sharing {
SharePhase::Sending => "Sharing…",
SharePhase::Sent => "Shared",
SharePhase::Idle => "Share update",
})
.disabled(archived || snap.sharing != SharePhase::Idle)
.on_select(move |_, w, cx| share_update(&share_state, w, cx)),
);
}
menu = menu.item(
DropdownItem::new("Copy project link")
.separator_before(collapsed)
.disabled(project_url.is_none())
.on_select(move |_, w, cx| copy_link(©_state, project_url.as_ref(), w, cx)),
);
menu = menu.item(
DropdownItem::new(if archived {
"Restore project"
} else {
"Archive project"
})
.separator_before(true)
.on_select({
let archive_state = state.clone();
let notice = notice.clone();
move |_, w, cx| {
toggle_archive(&archive_state, notice.as_ref(), w, cx);
}
}),
);
actions = actions.child(menu);
let intro = arc_spring(
(self.id.clone(), "intro"),
if snap.condensed { 0.0 } else { 1.0 },
motion.spring.smooth,
w,
cx,
)
.clamp(0.0, 1.0);
let member_row = AvatarGroup::new(child_id(&self.id, "members"))
.members(self.members.iter().map(|p| {
let member = AvatarGroupMember::new(p.name.clone());
match &p.photo {
Some(photo) => member.src(photo.clone()),
None => member,
}
}))
.max(4)
.size(AvatarSize::Sm)
.label("Project members");
root = root.child(
div()
.id(child_id(&self.id, "header"))
.pt(Spacing::S4)
.px(Spacing::S4)
.flex_none()
.child(
div()
.flex()
.gap(Spacing::S4)
.justify_between()
.items_center()
.child(div().flex_1().min_w(px(0.0)).child(lead))
.child(actions),
)
.child(
div()
.overflow_hidden()
.flex()
.flex_col()
.gap(Spacing::S2)
.max_h(px(220.0 * intro))
.pt(Spacing::S4)
.when(intro > 0.02, |d| {
d.child(
div()
.flex()
.flex_wrap()
.items_center()
.gap(Spacing::S2)
.child(
div()
.text_size(Typography::TEXT_2XL)
.font_medium()
.child(self.title.clone()),
)
.child(
Badge::new(
child_id(&self.id, "status"),
if archived { "Archived" } else { "On track" },
)
.tone(
if archived {
BadgeTone::Neutral
} else {
BadgeTone::Success
},
),
),
)
.child(
text(self.description.clone(), cx)
.text_color(colors.text_secondary),
)
.child(
div()
.flex()
.flex_wrap()
.items_center()
.gap(Spacing::S4)
.child(member_row)
.child(
text("Led by Emma Collins", cx)
.text_color(colors.text_muted),
)
.child(text("Target Oct 14", cx).text_color(colors.text_muted)),
)
}),
),
);
let sections = [
PageSection::Overview,
PageSection::Issues,
PageSection::Updates,
PageSection::Files,
];
let tab_bounds = state.read(cx).tab_bounds.clone();
let selected_order = snap.section.order();
let indicator_scope = layout_scope_key(&self.id);
let indicator_morph = motion.spring.morph;
let indicator = canvas(
move |_, _, _| {},
move |list_rect, _, window, cx| {
let Some(tab_rect) = tab_bounds.borrow()[selected_order] else {
window.request_animation_frame();
return;
};
let target = LayoutSnapshot::new(
bounds(
point(
tab_rect.origin.x - list_rect.origin.x + px(10.0),
tab_rect.origin.y - list_rect.origin.y + tab_rect.size.height - px(2.0),
),
gpui_kit::size(tab_rect.size.width - px(20.0), px(2.0)),
),
gpui_kit::Corners {
top_left: px(2.0),
top_right: px(2.0),
bottom_right: px(0.0),
bottom_left: px(0.0),
},
);
let flip = sample_shared_layout(
indicator_scope.clone(),
"indicator",
target,
Some(indicator_morph),
window,
cx,
);
let paint = bounds(
point(
list_rect.origin.x + flip.bounds.origin.x,
list_rect.origin.y + flip.bounds.origin.y,
),
flip.bounds.size,
);
window.paint_quad(quad(
paint,
flip.corner_radii,
colors.accent,
Edges::default(),
colors.accent,
BorderStyle::Solid,
));
},
);
let mut tabs = div()
.relative()
.flex()
.gap(Spacing::S1)
.mt(Spacing::S3)
.mx(-Spacing::S4)
.px(Spacing::S4 - Spacing::S2)
.border_b_1()
.border_color(colors.border)
.child(indicator);
for section in sections {
let count = match section {
PageSection::Issues => Some(snap.issues.len()),
PageSection::Updates => Some(snap.updates.len()),
PageSection::Files => Some(self.files.len()),
PageSection::Overview => None,
};
let selected = snap.section == section;
let st = state.clone();
let measured = state.read(cx).tab_bounds.clone();
let measure_index = section.order();
let measure = canvas(
move |bounds, _, _| {
measured.borrow_mut()[measure_index] = Some(bounds);
},
|_, _, _, _| {},
)
.absolute()
.inset_0();
let mut tab = div()
.id(child_id(&self.id, format!("tab-{}", section.label())))
.test_support()
.role(Role::Tab)
.aria_selected(selected)
.aria_label(match count {
Some(count) => format!("{} · {count}", section.label()),
None => section.label().to_owned(),
})
.cursor_pointer()
.relative()
.h(px(44.0))
.px(Spacing::S2)
.flex()
.flex_none()
.items_center()
.gap(Spacing::S1)
.text_size(Typography::TEXT_SM)
.font_medium()
.whitespace_nowrap()
.text_color(if selected {
colors.foreground
} else {
colors.text_muted
})
.hover(move |s| s.text_color(colors.foreground))
.on_click(move |_, w, cx| {
st.update(cx, |s, _| {
if section != s.section {
s.direction = if section.order() > s.section.order() {
1.0
} else {
-1.0
};
}
s.section = section;
s.scroll.set_offset(gpui_kit::point(px(0.0), px(0.0)));
});
w.refresh();
})
.child(measure)
.child(section.label());
if let Some(count) = count {
tab = tab.child(
text(count.to_string(), cx)
.text_color(if selected {
colors.text_secondary
} else {
colors.text_muted
})
.text_size(Typography::TEXT_SM),
);
}
tabs = tabs.child(tab);
}
root = root.child(tabs);
let scroll_state = state.clone();
let mut body = div()
.id(child_id(&self.id, "body"))
.test_support()
.p(Spacing::S6)
.flex_1()
.min_h(px(0.0))
.track_scroll(&snap.scroll)
.on_scroll(move |_, w, cx| {
scroll_state.update(cx, |s, _| {
let top = -f32::from(s.scroll.offset().y);
s.condensed = if s.condensed {
top > BlockTokens::EXPAND_AT
} else {
top > BlockTokens::CONDENSE_AT
};
});
w.refresh();
})
.overflow_y_scroll();
let slide = arc_spring_with_options(
(
child_id(&self.id, format!("panel-{}", snap.section.label())),
"slide",
),
0.0,
SpringOptions::new(motion.spring.smooth).with_initial_value(snap.direction * 12.0),
w,
cx,
);
body = body.ml(px(slide.value));
match snap.section {
PageSection::Overview => {
body = body.child(
Progress::new(child_id(&self.id, "progress"))
.value(done as f32)
.max((open + done).max(1) as f32)
.label(format!("{done} of {} issues done", open + done))
.show_value(true),
);
body = body.child(
div()
.id(child_id(&self.id, "milestones"))
.role(Role::List)
.aria_label("Milestones")
.flex()
.flex_col()
.gap(Spacing::S1)
.child(div().font_medium().child("Milestones"))
.children(self.milestones.iter().map(|m| {
let (glyph, color) = match m.state {
MilestoneState::Done => ("✓", colors.success),
MilestoneState::Active => ("◌", colors.accent),
MilestoneState::Planned => ("○", colors.text_muted),
};
div()
.id(child_id(&self.id, format!("milestone-{}", m.id)))
.test_support()
.role(Role::ListItem)
.flex()
.items_center()
.gap(Spacing::S2)
.child(div().text_color(color).child(glyph))
.child(div().flex_1().child(m.name.clone()))
.child(text(m.note.clone(), cx))
})),
);
body = body.child(
div()
.id(child_id(&self.id, "activity"))
.role(Role::List)
.aria_label("Recent activity")
.flex()
.flex_col()
.gap(Spacing::S2)
.child(div().font_medium().child("Recent activity"))
.children(self.activity.iter().map(|a| {
div()
.id(child_id(&self.id, format!("activity-{}", a.id)))
.test_support()
.role(Role::ListItem)
.flex()
.items_center()
.gap(Spacing::S2)
.child(avatar(
child_id(&self.id, format!("who-{}", a.id)),
&a.person,
))
.child(
div()
.flex_1()
.child(format!("{} {}", a.person.name, a.text)),
)
.child(text(a.time.clone(), cx))
})),
);
}
PageSection::Issues => {
body = body.role(Role::List).aria_label("Open issues");
let has_issues = !snap.issues.is_empty();
let all_closing =
!has_issues || snap.issues.iter().all(|i| snap.closing.contains(&i.id));
for issue in snap.issues {
let issue_state = state.clone();
let key = issue.id.clone();
let issue_id = issue.id.clone();
let issue_title = issue.title.clone();
let closing = snap.closing.contains(&issue.id);
let id = child_id(&self.id, format!("issue-{}", issue.id));
let presence = ArcPresence::new((id.clone(), "row"), !closing)
.animate_initial(false)
.config(ArcPresenceConfig {
enter_duration: motion.duration.standard,
exit_duration: Duration::from_millis(380),
enter_ease: motion.ease.enter,
exit_ease: motion.ease.standard,
fade_on_reduced_motion: true,
})
.sample(w, cx);
if !presence.should_render() {
continue;
}
let cb = self.on_notice.clone();
let mut row = div()
.id(id)
.role(Role::ListItem)
.opacity(presence.progress)
.max_h(BlockTokens::ROW_HEIGHT * presence.progress)
.overflow_hidden()
.flex()
.items_center()
.gap(Spacing::S2)
.p(Spacing::S2)
.child(
Button::new(child_id(&self.id, format!("check-{}", issue.id)))
.label(if closing { "✓" } else { "○" })
.accessibility_label(format!(
"Mark {} {}",
issue.title,
if closing { "open" } else { "done" }
))
.disabled(closing)
.size(ButtonSize::Sm)
.variant(ButtonVariant::Ghost)
.on_click(move |_, w, cx| {
let now = motion_now(cx);
let first = issue_state.update(cx, |s, _| {
if s.closing.contains(&key) {
return false;
}
s.closing.push(key.clone());
s.notify(
format!("{key} marked done"),
NoticeTone::Success,
now,
);
true
});
if !first {
return;
}
let weak = issue_state.downgrade();
let removal = issue_id.clone();
w.spawn(cx, async move |cx| {
cx.background_executor()
.timer(Duration::from_millis(380))
.await;
let _ = cx.update(|w, cx| {
let _ = weak.update(cx, |s, _| {
s.issues.retain(|i| i.id != removal);
s.closing.retain(|c| c != &removal);
s.done_count += 1;
});
w.refresh();
});
})
.detach();
if let Some(cb) = &cb {
cb(format!("{} marked done", issue_id).into(), w, cx)
}
w.refresh();
}),
)
.child(
div()
.text_color(colors.text_muted)
.child(issue_title.clone()),
)
.child(div().flex_1().child(issue_title));
if let Some(label) = issue.label.clone() {
row = row.child(Badge::new(
child_id(&self.id, format!("label-{}", issue.id)),
label,
));
}
if let Some(owner) = issue.owner.as_ref() {
row = row.child(avatar(
child_id(&self.id, format!("owner-{}", issue.id)),
owner,
));
}
body = body.child(row);
}
if all_closing {
let st = state.clone();
body = body.child(
div()
.id(child_id(&self.id, "empty-issues"))
.test_support()
.flex()
.flex_col()
.items_center()
.gap(Spacing::S2)
.p(Spacing::S6)
.child(div().font_medium().child("No open issues"))
.child(text("Everything in this project is done.", cx))
.child(
Button::new(child_id(&self.id, "restore-issues"))
.label("Restore sample issues")
.size(ButtonSize::Sm)
.variant(ButtonVariant::Secondary)
.on_click(move |_, w, cx| {
let now = motion_now(cx);
st.update(cx, |s, _| {
s.issues = s
.sample
.iter()
.filter(|i| !i.done)
.cloned()
.collect();
s.done_count =
s.sample.iter().filter(|i| i.done).count() as u32;
s.closing.clear();
s.notify(
"Sample issues restored",
NoticeTone::Neutral,
now,
);
});
w.refresh();
}),
),
);
}
}
PageSection::Updates => {
body = body.role(Role::List);
if snap.updates.is_empty() {
body = body.child(text("No project updates yet", cx));
}
for update in snap.updates {
let mut head = div()
.flex()
.items_center()
.gap(Spacing::S2)
.child(div().font_medium().child(update.author.name.clone()))
.child(text(update.date.clone(), cx));
if let Some(status) = update.status.clone() {
head = head.child(
Badge::new(child_id(&self.id, format!("status-{}", update.id)), status)
.tone(update.tone),
);
}
body = body.child(
div()
.id(child_id(&self.id, format!("update-{}", update.id)))
.test_support()
.role(Role::ListItem)
.p(Spacing::S3)
.flex()
.gap(Spacing::S3)
.child(avatar(
child_id(&self.id, format!("author-{}", update.id)),
&update.author,
))
.child(
div()
.flex_1()
.flex()
.flex_col()
.gap(Spacing::S1)
.child(head)
.child(text(update.body, cx)),
),
);
}
}
PageSection::Files => {
body = body.role(Role::List);
if self.files.is_empty() {
body = body.child(text("No project files", cx));
}
for file in self.files {
body = body.child(
div()
.id(child_id(&self.id, format!("file-{}", file.id)))
.test_support()
.role(Role::ListItem)
.p(Spacing::S3)
.flex()
.items_center()
.gap(Spacing::S3)
.child(div().text_color(colors.text_secondary).child("▤"))
.child(
div()
.flex_1()
.flex()
.flex_col()
.child(div().font_medium().child(file.name))
.child(text(format!("{} · {}", file.kind, file.size), cx)),
)
.when_some(file.owner.as_ref(), |d, owner| {
d.child(avatar(
child_id(&self.id, format!("owner-{}", file.id)),
owner,
))
})
.when_some(file.date, |d, date| d.child(text(date, cx))),
);
}
}
}
let notice_live = (now - snap.notice_at) < 3.2 && !snap.notice.is_empty();
if notice_live {
w.request_animation_frame();
}
let tone = snap.notice_tone;
let toast_color = match tone {
NoticeTone::Success => colors.success,
NoticeTone::Neutral => colors.text_secondary,
};
root.child(body.child(div().min_h(BlockTokens::PAGE_BODY_MIN)))
.child(
div()
.id(child_id(&self.id, "notice"))
.role(Role::Status)
.child(snap.notice.clone())
.when(notice_live, |d| {
d.absolute()
.bottom(Spacing::S4)
.left(Spacing::S4)
.flex()
.items_center()
.gap(Spacing::S2)
.px(Spacing::S4)
.py(Spacing::S2)
.rounded(Radii::PANEL)
.border_1()
.border_color(colors.border)
.bg(colors.surface_raised)
.text_color(colors.foreground)
.child(div().text_color(toast_color).child(tone.glyph()))
.child(snap.notice.clone())
}),
)
.child(
div()
.id(child_id(&self.id, "members-sr"))
.role(Role::Status)
.aria_label(format!("{} project members", self.members.len()))
.opacity(0.0)
.child(self.members.len().to_string()),
)
}
}
fn toggle_follow(state: &gpui_kit::Entity<State>, w: &mut Window, cx: &mut App) {
let now = motion_now(cx);
state.update(cx, |s, _| {
s.following = !s.following;
let message = if s.following {
"Following project"
} else {
"Stopped following project"
};
s.notify(message, NoticeTone::Success, now);
});
w.refresh();
}
fn share_update(state: &gpui_kit::Entity<State>, w: &mut Window, cx: &mut App) {
if state.read(cx).sharing != SharePhase::Idle {
return;
}
let now = motion_now(cx);
state.update(cx, |s, _| {
s.sharing = SharePhase::Sending;
s.notify("Sharing update…", NoticeTone::Neutral, now);
});
let weak = state.downgrade();
w.spawn(cx, async move |cx| {
cx.background_executor()
.timer(Duration::from_millis(700))
.await;
let _ = cx.update(|w, cx| {
let now = motion_now(cx);
let _ = weak.update(cx, |s, _| {
s.serial += 1;
let key: SharedString = format!("local-update-{}", s.serial).into();
s.updates.insert(
0,
PageUpdate::new(
key,
"You",
"Just now",
"Local project update shared with the preview team.",
)
.status("On track", BadgeTone::Success),
);
if s.section != PageSection::Updates {
s.direction = if PageSection::Updates.order() > s.section.order() {
1.0
} else {
-1.0
};
}
s.section = PageSection::Updates;
s.sharing = SharePhase::Sent;
s.notify(
"Local update shared; no request sent",
NoticeTone::Success,
now,
);
});
w.refresh();
});
cx.background_executor()
.timer(Duration::from_millis(1800))
.await;
let _ = cx.update(|w, cx| {
let _ = weak.update(cx, |s, _| {
if s.sharing == SharePhase::Sent {
s.sharing = SharePhase::Idle;
}
});
w.refresh();
});
})
.detach();
w.refresh();
}
fn create_issue(state: &gpui_kit::Entity<State>, w: &mut Window, cx: &mut App) {
let now = motion_now(cx);
state.update(cx, |s, _| {
s.serial += 1;
let key: SharedString = format!("local-issue-{}", s.serial).into();
s.issues
.push(PageIssue::new(key, "Review the next project task"));
if s.section != PageSection::Issues {
s.direction = if PageSection::Issues.order() > s.section.order() {
1.0
} else {
-1.0
};
}
s.section = PageSection::Issues;
s.notify("Local issue created", NoticeTone::Success, now);
});
w.refresh();
}
fn copy_link(
state: &gpui_kit::Entity<State>,
url: Option<&SharedString>,
w: &mut Window,
cx: &mut App,
) {
let Some(url) = url else { return };
cx.write_to_clipboard(gpui_kit::ClipboardItem::new_string(url.to_string()));
let now = motion_now(cx);
state.update(cx, |s, _| s.notify("Link copied", NoticeTone::Success, now));
w.refresh();
}
fn toggle_archive(
state: &gpui_kit::Entity<State>,
notice: Option<&Notice>,
w: &mut Window,
cx: &mut App,
) {
let now = motion_now(cx);
let mut archived = false;
state.update(cx, |s, _| {
s.archived = !s.archived;
archived = s.archived;
let message = if archived {
"Project archived"
} else {
"Project restored"
};
s.notify(message, NoticeTone::Neutral, now);
});
w.refresh();
if let Some(cb) = notice {
cb(
if archived {
"Project archived"
} else {
"Project restored"
}
.into(),
w,
cx,
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sections_are_distinct() {
assert_ne!(PageSection::Issues, PageSection::Files);
assert!(PageSection::Files.order() > PageSection::Overview.order());
}
}