nav: refactor title rendering for flexibility
Updated navigation to use a custom title renderer for more flexible rendering of navigation titles. This change decouples the rendering logic from predefined formats, enabling dynamic title compositions based on application context and data. This includes: - Refactoring `NavResponse` to introduce `NotedeckNavResponse` for handling unified navigation response data. - Adding `NavTitle` in `ui/column/header.rs` to handle rendering of navigation titles and profile images dynamically. - Updating route and timeline logic to support new rendering pipeline. - Replacing hardcoded title rendering with data-driven approaches. Benefits: - Simplifies navigation handling by consolidating title and action management. - Improves scalability for new navigation features without modifying core logic. - Enhances visual customization capabilities. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
53
src/route.rs
53
src/route.rs
@@ -1,5 +1,5 @@
|
||||
use enostr::{NoteId, Pubkey};
|
||||
use nostrdb::Ndb;
|
||||
use nostrdb::{Ndb, Transaction};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{self};
|
||||
|
||||
@@ -24,18 +24,6 @@ pub enum Route {
|
||||
Support,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TitledRoute {
|
||||
pub route: Route,
|
||||
pub title: String,
|
||||
}
|
||||
|
||||
impl fmt::Display for TitledRoute {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.title)
|
||||
}
|
||||
}
|
||||
|
||||
impl Route {
|
||||
pub fn timeline(timeline_id: TimelineId) -> Self {
|
||||
Route::Timeline(TimelineRoute::Timeline(timeline_id))
|
||||
@@ -77,8 +65,8 @@ impl Route {
|
||||
Route::Accounts(AccountsRoute::AddAccount)
|
||||
}
|
||||
|
||||
pub fn get_titled_route(&self, columns: &Columns, ndb: &Ndb) -> TitledRoute {
|
||||
let title = match self {
|
||||
pub fn title(&self, columns: &Columns, ndb: &Ndb) -> String {
|
||||
match self {
|
||||
Route::Timeline(tlr) => match tlr {
|
||||
TimelineRoute::Timeline(id) => {
|
||||
let timeline = columns
|
||||
@@ -87,16 +75,32 @@ impl Route {
|
||||
timeline.kind.to_title(ndb)
|
||||
}
|
||||
TimelineRoute::Thread(id) => {
|
||||
format!("{}'s Thread", get_note_users_displayname_string(ndb, id))
|
||||
let txn = Transaction::new(ndb).expect("txn");
|
||||
format!(
|
||||
"{}'s Thread",
|
||||
get_note_users_displayname_string(&txn, ndb, id)
|
||||
)
|
||||
}
|
||||
TimelineRoute::Reply(id) => {
|
||||
format!("{}'s Reply", get_note_users_displayname_string(ndb, id))
|
||||
let txn = Transaction::new(ndb).expect("txn");
|
||||
format!(
|
||||
"{}'s Reply",
|
||||
get_note_users_displayname_string(&txn, ndb, id)
|
||||
)
|
||||
}
|
||||
TimelineRoute::Quote(id) => {
|
||||
format!("{}'s Quote", get_note_users_displayname_string(ndb, id))
|
||||
let txn = Transaction::new(ndb).expect("txn");
|
||||
format!(
|
||||
"{}'s Quote",
|
||||
get_note_users_displayname_string(&txn, ndb, id)
|
||||
)
|
||||
}
|
||||
TimelineRoute::Profile(pubkey) => {
|
||||
format!("{}'s Profile", get_profile_displayname_string(ndb, pubkey))
|
||||
let txn = Transaction::new(ndb).expect("txn");
|
||||
format!(
|
||||
"{}'s Profile",
|
||||
get_profile_displayname_string(&txn, ndb, pubkey)
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -116,11 +120,6 @@ impl Route {
|
||||
AddColumnRoute::Hashtag => "Add Hashtag Column".to_owned(),
|
||||
},
|
||||
Route::Support => "Damus Support".to_owned(),
|
||||
};
|
||||
|
||||
TitledRoute {
|
||||
title,
|
||||
route: *self,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,7 +168,7 @@ impl<R: Clone> Router<R> {
|
||||
return None;
|
||||
}
|
||||
self.returning = true;
|
||||
self.routes.get(self.routes.len() - 2).cloned()
|
||||
self.prev().cloned()
|
||||
}
|
||||
|
||||
/// Pop a route, should only be called on a NavRespose::Returned reseponse
|
||||
@@ -200,6 +199,10 @@ impl<R: Clone> Router<R> {
|
||||
self.routes.last().expect("routes can't be empty")
|
||||
}
|
||||
|
||||
pub fn prev(&self) -> Option<&R> {
|
||||
self.routes.get(self.routes.len() - 2)
|
||||
}
|
||||
|
||||
pub fn routes(&self) -> &Vec<R> {
|
||||
&self.routes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user