ui: customizable tabs per column view
This reduces the number of choices the user needs to make. Some of these filters were redundant anyways. This also saves memory. Universe: Notes Notificaitons: Notes & Replies Everything else: Notes, Notes & Replies Changelog-Changed: Simplified tab selections on some columns Fixes: https://github.com/damus-io/notedeck/issues/517
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
use notedeck::FilterState;
|
use notedeck::FilterState;
|
||||||
|
|
||||||
use crate::timeline::{PubkeySource, Timeline, TimelineKind};
|
use crate::timeline::{PubkeySource, Timeline, TimelineKind, TimelineTab};
|
||||||
use enostr::{Filter, Pubkey};
|
use enostr::{Filter, Pubkey};
|
||||||
use nostrdb::Ndb;
|
use nostrdb::Ndb;
|
||||||
use tracing::{debug, error, info};
|
use tracing::{debug, error, info};
|
||||||
@@ -151,6 +151,7 @@ impl ArgColumn {
|
|||||||
ArgColumn::Generic(filters) => Some(Timeline::new(
|
ArgColumn::Generic(filters) => Some(Timeline::new(
|
||||||
TimelineKind::Generic,
|
TimelineKind::Generic,
|
||||||
FilterState::ready(filters),
|
FilterState::ready(filters),
|
||||||
|
TimelineTab::full_tabs(),
|
||||||
)),
|
)),
|
||||||
ArgColumn::Timeline(tk) => tk.into_timeline(ndb, user),
|
ArgColumn::Timeline(tk) => tk.into_timeline(ndb, user),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use notedeck::{filter::default_limit, FilterState, MuteFun, NoteCache, NoteRef};
|
|||||||
use crate::{
|
use crate::{
|
||||||
multi_subscriber::MultiSubscriber,
|
multi_subscriber::MultiSubscriber,
|
||||||
notes_holder::NotesHolder,
|
notes_holder::NotesHolder,
|
||||||
timeline::{copy_notes_into_timeline, PubkeySource, Timeline, TimelineKind},
|
timeline::{copy_notes_into_timeline, PubkeySource, Timeline, TimelineKind, TimelineTab},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum DisplayName<'a> {
|
pub enum DisplayName<'a> {
|
||||||
@@ -62,8 +62,11 @@ impl Profile {
|
|||||||
notes: Vec<NoteRef>,
|
notes: Vec<NoteRef>,
|
||||||
is_muted: &MuteFun,
|
is_muted: &MuteFun,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut timeline =
|
let mut timeline = Timeline::new(
|
||||||
Timeline::new(TimelineKind::profile(source), FilterState::ready(filters));
|
TimelineKind::profile(source),
|
||||||
|
FilterState::ready(filters),
|
||||||
|
TimelineTab::full_tabs(),
|
||||||
|
);
|
||||||
|
|
||||||
copy_notes_into_timeline(&mut timeline, txn, ndb, note_cache, notes, is_muted);
|
copy_notes_into_timeline(&mut timeline, txn, ndb, note_cache, notes, is_muted);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::timeline::Timeline;
|
use crate::timeline::{Timeline, TimelineTab};
|
||||||
use enostr::{Filter, Pubkey};
|
use enostr::{Filter, Pubkey};
|
||||||
use nostrdb::{Ndb, Transaction};
|
use nostrdb::{Ndb, Transaction};
|
||||||
use notedeck::{filter::default_limit, FilterError, FilterState};
|
use notedeck::{filter::default_limit, FilterError, FilterState};
|
||||||
@@ -119,6 +119,7 @@ impl TimelineKind {
|
|||||||
.kinds([1])
|
.kinds([1])
|
||||||
.limit(default_limit())
|
.limit(default_limit())
|
||||||
.build()]),
|
.build()]),
|
||||||
|
TimelineTab::no_replies(),
|
||||||
)),
|
)),
|
||||||
|
|
||||||
TimelineKind::Generic => {
|
TimelineKind::Generic => {
|
||||||
@@ -141,6 +142,7 @@ impl TimelineKind {
|
|||||||
Some(Timeline::new(
|
Some(Timeline::new(
|
||||||
TimelineKind::profile(pk_src),
|
TimelineKind::profile(pk_src),
|
||||||
FilterState::ready(vec![filter]),
|
FilterState::ready(vec![filter]),
|
||||||
|
TimelineTab::full_tabs(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,6 +161,7 @@ impl TimelineKind {
|
|||||||
Some(Timeline::new(
|
Some(Timeline::new(
|
||||||
TimelineKind::notifications(pk_src),
|
TimelineKind::notifications(pk_src),
|
||||||
FilterState::ready(vec![notifications_filter]),
|
FilterState::ready(vec![notifications_filter]),
|
||||||
|
TimelineTab::only_notes_and_replies(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,6 +184,7 @@ impl TimelineKind {
|
|||||||
return Some(Timeline::new(
|
return Some(Timeline::new(
|
||||||
TimelineKind::contact_list(pk_src),
|
TimelineKind::contact_list(pk_src),
|
||||||
FilterState::needs_remote(vec![contact_filter.clone()]),
|
FilterState::needs_remote(vec![contact_filter.clone()]),
|
||||||
|
TimelineTab::full_tabs(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,6 +193,7 @@ impl TimelineKind {
|
|||||||
Some(Timeline::new(
|
Some(Timeline::new(
|
||||||
TimelineKind::contact_list(pk_src),
|
TimelineKind::contact_list(pk_src),
|
||||||
FilterState::needs_remote(vec![contact_filter]),
|
FilterState::needs_remote(vec![contact_filter]),
|
||||||
|
TimelineTab::full_tabs(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|||||||
@@ -60,13 +60,6 @@ impl ViewFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn index(&self) -> usize {
|
|
||||||
match self {
|
|
||||||
ViewFilter::Notes => 0,
|
|
||||||
ViewFilter::NotesAndReplies => 1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn filter_notes(cache: &CachedNote, note: &Note) -> bool {
|
pub fn filter_notes(cache: &CachedNote, note: &Note) -> bool {
|
||||||
!cache.reply.borrow(note.tags()).is_reply()
|
!cache.reply.borrow(note.tags()).is_reply()
|
||||||
}
|
}
|
||||||
@@ -100,6 +93,21 @@ impl TimelineTab {
|
|||||||
TimelineTab::new_with_capacity(filter, 1000)
|
TimelineTab::new_with_capacity(filter, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn only_notes_and_replies() -> Vec<Self> {
|
||||||
|
vec![TimelineTab::new(ViewFilter::NotesAndReplies)]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn no_replies() -> Vec<Self> {
|
||||||
|
vec![TimelineTab::new(ViewFilter::Notes)]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn full_tabs() -> Vec<Self> {
|
||||||
|
vec![
|
||||||
|
TimelineTab::new(ViewFilter::Notes),
|
||||||
|
TimelineTab::new(ViewFilter::NotesAndReplies),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new_with_capacity(filter: ViewFilter, cap: usize) -> Self {
|
pub fn new_with_capacity(filter: ViewFilter, cap: usize) -> Self {
|
||||||
let selection = 0i32;
|
let selection = 0i32;
|
||||||
let mut list = VirtualList::new();
|
let mut list = VirtualList::new();
|
||||||
@@ -179,7 +187,7 @@ pub struct Timeline {
|
|||||||
// that codepaths have to explicitly handle it
|
// that codepaths have to explicitly handle it
|
||||||
pub filter: FilterStates,
|
pub filter: FilterStates,
|
||||||
pub views: Vec<TimelineTab>,
|
pub views: Vec<TimelineTab>,
|
||||||
pub selected_view: i32,
|
pub selected_view: usize,
|
||||||
|
|
||||||
/// Our nostrdb subscription
|
/// Our nostrdb subscription
|
||||||
pub subscription: Option<Subscription>,
|
pub subscription: Option<Subscription>,
|
||||||
@@ -198,6 +206,7 @@ impl Timeline {
|
|||||||
Ok(Timeline::new(
|
Ok(Timeline::new(
|
||||||
TimelineKind::contact_list(pk_src),
|
TimelineKind::contact_list(pk_src),
|
||||||
FilterState::ready(filter),
|
FilterState::ready(filter),
|
||||||
|
TimelineTab::full_tabs(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,10 +220,11 @@ impl Timeline {
|
|||||||
Timeline::new(
|
Timeline::new(
|
||||||
TimelineKind::Hashtag(hashtag),
|
TimelineKind::Hashtag(hashtag),
|
||||||
FilterState::ready(vec![filter]),
|
FilterState::ready(vec![filter]),
|
||||||
|
TimelineTab::full_tabs(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_view_id(id: TimelineId, selected_view: i32) -> egui::Id {
|
pub fn make_view_id(id: TimelineId, selected_view: usize) -> egui::Id {
|
||||||
egui::Id::new((id, selected_view))
|
egui::Id::new((id, selected_view))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,15 +232,12 @@ impl Timeline {
|
|||||||
Timeline::make_view_id(self.id, self.selected_view)
|
Timeline::make_view_id(self.id, self.selected_view)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(kind: TimelineKind, filter_state: FilterState) -> Self {
|
pub fn new(kind: TimelineKind, filter_state: FilterState, views: Vec<TimelineTab>) -> Self {
|
||||||
// global unique id for all new timelines
|
// global unique id for all new timelines
|
||||||
static UIDS: AtomicU32 = AtomicU32::new(0);
|
static UIDS: AtomicU32 = AtomicU32::new(0);
|
||||||
|
|
||||||
let filter = FilterStates::new(filter_state);
|
let filter = FilterStates::new(filter_state);
|
||||||
let subscription: Option<Subscription> = None;
|
let subscription: Option<Subscription> = None;
|
||||||
let notes = TimelineTab::new(ViewFilter::Notes);
|
|
||||||
let replies = TimelineTab::new(ViewFilter::NotesAndReplies);
|
|
||||||
let views = vec![notes, replies];
|
|
||||||
let selected_view = 0;
|
let selected_view = 0;
|
||||||
let id = TimelineId::new(UIDS.fetch_add(1, Ordering::Relaxed));
|
let id = TimelineId::new(UIDS.fetch_add(1, Ordering::Relaxed));
|
||||||
|
|
||||||
@@ -245,23 +252,32 @@ impl Timeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_view(&self) -> &TimelineTab {
|
pub fn current_view(&self) -> &TimelineTab {
|
||||||
&self.views[self.selected_view as usize]
|
&self.views[self.selected_view]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_view_mut(&mut self) -> &mut TimelineTab {
|
pub fn current_view_mut(&mut self) -> &mut TimelineTab {
|
||||||
&mut self.views[self.selected_view as usize]
|
&mut self.views[self.selected_view]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn notes(&self, view: ViewFilter) -> &[NoteRef] {
|
/// Get the note refs for NotesAndReplies. If we only have Notes, then
|
||||||
&self.views[view.index()].notes
|
/// just return that instead
|
||||||
|
pub fn all_or_any_notes(&self) -> &[NoteRef] {
|
||||||
|
self.notes(ViewFilter::NotesAndReplies).unwrap_or_else(|| {
|
||||||
|
self.notes(ViewFilter::Notes)
|
||||||
|
.expect("should have at least notes")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self, view: ViewFilter) -> &TimelineTab {
|
pub fn notes(&self, view: ViewFilter) -> Option<&[NoteRef]> {
|
||||||
&self.views[view.index()]
|
self.view(view).map(|v| &*v.notes)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view_mut(&mut self, view: ViewFilter) -> &mut TimelineTab {
|
pub fn view(&self, view: ViewFilter) -> Option<&TimelineTab> {
|
||||||
&mut self.views[view.index()]
|
self.views.iter().find(|tab| tab.filter == view)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn view_mut(&mut self, view: ViewFilter) -> Option<&mut TimelineTab> {
|
||||||
|
self.views.iter_mut().find(|tab| tab.filter == view)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn poll_notes_into_view(
|
pub fn poll_notes_into_view(
|
||||||
@@ -314,13 +330,10 @@ impl Timeline {
|
|||||||
let reversed = false;
|
let reversed = false;
|
||||||
|
|
||||||
// ViewFilter::NotesAndReplies
|
// ViewFilter::NotesAndReplies
|
||||||
{
|
if let Some(view) = timeline.view_mut(ViewFilter::NotesAndReplies) {
|
||||||
let refs: Vec<NoteRef> = new_refs.iter().map(|(_note, nr)| *nr).collect();
|
let refs: Vec<NoteRef> = new_refs.iter().map(|(_note, nr)| *nr).collect();
|
||||||
|
|
||||||
let reversed = false;
|
view.insert(&refs, reversed);
|
||||||
timeline
|
|
||||||
.view_mut(ViewFilter::NotesAndReplies)
|
|
||||||
.insert(&refs, reversed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -328,7 +341,7 @@ impl Timeline {
|
|||||||
//
|
//
|
||||||
// TODO(jb55): this is mostly just copied from above, let's just use a loop
|
// TODO(jb55): this is mostly just copied from above, let's just use a loop
|
||||||
// I initially tried this but ran into borrow checker issues
|
// I initially tried this but ran into borrow checker issues
|
||||||
{
|
if let Some(view) = timeline.view_mut(ViewFilter::Notes) {
|
||||||
let mut filtered_refs = Vec::with_capacity(new_refs.len());
|
let mut filtered_refs = Vec::with_capacity(new_refs.len());
|
||||||
for (note, nr) in &new_refs {
|
for (note, nr) in &new_refs {
|
||||||
let cached_note = note_cache.cached_note_or_insert(nr.key, note);
|
let cached_note = note_cache.cached_note_or_insert(nr.key, note);
|
||||||
@@ -338,9 +351,7 @@ impl Timeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
timeline
|
view.insert(&filtered_refs, reversed);
|
||||||
.view_mut(ViewFilter::Notes)
|
|
||||||
.insert(&filtered_refs, reversed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -478,7 +489,7 @@ pub fn send_initial_timeline_filter(
|
|||||||
filter = filter.limit_mut(lim);
|
filter = filter.limit_mut(lim);
|
||||||
}
|
}
|
||||||
|
|
||||||
let notes = timeline.notes(ViewFilter::NotesAndReplies);
|
let notes = timeline.all_or_any_notes();
|
||||||
|
|
||||||
// Should we since optimize? Not always. For example
|
// Should we since optimize? Not always. For example
|
||||||
// if we only have a few notes locally. One way to
|
// if we only have a few notes locally. One way to
|
||||||
|
|||||||
@@ -67,7 +67,8 @@ impl<'a> ProfileView<'a> {
|
|||||||
)
|
)
|
||||||
.get_ptr();
|
.get_ptr();
|
||||||
|
|
||||||
profile.timeline.selected_view = tabs_ui(ui);
|
profile.timeline.selected_view =
|
||||||
|
tabs_ui(ui, profile.timeline.selected_view, &profile.timeline.views);
|
||||||
|
|
||||||
// poll for new notes and insert them into our existing notes
|
// poll for new notes and insert them into our existing notes
|
||||||
if let Err(e) = profile.poll_notes_into_view(&txn, self.ndb, is_muted) {
|
if let Err(e) = profile.poll_notes_into_view(&txn, self.ndb, is_muted) {
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
use crate::actionbar::NoteAction;
|
use crate::actionbar::NoteAction;
|
||||||
use crate::timeline::TimelineTab;
|
use crate::timeline::TimelineTab;
|
||||||
use crate::{column::Columns, timeline::TimelineId, ui, ui::note::NoteOptions};
|
use crate::{
|
||||||
|
column::Columns,
|
||||||
|
timeline::{TimelineId, ViewFilter},
|
||||||
|
ui,
|
||||||
|
ui::note::NoteOptions,
|
||||||
|
};
|
||||||
use egui::containers::scroll_area::ScrollBarVisibility;
|
use egui::containers::scroll_area::ScrollBarVisibility;
|
||||||
use egui::{Direction, Layout};
|
use egui::{Direction, Layout};
|
||||||
use egui_tabs::TabColor;
|
use egui_tabs::TabColor;
|
||||||
@@ -86,7 +91,7 @@ fn timeline_ui(
|
|||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
timeline.selected_view = tabs_ui(ui);
|
timeline.selected_view = tabs_ui(ui, timeline.selected_view, &timeline.views);
|
||||||
|
|
||||||
// need this for some reason??
|
// need this for some reason??
|
||||||
ui.add_space(3.0);
|
ui.add_space(3.0);
|
||||||
@@ -124,11 +129,11 @@ fn timeline_ui(
|
|||||||
.inner
|
.inner
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tabs_ui(ui: &mut egui::Ui) -> i32 {
|
pub fn tabs_ui(ui: &mut egui::Ui, selected: usize, views: &[TimelineTab]) -> usize {
|
||||||
ui.spacing_mut().item_spacing.y = 0.0;
|
ui.spacing_mut().item_spacing.y = 0.0;
|
||||||
|
|
||||||
let tab_res = egui_tabs::Tabs::new(2)
|
let tab_res = egui_tabs::Tabs::new(views.len() as i32)
|
||||||
.selected(1)
|
.selected(selected as i32)
|
||||||
.hover_bg(TabColor::none())
|
.hover_bg(TabColor::none())
|
||||||
.selected_fg(TabColor::none())
|
.selected_fg(TabColor::none())
|
||||||
.selected_bg(TabColor::none())
|
.selected_bg(TabColor::none())
|
||||||
@@ -141,7 +146,10 @@ pub fn tabs_ui(ui: &mut egui::Ui) -> i32 {
|
|||||||
|
|
||||||
let ind = state.index();
|
let ind = state.index();
|
||||||
|
|
||||||
let txt = if ind == 0 { "Notes" } else { "Notes & Replies" };
|
let txt = match views[ind as usize].filter {
|
||||||
|
ViewFilter::Notes => "Notes",
|
||||||
|
ViewFilter::NotesAndReplies => "Notes & Replies",
|
||||||
|
};
|
||||||
|
|
||||||
let res = ui.add(egui::Label::new(txt).selectable(false));
|
let res = ui.add(egui::Label::new(txt).selectable(false));
|
||||||
|
|
||||||
@@ -189,7 +197,7 @@ pub fn tabs_ui(ui: &mut egui::Ui) -> i32 {
|
|||||||
|
|
||||||
ui.painter().hline(underline, underline_y, stroke);
|
ui.painter().hline(underline, underline_y, stroke);
|
||||||
|
|
||||||
sel
|
sel as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_label_width(ui: &mut egui::Ui, text: &str) -> f32 {
|
fn get_label_width(ui: &mut egui::Ui, text: &str) -> f32 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{column::Columns, timeline::ViewFilter, Result};
|
use crate::{column::Columns, Result};
|
||||||
use nostrdb::{Ndb, NoteKey, Transaction};
|
use nostrdb::{Ndb, NoteKey, Transaction};
|
||||||
use notedeck::{CachedNote, NoteCache, UnknownIds};
|
use notedeck::{CachedNote, NoteCache, UnknownIds};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
@@ -37,7 +37,7 @@ pub fn get_unknown_ids(
|
|||||||
let mut new_cached_notes: Vec<(NoteKey, CachedNote)> = vec![];
|
let mut new_cached_notes: Vec<(NoteKey, CachedNote)> = vec![];
|
||||||
|
|
||||||
for timeline in columns.timelines() {
|
for timeline in columns.timelines() {
|
||||||
for noteref in timeline.notes(ViewFilter::NotesAndReplies) {
|
for noteref in timeline.all_or_any_notes() {
|
||||||
let note = ndb.get_note_by_key(txn, noteref.key)?;
|
let note = ndb.get_note_by_key(txn, noteref.key)?;
|
||||||
let note_key = note.key().unwrap();
|
let note_key = note.key().unwrap();
|
||||||
let cached_note = note_cache.cached_note(noteref.key);
|
let cached_note = note_cache.cached_note(noteref.key);
|
||||||
|
|||||||
Reference in New Issue
Block a user