feat(notify): activity panel remembers the chosen filter
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -43,6 +43,18 @@ pub enum Filter {
43
43
impl Filter {
44
44
pub const ALL: [Filter; 3] = [Filter::All, Filter::Mentions, Filter::Unread];
45
45
46
pub fn key(self) -> &'static str {
47
match self {
48
Filter::All => "all",
49
Filter::Mentions => "mentions",
50
Filter::Unread => "unread",
51
}
52
}
53
54
pub fn from_key(key: &str) -> Option<Filter> {
55
Filter::ALL.into_iter().find(|filter| filter.key() == key)
56
}
57
46
58
pub fn label(self) -> &'static str {
47
59
match self {
48
60
Filter::All => "All",
@@ -470,6 +482,14 @@ mod tests {
470
482
use super::*;
471
483
use crate::notify::{ChatKind, Preview};
472
484
485
#[test]
486
fn filters_round_trip_through_their_key() {
487
for filter in Filter::ALL {
488
assert_eq!(Filter::from_key(filter.key()), Some(filter));
489
}
490
assert_eq!(Filter::from_key("other"), None);
491
}
492
473
493
fn at(hour: u32, minute: u32) -> DateTime<Utc> {
474
494
Utc.with_ymd_and_hms(2026, 10, 8, hour, minute, 0).unwrap()
475
495
}
@@ -43,6 +43,18 @@ pub enum Filter {43
impl Filter {43
impl Filter {44
pub const ALL: [Filter; 3] = [Filter::All, Filter::Mentions, Filter::Unread];44
pub const ALL: [Filter; 3] = [Filter::All, Filter::Mentions, Filter::Unread];45
45
46
pub fn key(self) -> &'static str {47
match self {48
Filter::All => "all",49
Filter::Mentions => "mentions",50
Filter::Unread => "unread",51
}52
}53
54
pub fn from_key(key: &str) -> Option<Filter> {55
Filter::ALL.into_iter().find(|filter| filter.key() == key)56
}57
46
pub fn label(self) -> &'static str {58
pub fn label(self) -> &'static str {47
match self {59
match self {48
Filter::All => "All",60
Filter::All => "All",@@ -470,6 +482,14 @@ mod tests {470
use super::*;482
use super::*;471
use crate::notify::{ChatKind, Preview};483
use crate::notify::{ChatKind, Preview};472
484
485
#[test]486
fn filters_round_trip_through_their_key() {487
for filter in Filter::ALL {488
assert_eq!(Filter::from_key(filter.key()), Some(filter));489
}490
assert_eq!(Filter::from_key("other"), None);491
}492
473
fn at(hour: u32, minute: u32) -> DateTime<Utc> {493
fn at(hour: u32, minute: u32) -> DateTime<Utc> {474
Utc.with_ymd_and_hms(2026, 10, 8, hour, minute, 0).unwrap()494
Utc.with_ymd_and_hms(2026, 10, 8, hour, minute, 0).unwrap()475
}495
}@@ -20,6 +20,7 @@ const PANEL_MARGIN: f32 = 8.;
20
20
const AVATAR_SIZE: f32 = 32.;
21
21
const KIND_MARKER_SIZE: f32 = 16.;
22
22
const BUTTON_SIZE: f32 = 28.;
23
const FILTER_KEY: &str = "activity_filter";
23
24
24
25
pub enum ActivityPanelEvent {
25
26
Close,
@@ -54,10 +55,18 @@ impl ActivityPanel {
54
55
cx.observe(&app, |_, _, cx| cx.notify()),
55
56
cx.observe(&activity, |_, _, cx| cx.notify()),
56
57
];
58
let filter = app
59
.read(cx)
60
.store
61
.meta(FILTER_KEY)
62
.ok()
63
.flatten()
64
.and_then(|key| Filter::from_key(&key))
65
.unwrap_or_default();
57
66
ActivityPanel {
58
67
app,
59
68
activity,
60
filter: Filter::default(),
69
filter,
61
70
focus_handle,
62
71
scroll: ScrollHandle::new(),
63
72
_observations: observations,
@@ -110,6 +119,7 @@ impl ActivityPanel {
110
119
.child(filter.label())
111
120
.on_click(cx.listener(move |this, _, _, cx| {
112
121
this.filter = filter;
122
let _ = this.app.read(cx).store.set_meta(FILTER_KEY, filter.key());
113
123
cx.notify();
114
124
}))
115
125
});
@@ -20,6 +20,7 @@ const PANEL_MARGIN: f32 = 8.;20
const AVATAR_SIZE: f32 = 32.;20
const AVATAR_SIZE: f32 = 32.;21
const KIND_MARKER_SIZE: f32 = 16.;21
const KIND_MARKER_SIZE: f32 = 16.;22
const BUTTON_SIZE: f32 = 28.;22
const BUTTON_SIZE: f32 = 28.;23
const FILTER_KEY: &str = "activity_filter";23
24
24
pub enum ActivityPanelEvent {25
pub enum ActivityPanelEvent {25
Close,26
Close,@@ -54,10 +55,18 @@ impl ActivityPanel {54
cx.observe(&app, |_, _, cx| cx.notify()),55
cx.observe(&app, |_, _, cx| cx.notify()),55
cx.observe(&activity, |_, _, cx| cx.notify()),56
cx.observe(&activity, |_, _, cx| cx.notify()),56
];57
];58
let filter = app59
.read(cx)60
.store61
.meta(FILTER_KEY)62
.ok()63
.flatten()64
.and_then(|key| Filter::from_key(&key))65
.unwrap_or_default();57
ActivityPanel {66
ActivityPanel {58
app,67
app,59
activity,68
activity,60
filter: Filter::default(),69
filter,61
focus_handle,70
focus_handle,62
scroll: ScrollHandle::new(),71
scroll: ScrollHandle::new(),63
_observations: observations,72
_observations: observations,@@ -110,6 +119,7 @@ impl ActivityPanel {110
.child(filter.label())119
.child(filter.label())111
.on_click(cx.listener(move |this, _, _, cx| {120
.on_click(cx.listener(move |this, _, _, cx| {112
this.filter = filter;121
this.filter = filter;122
let _ = this.app.read(cx).store.set_meta(FILTER_KEY, filter.key());113
cx.notify();123
cx.notify();114
}))124
}))115
});125
});