add recents tab

This commit is contained in:
2026-09-20 07:54:25 +07:00
parent 52f92c226f
commit 564382756d
5 changed files with 152 additions and 568 deletions
+18
View File
@@ -46,8 +46,11 @@ setting_accessors! {
pub nip4e: bool,
pub trusted_relays: Vec<String>,
pub file_server: Url,
pub recent_communities: Vec<String>,
}
const RECENT_COMMUNITIES_CAP: usize = 10;
/// Signer kind
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub enum SignerKind {
@@ -130,6 +133,10 @@ pub struct Settings {
/// Server for blossom media attachments
pub file_server: Url,
/// Recently opened community ids, newest first
#[serde(default)]
pub recent_communities: Vec<String>,
}
impl Default for Settings {
@@ -142,6 +149,7 @@ impl Default for Settings {
nip4e: false,
trusted_relays: vec![],
file_server: Url::parse(DEFAULT_FILE_SERVER).unwrap(),
recent_communities: vec![],
}
}
}
@@ -324,4 +332,14 @@ impl AppSettings {
}
});
}
/// Move a community to the front of the recently opened list
pub fn record_recent_community(&mut self, id: String, cx: &mut Context<Self>) {
self.inner.update(cx, |this, cx| {
this.recent_communities.retain(|existing| existing != &id);
this.recent_communities.insert(0, id);
this.recent_communities.truncate(RECENT_COMMUNITIES_CAP);
cx.notify();
});
}
}