column: switch to simplified strings for column headers
This uses less allocations, and once we switch to profile pictures in the header the old way won't be needed Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
65
src/route.rs
65
src/route.rs
@@ -1,16 +1,15 @@
|
|||||||
use enostr::{NoteId, Pubkey};
|
use enostr::{NoteId, Pubkey};
|
||||||
use nostrdb::{Ndb, Transaction};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt::{self};
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
|
fmt::{self},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
accounts::AccountsRoute,
|
accounts::AccountsRoute,
|
||||||
column::Columns,
|
column::Columns,
|
||||||
timeline::{TimelineId, TimelineRoute},
|
timeline::{TimelineId, TimelineRoute},
|
||||||
ui::{
|
ui::add_column::AddColumnRoute,
|
||||||
add_column::AddColumnRoute,
|
|
||||||
profile::preview::{get_note_users_displayname_string, get_profile_displayname_string},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// App routing. These describe different places you can go inside Notedeck.
|
/// App routing. These describe different places you can go inside Notedeck.
|
||||||
@@ -65,61 +64,37 @@ impl Route {
|
|||||||
Route::Accounts(AccountsRoute::AddAccount)
|
Route::Accounts(AccountsRoute::AddAccount)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn title(&self, columns: &Columns, ndb: &Ndb) -> String {
|
pub fn title(&self, columns: &Columns) -> Cow<'static, str> {
|
||||||
match self {
|
match self {
|
||||||
Route::Timeline(tlr) => match tlr {
|
Route::Timeline(tlr) => match tlr {
|
||||||
TimelineRoute::Timeline(id) => {
|
TimelineRoute::Timeline(id) => {
|
||||||
let timeline = columns
|
let timeline = columns
|
||||||
.find_timeline(*id)
|
.find_timeline(*id)
|
||||||
.expect("expected to find timeline");
|
.expect("expected to find timeline");
|
||||||
timeline.kind.to_title(ndb)
|
timeline.kind.to_title()
|
||||||
}
|
|
||||||
TimelineRoute::Thread(id) => {
|
|
||||||
let txn = Transaction::new(ndb).expect("txn");
|
|
||||||
format!(
|
|
||||||
"{}'s Thread",
|
|
||||||
get_note_users_displayname_string(&txn, ndb, id)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
TimelineRoute::Reply(id) => {
|
|
||||||
let txn = Transaction::new(ndb).expect("txn");
|
|
||||||
format!(
|
|
||||||
"{}'s Reply",
|
|
||||||
get_note_users_displayname_string(&txn, ndb, id)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
TimelineRoute::Quote(id) => {
|
|
||||||
let txn = Transaction::new(ndb).expect("txn");
|
|
||||||
format!(
|
|
||||||
"{}'s Quote",
|
|
||||||
get_note_users_displayname_string(&txn, ndb, id)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
TimelineRoute::Profile(pubkey) => {
|
|
||||||
let txn = Transaction::new(ndb).expect("txn");
|
|
||||||
format!(
|
|
||||||
"{}'s Profile",
|
|
||||||
get_profile_displayname_string(&txn, ndb, pubkey)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
TimelineRoute::Thread(_id) => Cow::Borrowed("Thread"),
|
||||||
|
TimelineRoute::Reply(_id) => Cow::Borrowed("Reply"),
|
||||||
|
TimelineRoute::Quote(_id) => Cow::Borrowed("Quote"),
|
||||||
|
TimelineRoute::Profile(_pubkey) => Cow::Borrowed("Profile"),
|
||||||
},
|
},
|
||||||
|
|
||||||
Route::Relays => "Relays".to_owned(),
|
Route::Relays => Cow::Borrowed("Relays"),
|
||||||
|
|
||||||
Route::Accounts(amr) => match amr {
|
Route::Accounts(amr) => match amr {
|
||||||
AccountsRoute::Accounts => "Accounts".to_owned(),
|
AccountsRoute::Accounts => Cow::Borrowed("Accounts"),
|
||||||
AccountsRoute::AddAccount => "Add Account".to_owned(),
|
AccountsRoute::AddAccount => Cow::Borrowed("Add Account"),
|
||||||
},
|
},
|
||||||
Route::ComposeNote => "Compose Note".to_owned(),
|
Route::ComposeNote => Cow::Borrowed("Compose Note"),
|
||||||
Route::AddColumn(c) => match c {
|
Route::AddColumn(c) => match c {
|
||||||
AddColumnRoute::Base => "Add Column".to_owned(),
|
AddColumnRoute::Base => Cow::Borrowed("Add Column"),
|
||||||
AddColumnRoute::UndecidedNotification => "Add Notifications Column".to_owned(),
|
AddColumnRoute::UndecidedNotification => Cow::Borrowed("Add Notifications Column"),
|
||||||
AddColumnRoute::ExternalNotification => {
|
AddColumnRoute::ExternalNotification => {
|
||||||
"Add External Notifications Column".to_owned()
|
Cow::Borrowed("Add External Notifications Column")
|
||||||
}
|
}
|
||||||
AddColumnRoute::Hashtag => "Add Hashtag Column".to_owned(),
|
AddColumnRoute::Hashtag => Cow::Borrowed("Add Hashtag Column"),
|
||||||
},
|
},
|
||||||
Route::Support => "Damus Support".to_owned(),
|
Route::Support => Cow::Borrowed("Damus Support"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ use crate::error::{Error, FilterError};
|
|||||||
use crate::filter;
|
use crate::filter;
|
||||||
use crate::filter::FilterState;
|
use crate::filter::FilterState;
|
||||||
use crate::timeline::Timeline;
|
use crate::timeline::Timeline;
|
||||||
use crate::ui::profile::preview::get_profile_displayname_string;
|
|
||||||
use enostr::{Filter, Pubkey};
|
use enostr::{Filter, Pubkey};
|
||||||
use nostrdb::{Ndb, Transaction};
|
use nostrdb::{Ndb, Transaction};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt::Display;
|
use std::{borrow::Cow, fmt::Display};
|
||||||
use tracing::{error, warn};
|
use tracing::{error, warn};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
@@ -194,43 +193,16 @@ impl TimelineKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_title(&self, ndb: &Ndb) -> String {
|
pub fn to_title(&self) -> Cow<'static, str> {
|
||||||
match self {
|
match self {
|
||||||
TimelineKind::List(list_kind) => match list_kind {
|
TimelineKind::List(list_kind) => match list_kind {
|
||||||
ListKind::Contact(pubkey_source) => match pubkey_source {
|
ListKind::Contact(_pubkey_source) => Cow::Borrowed("Contacts"),
|
||||||
PubkeySource::Explicit(pubkey) => {
|
|
||||||
let txn = Transaction::new(ndb).expect("txn");
|
|
||||||
format!(
|
|
||||||
"{}'s Contacts",
|
|
||||||
get_profile_displayname_string(&txn, ndb, pubkey)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
PubkeySource::DeckAuthor => "Contacts".to_owned(),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
TimelineKind::Notifications(pubkey_source) => match pubkey_source {
|
TimelineKind::Notifications(_pubkey_source) => Cow::Borrowed("Notifications"),
|
||||||
PubkeySource::DeckAuthor => "Notifications".to_owned(),
|
TimelineKind::Profile(_pubkey_source) => Cow::Borrowed("Profile"),
|
||||||
PubkeySource::Explicit(pk) => {
|
TimelineKind::Universe => Cow::Borrowed("Universe"),
|
||||||
let txn = Transaction::new(ndb).expect("txn");
|
TimelineKind::Generic => Cow::Borrowed("Custom"),
|
||||||
format!(
|
TimelineKind::Hashtag(hashtag) => Cow::Owned(format!("#{}", hashtag)),
|
||||||
"{}'s Notifications",
|
|
||||||
get_profile_displayname_string(&txn, ndb, pk)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
TimelineKind::Profile(pubkey_source) => match pubkey_source {
|
|
||||||
PubkeySource::DeckAuthor => "Profile".to_owned(),
|
|
||||||
PubkeySource::Explicit(pk) => {
|
|
||||||
let txn = Transaction::new(ndb).expect("txn");
|
|
||||||
format!(
|
|
||||||
"{}'s Profile",
|
|
||||||
get_profile_displayname_string(&txn, ndb, pk)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
TimelineKind::Universe => "Universe".to_owned(),
|
|
||||||
TimelineKind::Generic => "Custom Filter".to_owned(),
|
|
||||||
TimelineKind::Hashtag(hashtag) => format!("#{}", hashtag),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user