committed by
William Casarin
parent
35613f2e74
commit
69e93b0ebf
@@ -8,12 +8,13 @@ use uuid::Uuid;
|
|||||||
use enostr::{ClientMessage, FilledKeypair, FullKeypair, Keypair, RelayPool};
|
use enostr::{ClientMessage, FilledKeypair, FullKeypair, Keypair, RelayPool};
|
||||||
use nostrdb::{Filter, Ndb, Note, NoteKey, Subscription, Transaction};
|
use nostrdb::{Filter, Ndb, Note, NoteKey, Subscription, Transaction};
|
||||||
|
|
||||||
|
use crate::app::get_active_columns_mut;
|
||||||
|
use crate::decks::DecksCache;
|
||||||
use crate::{
|
use crate::{
|
||||||
column::Columns,
|
|
||||||
imgcache::ImageCache,
|
imgcache::ImageCache,
|
||||||
login_manager::AcquireKeyState,
|
login_manager::AcquireKeyState,
|
||||||
muted::Muted,
|
muted::Muted,
|
||||||
route::{Route, Router},
|
route::Route,
|
||||||
storage::{KeyStorageResponse, KeyStorageType},
|
storage::{KeyStorageResponse, KeyStorageType},
|
||||||
ui::{
|
ui::{
|
||||||
account_login_view::{AccountLoginResponse, AccountLoginView},
|
account_login_view::{AccountLoginResponse, AccountLoginView},
|
||||||
@@ -230,13 +231,12 @@ pub fn render_accounts_route(
|
|||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
ndb: &Ndb,
|
ndb: &Ndb,
|
||||||
col: usize,
|
col: usize,
|
||||||
columns: &mut Columns,
|
|
||||||
img_cache: &mut ImageCache,
|
img_cache: &mut ImageCache,
|
||||||
accounts: &mut Accounts,
|
accounts: &mut Accounts,
|
||||||
|
decks: &mut DecksCache,
|
||||||
login_state: &mut AcquireKeyState,
|
login_state: &mut AcquireKeyState,
|
||||||
route: AccountsRoute,
|
route: AccountsRoute,
|
||||||
) -> SingleUnkIdAction {
|
) -> SingleUnkIdAction {
|
||||||
let router = columns.column_mut(col).router_mut();
|
|
||||||
let resp = match route {
|
let resp = match route {
|
||||||
AccountsRoute::Accounts => AccountsView::new(ndb, accounts, img_cache)
|
AccountsRoute::Accounts => AccountsView::new(ndb, accounts, img_cache)
|
||||||
.ui(ui)
|
.ui(ui)
|
||||||
@@ -252,12 +252,15 @@ pub fn render_accounts_route(
|
|||||||
if let Some(resp) = resp {
|
if let Some(resp) = resp {
|
||||||
match resp {
|
match resp {
|
||||||
AccountsRouteResponse::Accounts(response) => {
|
AccountsRouteResponse::Accounts(response) => {
|
||||||
process_accounts_view_response(accounts, response, router);
|
process_accounts_view_response(accounts, decks, col, response);
|
||||||
SingleUnkIdAction::no_action()
|
SingleUnkIdAction::no_action()
|
||||||
}
|
}
|
||||||
AccountsRouteResponse::AddAccount(response) => {
|
AccountsRouteResponse::AddAccount(response) => {
|
||||||
let action = process_login_view_response(accounts, response);
|
let action = process_login_view_response(accounts, decks, response);
|
||||||
*login_state = Default::default();
|
*login_state = Default::default();
|
||||||
|
let router = get_active_columns_mut(accounts, decks)
|
||||||
|
.column_mut(col)
|
||||||
|
.router_mut();
|
||||||
router.go_back();
|
router.go_back();
|
||||||
action
|
action
|
||||||
}
|
}
|
||||||
@@ -268,16 +271,20 @@ pub fn render_accounts_route(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_accounts_view_response(
|
pub fn process_accounts_view_response(
|
||||||
manager: &mut Accounts,
|
accounts: &mut Accounts,
|
||||||
|
decks: &mut DecksCache,
|
||||||
|
col: usize,
|
||||||
response: AccountsViewResponse,
|
response: AccountsViewResponse,
|
||||||
router: &mut Router<Route>,
|
|
||||||
) {
|
) {
|
||||||
|
let router = get_active_columns_mut(accounts, decks)
|
||||||
|
.column_mut(col)
|
||||||
|
.router_mut();
|
||||||
match response {
|
match response {
|
||||||
AccountsViewResponse::RemoveAccount(index) => {
|
AccountsViewResponse::RemoveAccount(index) => {
|
||||||
manager.remove_account(index);
|
accounts.remove_account(index);
|
||||||
}
|
}
|
||||||
AccountsViewResponse::SelectAccount(index) => {
|
AccountsViewResponse::SelectAccount(index) => {
|
||||||
manager.select_account(index);
|
accounts.select_account(index);
|
||||||
}
|
}
|
||||||
AccountsViewResponse::RouteToLogin => {
|
AccountsViewResponse::RouteToLogin => {
|
||||||
router.route_to(Route::add_account());
|
router.route_to(Route::add_account());
|
||||||
@@ -619,15 +626,18 @@ fn get_selected_index(accounts: &[UserAccount], keystore: &KeyStorageType) -> Op
|
|||||||
|
|
||||||
pub fn process_login_view_response(
|
pub fn process_login_view_response(
|
||||||
manager: &mut Accounts,
|
manager: &mut Accounts,
|
||||||
|
decks: &mut DecksCache,
|
||||||
response: AccountLoginResponse,
|
response: AccountLoginResponse,
|
||||||
) -> SingleUnkIdAction {
|
) -> SingleUnkIdAction {
|
||||||
let login_action = match response {
|
let (pubkey, login_action) = match response {
|
||||||
AccountLoginResponse::CreateNew => {
|
AccountLoginResponse::CreateNew => {
|
||||||
manager.add_account(FullKeypair::generate().to_keypair())
|
let kp = FullKeypair::generate().to_keypair();
|
||||||
|
(kp.pubkey, manager.add_account(kp))
|
||||||
}
|
}
|
||||||
AccountLoginResponse::LoginWith(keypair) => manager.add_account(keypair),
|
AccountLoginResponse::LoginWith(keypair) => (keypair.pubkey, manager.add_account(keypair)),
|
||||||
};
|
};
|
||||||
manager.select_account(login_action.switch_to_index);
|
manager.select_account(login_action.switch_to_index);
|
||||||
|
decks.add_deck_default(pubkey);
|
||||||
login_action.unk
|
login_action.unk
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
144
src/app.rs
144
src/app.rs
@@ -3,7 +3,8 @@ use crate::{
|
|||||||
app_creation::setup_cc,
|
app_creation::setup_cc,
|
||||||
app_size_handler::AppSizeHandler,
|
app_size_handler::AppSizeHandler,
|
||||||
args::Args,
|
args::Args,
|
||||||
column::{Column, Columns},
|
column::Columns,
|
||||||
|
decks::{Decks, DecksCache},
|
||||||
draft::Drafts,
|
draft::Drafts,
|
||||||
filter::FilterState,
|
filter::FilterState,
|
||||||
frame_history::FrameHistory,
|
frame_history::FrameHistory,
|
||||||
@@ -12,13 +13,12 @@ use crate::{
|
|||||||
notecache::NoteCache,
|
notecache::NoteCache,
|
||||||
notes_holder::NotesHolderStorage,
|
notes_holder::NotesHolderStorage,
|
||||||
profile::Profile,
|
profile::Profile,
|
||||||
route::Route,
|
|
||||||
storage::{self, DataPath, DataPathType, Directory, FileKeyStorage, KeyStorageType},
|
storage::{self, DataPath, DataPathType, Directory, FileKeyStorage, KeyStorageType},
|
||||||
subscriptions::{SubKind, Subscriptions},
|
subscriptions::{SubKind, Subscriptions},
|
||||||
support::Support,
|
support::Support,
|
||||||
thread::Thread,
|
thread::Thread,
|
||||||
timeline::{self, Timeline, TimelineKind},
|
timeline::{self, Timeline},
|
||||||
ui::{self, add_column::AddColumnRoute, DesktopSidePanel},
|
ui::{self, DesktopSidePanel},
|
||||||
unknowns::UnknownIds,
|
unknowns::UnknownIds,
|
||||||
view_state::ViewState,
|
view_state::ViewState,
|
||||||
Result,
|
Result,
|
||||||
@@ -30,7 +30,7 @@ use uuid::Uuid;
|
|||||||
use egui::{Context, Frame, Style};
|
use egui::{Context, Frame, Style};
|
||||||
use egui_extras::{Size, StripBuilder};
|
use egui_extras::{Size, StripBuilder};
|
||||||
|
|
||||||
use nostrdb::{Config, Filter, Ndb, Transaction};
|
use nostrdb::{Config, Ndb, Transaction};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@@ -49,7 +49,7 @@ pub struct Damus {
|
|||||||
pub note_cache: NoteCache,
|
pub note_cache: NoteCache,
|
||||||
pub pool: RelayPool,
|
pub pool: RelayPool,
|
||||||
|
|
||||||
pub columns: Columns,
|
pub decks_cache: DecksCache,
|
||||||
pub ndb: Ndb,
|
pub ndb: Ndb,
|
||||||
pub view_state: ViewState,
|
pub view_state: ViewState,
|
||||||
pub unknown_ids: UnknownIds,
|
pub unknown_ids: UnknownIds,
|
||||||
@@ -98,7 +98,8 @@ fn handle_key_events(input: &egui::InputState, _pixels_per_point: f32, columns:
|
|||||||
|
|
||||||
fn try_process_event(damus: &mut Damus, ctx: &egui::Context) -> Result<()> {
|
fn try_process_event(damus: &mut Damus, ctx: &egui::Context) -> Result<()> {
|
||||||
let ppp = ctx.pixels_per_point();
|
let ppp = ctx.pixels_per_point();
|
||||||
ctx.input(|i| handle_key_events(i, ppp, &mut damus.columns));
|
let current_columns = get_active_columns_mut(&damus.accounts, &mut damus.decks_cache);
|
||||||
|
ctx.input(|i| handle_key_events(i, ppp, current_columns));
|
||||||
|
|
||||||
let ctx2 = ctx.clone();
|
let ctx2 = ctx.clone();
|
||||||
let wakeup = move || {
|
let wakeup = move || {
|
||||||
@@ -124,7 +125,7 @@ fn try_process_event(damus: &mut Damus, ctx: &egui::Context) -> Result<()> {
|
|||||||
timeline::send_initial_timeline_filters(
|
timeline::send_initial_timeline_filters(
|
||||||
&damus.ndb,
|
&damus.ndb,
|
||||||
damus.since_optimize,
|
damus.since_optimize,
|
||||||
&mut damus.columns,
|
get_active_columns_mut(&damus.accounts, &mut damus.decks_cache),
|
||||||
&mut damus.subscriptions,
|
&mut damus.subscriptions,
|
||||||
&mut damus.pool,
|
&mut damus.pool,
|
||||||
&ev.relay,
|
&ev.relay,
|
||||||
@@ -138,10 +139,11 @@ fn try_process_event(damus: &mut Damus, ctx: &egui::Context) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let n_timelines = damus.columns.timelines().len();
|
let current_columns = get_active_columns_mut(&damus.accounts, &mut damus.decks_cache);
|
||||||
|
let n_timelines = current_columns.timelines().len();
|
||||||
for timeline_ind in 0..n_timelines {
|
for timeline_ind in 0..n_timelines {
|
||||||
let is_ready = {
|
let is_ready = {
|
||||||
let timeline = &mut damus.columns.timelines[timeline_ind];
|
let timeline = &mut current_columns.timelines[timeline_ind];
|
||||||
timeline::is_timeline_ready(
|
timeline::is_timeline_ready(
|
||||||
&damus.ndb,
|
&damus.ndb,
|
||||||
&mut damus.pool,
|
&mut damus.pool,
|
||||||
@@ -156,7 +158,7 @@ fn try_process_event(damus: &mut Damus, ctx: &egui::Context) -> Result<()> {
|
|||||||
|
|
||||||
if let Err(err) = Timeline::poll_notes_into_view(
|
if let Err(err) = Timeline::poll_notes_into_view(
|
||||||
timeline_ind,
|
timeline_ind,
|
||||||
damus.columns.timelines_mut(),
|
current_columns.timelines_mut(),
|
||||||
&damus.ndb,
|
&damus.ndb,
|
||||||
&txn,
|
&txn,
|
||||||
&mut damus.unknown_ids,
|
&mut damus.unknown_ids,
|
||||||
@@ -209,7 +211,7 @@ fn update_damus(damus: &mut Damus, ctx: &egui::Context) {
|
|||||||
if let Err(err) = timeline::setup_initial_nostrdb_subs(
|
if let Err(err) = timeline::setup_initial_nostrdb_subs(
|
||||||
&damus.ndb,
|
&damus.ndb,
|
||||||
&mut damus.note_cache,
|
&mut damus.note_cache,
|
||||||
&mut damus.columns,
|
&mut damus.decks_cache,
|
||||||
&damus.accounts.mutefun(),
|
&damus.accounts.mutefun(),
|
||||||
) {
|
) {
|
||||||
warn!("update_damus init: {err}");
|
warn!("update_damus init: {err}");
|
||||||
@@ -257,7 +259,7 @@ fn handle_eose(damus: &mut Damus, subid: &str, relay_url: &str) -> Result<()> {
|
|||||||
UnknownIds::update(
|
UnknownIds::update(
|
||||||
&txn,
|
&txn,
|
||||||
&mut damus.unknown_ids,
|
&mut damus.unknown_ids,
|
||||||
&damus.columns,
|
get_active_columns(&damus.accounts, &damus.decks_cache),
|
||||||
&damus.ndb,
|
&damus.ndb,
|
||||||
&mut damus.note_cache,
|
&mut damus.note_cache,
|
||||||
);
|
);
|
||||||
@@ -274,7 +276,10 @@ fn handle_eose(damus: &mut Damus, subid: &str, relay_url: &str) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SubKind::FetchingContactList(timeline_uid) => {
|
SubKind::FetchingContactList(timeline_uid) => {
|
||||||
let timeline = if let Some(tl) = damus.columns.find_timeline_mut(timeline_uid) {
|
let timeline = if let Some(tl) =
|
||||||
|
get_active_columns_mut(&damus.accounts, &mut damus.decks_cache)
|
||||||
|
.find_timeline_mut(timeline_uid)
|
||||||
|
{
|
||||||
tl
|
tl
|
||||||
} else {
|
} else {
|
||||||
error!(
|
error!(
|
||||||
@@ -435,7 +440,7 @@ impl Damus {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|a| a.pubkey.bytes());
|
.map(|a| a.pubkey.bytes());
|
||||||
|
|
||||||
let mut columns = if parsed_args.columns.is_empty() {
|
let columns = if parsed_args.columns.is_empty() {
|
||||||
if let Some(serializable_columns) = storage::load_columns(&path) {
|
if let Some(serializable_columns) = storage::load_columns(&path) {
|
||||||
info!("Using columns from disk");
|
info!("Using columns from disk");
|
||||||
serializable_columns.into_columns(&ndb, account)
|
serializable_columns.into_columns(&ndb, account)
|
||||||
@@ -458,13 +463,35 @@ impl Damus {
|
|||||||
columns
|
columns
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut decks_cache = {
|
||||||
|
let mut decks_cache = DecksCache::default();
|
||||||
|
|
||||||
|
let mut decks = Decks::default();
|
||||||
|
*decks.active_mut().columns_mut() = columns;
|
||||||
|
|
||||||
|
if let Some(acc) = account {
|
||||||
|
decks_cache.add_decks(Pubkey::new(*acc), decks);
|
||||||
|
}
|
||||||
|
|
||||||
|
decks_cache
|
||||||
|
};
|
||||||
|
|
||||||
let debug = parsed_args.debug;
|
let debug = parsed_args.debug;
|
||||||
|
|
||||||
if columns.columns().is_empty() {
|
if get_active_columns(&accounts, &decks_cache)
|
||||||
|
.columns()
|
||||||
|
.is_empty()
|
||||||
|
{
|
||||||
if accounts.get_accounts().is_empty() {
|
if accounts.get_accounts().is_empty() {
|
||||||
set_demo(&path, &ndb, &mut accounts, &mut columns, &mut unknown_ids);
|
set_demo(
|
||||||
|
&path,
|
||||||
|
&ndb,
|
||||||
|
&mut accounts,
|
||||||
|
&mut decks_cache,
|
||||||
|
&mut unknown_ids,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
columns.new_column_picker();
|
get_active_columns_mut(&accounts, &mut decks_cache).new_column_picker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,7 +510,6 @@ impl Damus {
|
|||||||
state: DamusState::Initializing,
|
state: DamusState::Initializing,
|
||||||
img_cache: ImageCache::new(imgcache_dir),
|
img_cache: ImageCache::new(imgcache_dir),
|
||||||
note_cache: NoteCache::default(),
|
note_cache: NoteCache::default(),
|
||||||
columns,
|
|
||||||
textmode: parsed_args.textmode,
|
textmode: parsed_args.textmode,
|
||||||
ndb,
|
ndb,
|
||||||
accounts,
|
accounts,
|
||||||
@@ -492,6 +518,7 @@ impl Damus {
|
|||||||
path,
|
path,
|
||||||
app_rect_handler,
|
app_rect_handler,
|
||||||
support,
|
support,
|
||||||
|
decks_cache,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,11 +551,11 @@ impl Damus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn columns_mut(&mut self) -> &mut Columns {
|
pub fn columns_mut(&mut self) -> &mut Columns {
|
||||||
&mut self.columns
|
get_active_columns_mut(&self.accounts, &mut self.decks_cache)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn columns(&self) -> &Columns {
|
pub fn columns(&self) -> &Columns {
|
||||||
&self.columns
|
get_active_columns(&self.accounts, &self.decks_cache)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_subid(&self, kind: &SubKind) -> String {
|
pub fn gen_subid(&self, kind: &SubKind) -> String {
|
||||||
@@ -540,12 +567,7 @@ impl Damus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn mock<P: AsRef<Path>>(data_path: P) -> Self {
|
pub fn mock<P: AsRef<Path>>(data_path: P) -> Self {
|
||||||
let mut columns = Columns::new();
|
let decks_cache = DecksCache::default();
|
||||||
let filter = Filter::from_json(include_str!("../queries/global.json")).unwrap();
|
|
||||||
|
|
||||||
let timeline = Timeline::new(TimelineKind::Universe, FilterState::ready(vec![filter]));
|
|
||||||
|
|
||||||
columns.add_new_timeline_column(timeline);
|
|
||||||
|
|
||||||
let path = DataPath::new(&data_path);
|
let path = DataPath::new(&data_path);
|
||||||
let imgcache_dir = path.path(DataPathType::Cache).join(ImageCache::rel_dir());
|
let imgcache_dir = path.path(DataPathType::Cache).join(ImageCache::rel_dir());
|
||||||
@@ -569,7 +591,6 @@ impl Damus {
|
|||||||
pool: RelayPool::new(),
|
pool: RelayPool::new(),
|
||||||
img_cache: ImageCache::new(imgcache_dir),
|
img_cache: ImageCache::new(imgcache_dir),
|
||||||
note_cache: NoteCache::default(),
|
note_cache: NoteCache::default(),
|
||||||
columns,
|
|
||||||
textmode: false,
|
textmode: false,
|
||||||
ndb: Ndb::new(
|
ndb: Ndb::new(
|
||||||
path.path(DataPathType::Db)
|
path.path(DataPathType::Db)
|
||||||
@@ -581,10 +602,10 @@ impl Damus {
|
|||||||
accounts: Accounts::new(KeyStorageType::None, vec![]),
|
accounts: Accounts::new(KeyStorageType::None, vec![]),
|
||||||
frame_history: FrameHistory::default(),
|
frame_history: FrameHistory::default(),
|
||||||
view_state: ViewState::default(),
|
view_state: ViewState::default(),
|
||||||
|
|
||||||
path,
|
path,
|
||||||
app_rect_handler,
|
app_rect_handler,
|
||||||
support,
|
support,
|
||||||
|
decks_cache,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -629,7 +650,7 @@ fn render_damus_mobile(ctx: &egui::Context, app: &mut Damus) {
|
|||||||
//let routes = app.timelines[0].routes.clone();
|
//let routes = app.timelines[0].routes.clone();
|
||||||
|
|
||||||
main_panel(&ctx.style(), ui::is_narrow(ctx)).show(ctx, |ui| {
|
main_panel(&ctx.style(), ui::is_narrow(ctx)).show(ctx, |ui| {
|
||||||
if !app.columns.columns().is_empty()
|
if !app.columns().columns().is_empty()
|
||||||
&& nav::render_nav(0, app, ui).process_render_nav_response(app)
|
&& nav::render_nav(0, app, ui).process_render_nav_response(app)
|
||||||
{
|
{
|
||||||
storage::save_columns(&app.path, app.columns().as_serializable_columns());
|
storage::save_columns(&app.path, app.columns().as_serializable_columns());
|
||||||
@@ -656,7 +677,9 @@ fn render_damus_desktop(ctx: &egui::Context, app: &mut Damus) {
|
|||||||
puffin::profile_function!();
|
puffin::profile_function!();
|
||||||
|
|
||||||
let screen_size = ctx.screen_rect().width();
|
let screen_size = ctx.screen_rect().width();
|
||||||
let calc_panel_width = (screen_size / app.columns.num_columns() as f32) - 30.0;
|
let calc_panel_width = (screen_size
|
||||||
|
/ get_active_columns(&app.accounts, &app.decks_cache).num_columns() as f32)
|
||||||
|
- 30.0;
|
||||||
let min_width = 320.0;
|
let min_width = 320.0;
|
||||||
let need_scroll = calc_panel_width < min_width;
|
let need_scroll = calc_panel_width < min_width;
|
||||||
let panel_sizes = if need_scroll {
|
let panel_sizes = if need_scroll {
|
||||||
@@ -680,7 +703,10 @@ fn render_damus_desktop(ctx: &egui::Context, app: &mut Damus) {
|
|||||||
fn timelines_view(ui: &mut egui::Ui, sizes: Size, app: &mut Damus) {
|
fn timelines_view(ui: &mut egui::Ui, sizes: Size, app: &mut Damus) {
|
||||||
StripBuilder::new(ui)
|
StripBuilder::new(ui)
|
||||||
.size(Size::exact(ui::side_panel::SIDE_PANEL_WIDTH))
|
.size(Size::exact(ui::side_panel::SIDE_PANEL_WIDTH))
|
||||||
.sizes(sizes, app.columns.num_columns())
|
.sizes(
|
||||||
|
sizes,
|
||||||
|
get_active_columns(&app.accounts, &app.decks_cache).num_columns(),
|
||||||
|
)
|
||||||
.clip(true)
|
.clip(true)
|
||||||
.horizontal(|mut strip| {
|
.horizontal(|mut strip| {
|
||||||
strip.cell(|ui| {
|
strip.cell(|ui| {
|
||||||
@@ -689,12 +715,14 @@ fn timelines_view(ui: &mut egui::Ui, sizes: Size, app: &mut Damus) {
|
|||||||
&app.ndb,
|
&app.ndb,
|
||||||
&mut app.img_cache,
|
&mut app.img_cache,
|
||||||
app.accounts.get_selected_account(),
|
app.accounts.get_selected_account(),
|
||||||
|
&app.decks_cache,
|
||||||
)
|
)
|
||||||
.show(ui);
|
.show(ui);
|
||||||
|
|
||||||
if side_panel.response.clicked() {
|
if side_panel.response.clicked() || side_panel.response.secondary_clicked() {
|
||||||
DesktopSidePanel::perform_action(
|
DesktopSidePanel::perform_action(
|
||||||
&mut app.columns,
|
&mut app.decks_cache,
|
||||||
|
&app.accounts,
|
||||||
&mut app.support,
|
&mut app.support,
|
||||||
side_panel.action,
|
side_panel.action,
|
||||||
);
|
);
|
||||||
@@ -708,8 +736,9 @@ fn timelines_view(ui: &mut egui::Ui, sizes: Size, app: &mut Damus) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut responses = Vec::with_capacity(app.columns.num_columns());
|
let num_cols = app.columns().num_columns();
|
||||||
for col_index in 0..app.columns.num_columns() {
|
let mut responses = Vec::with_capacity(num_cols);
|
||||||
|
for col_index in 0..num_cols {
|
||||||
strip.cell(|ui| {
|
strip.cell(|ui| {
|
||||||
let rect = ui.available_rect_before_wrap();
|
let rect = ui.available_rect_before_wrap();
|
||||||
responses.push(nav::render_nav(col_index, app, ui));
|
responses.push(nav::render_nav(col_index, app, ui));
|
||||||
@@ -756,13 +785,44 @@ impl eframe::App for Damus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_demo(
|
pub fn get_active_columns<'a>(accounts: &Accounts, decks_cache: &'a DecksCache) -> &'a Columns {
|
||||||
|
get_decks(accounts, decks_cache).active().columns()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_decks<'a>(accounts: &Accounts, decks_cache: &'a DecksCache) -> &'a Decks {
|
||||||
|
let key = if let Some(acc) = accounts.get_selected_account() {
|
||||||
|
&acc.pubkey
|
||||||
|
} else {
|
||||||
|
&decks_cache.fallback_pubkey
|
||||||
|
};
|
||||||
|
decks_cache.decks(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_active_columns_mut<'a>(
|
||||||
|
accounts: &Accounts,
|
||||||
|
decks_cache: &'a mut DecksCache,
|
||||||
|
) -> &'a mut Columns {
|
||||||
|
get_decks_mut(accounts, decks_cache)
|
||||||
|
.active_mut()
|
||||||
|
.columns_mut()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_decks_mut<'a>(accounts: &Accounts, decks_cache: &'a mut DecksCache) -> &'a mut Decks {
|
||||||
|
if let Some(acc) = accounts.get_selected_account() {
|
||||||
|
decks_cache.decks_mut(&acc.pubkey)
|
||||||
|
} else {
|
||||||
|
decks_cache.fallback_mut()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_demo(
|
||||||
data_path: &DataPath,
|
data_path: &DataPath,
|
||||||
ndb: &Ndb,
|
ndb: &Ndb,
|
||||||
accounts: &mut Accounts,
|
accounts: &mut Accounts,
|
||||||
columns: &mut Columns,
|
decks_cache: &mut DecksCache,
|
||||||
unk_ids: &mut UnknownIds,
|
unk_ids: &mut UnknownIds,
|
||||||
) {
|
) {
|
||||||
|
let columns = get_active_columns_mut(accounts, decks_cache);
|
||||||
let demo_pubkey =
|
let demo_pubkey =
|
||||||
Pubkey::from_hex("aa733081e4f0f79dd43023d8983265593f2b41a988671cfcef3f489b91ad93fe")
|
Pubkey::from_hex("aa733081e4f0f79dd43023d8983265593f2b41a988671cfcef3f489b91ad93fe")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -774,13 +834,13 @@ fn set_demo(
|
|||||||
accounts.select_account(0);
|
accounts.select_account(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
columns.add_column(Column::new(vec![
|
columns.add_column(crate::column::Column::new(vec![
|
||||||
Route::AddColumn(AddColumnRoute::Base),
|
crate::route::Route::AddColumn(ui::add_column::AddColumnRoute::Base),
|
||||||
Route::Accounts(AccountsRoute::Accounts),
|
crate::route::Route::Accounts(AccountsRoute::Accounts),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
if let Some(timeline) =
|
if let Some(timeline) =
|
||||||
TimelineKind::contact_list(timeline::PubkeySource::Explicit(demo_pubkey))
|
timeline::TimelineKind::contact_list(timeline::PubkeySource::Explicit(demo_pubkey))
|
||||||
.into_timeline(ndb, Some(demo_pubkey.bytes()))
|
.into_timeline(ndb, Some(demo_pubkey.bytes()))
|
||||||
{
|
{
|
||||||
columns.add_new_timeline_column(timeline);
|
columns.add_new_timeline_column(timeline);
|
||||||
|
|||||||
@@ -306,15 +306,15 @@ mod tests {
|
|||||||
let ctx = egui::Context::default();
|
let ctx = egui::Context::default();
|
||||||
let app = Damus::new(&ctx, &tmpdir, args);
|
let app = Damus::new(&ctx, &tmpdir, args);
|
||||||
|
|
||||||
assert_eq!(app.columns.columns().len(), 2);
|
assert_eq!(app.columns().columns().len(), 2);
|
||||||
|
|
||||||
let tl1 = app.columns.column(0).router().top().timeline_id();
|
let tl1 = app.columns().column(0).router().top().timeline_id();
|
||||||
let tl2 = app.columns.column(1).router().top().timeline_id();
|
let tl2 = app.columns().column(1).router().top().timeline_id();
|
||||||
|
|
||||||
assert_eq!(tl1.is_some(), true);
|
assert_eq!(tl1.is_some(), true);
|
||||||
assert_eq!(tl2.is_some(), true);
|
assert_eq!(tl2.is_some(), true);
|
||||||
|
|
||||||
let timelines = app.columns.timelines();
|
let timelines = app.columns().timelines();
|
||||||
assert!(timelines[0].kind.is_notifications());
|
assert!(timelines[0].kind.is_notifications());
|
||||||
assert!(timelines[1].kind.is_contacts());
|
assert!(timelines[1].kind.is_contacts());
|
||||||
|
|
||||||
|
|||||||
16
src/nav.rs
16
src/nav.rs
@@ -1,6 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
accounts::render_accounts_route,
|
accounts::render_accounts_route,
|
||||||
actionbar::NoteAction,
|
actionbar::NoteAction,
|
||||||
|
app::{get_active_columns, get_active_columns_mut},
|
||||||
notes_holder::NotesHolder,
|
notes_holder::NotesHolder,
|
||||||
profile::Profile,
|
profile::Profile,
|
||||||
relay_pool_manager::RelayPoolManager,
|
relay_pool_manager::RelayPoolManager,
|
||||||
@@ -87,7 +88,10 @@ impl RenderNavResponse {
|
|||||||
RenderNavAction::PostAction(post_action) => {
|
RenderNavAction::PostAction(post_action) => {
|
||||||
let txn = Transaction::new(&app.ndb).expect("txn");
|
let txn = Transaction::new(&app.ndb).expect("txn");
|
||||||
let _ = post_action.execute(&app.ndb, &txn, &mut app.pool, &mut app.drafts);
|
let _ = post_action.execute(&app.ndb, &txn, &mut app.pool, &mut app.drafts);
|
||||||
app.columns_mut().column_mut(col).router_mut().go_back();
|
get_active_columns_mut(&app.accounts, &mut app.decks_cache)
|
||||||
|
.column_mut(col)
|
||||||
|
.router_mut()
|
||||||
|
.go_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderNavAction::NoteAction(note_action) => {
|
RenderNavAction::NoteAction(note_action) => {
|
||||||
@@ -95,7 +99,7 @@ impl RenderNavResponse {
|
|||||||
|
|
||||||
note_action.execute_and_process_result(
|
note_action.execute_and_process_result(
|
||||||
&app.ndb,
|
&app.ndb,
|
||||||
&mut app.columns,
|
get_active_columns_mut(&app.accounts, &mut app.decks_cache),
|
||||||
col,
|
col,
|
||||||
&mut app.threads,
|
&mut app.threads,
|
||||||
&mut app.profiles,
|
&mut app.profiles,
|
||||||
@@ -176,7 +180,7 @@ fn render_nav_body(
|
|||||||
match top {
|
match top {
|
||||||
Route::Timeline(tlr) => render_timeline_route(
|
Route::Timeline(tlr) => render_timeline_route(
|
||||||
&app.ndb,
|
&app.ndb,
|
||||||
&mut app.columns,
|
get_active_columns_mut(&app.accounts, &mut app.decks_cache),
|
||||||
&mut app.drafts,
|
&mut app.drafts,
|
||||||
&mut app.img_cache,
|
&mut app.img_cache,
|
||||||
&mut app.unknown_ids,
|
&mut app.unknown_ids,
|
||||||
@@ -194,9 +198,9 @@ fn render_nav_body(
|
|||||||
ui,
|
ui,
|
||||||
&app.ndb,
|
&app.ndb,
|
||||||
col,
|
col,
|
||||||
&mut app.columns,
|
|
||||||
&mut app.img_cache,
|
&mut app.img_cache,
|
||||||
&mut app.accounts,
|
&mut app.accounts,
|
||||||
|
&mut app.decks_cache,
|
||||||
&mut app.view_state.login,
|
&mut app.view_state.login,
|
||||||
*amr,
|
*amr,
|
||||||
);
|
);
|
||||||
@@ -241,7 +245,7 @@ fn render_nav_body(
|
|||||||
|
|
||||||
#[must_use = "RenderNavResponse must be handled by calling .process_render_nav_response(..)"]
|
#[must_use = "RenderNavResponse must be handled by calling .process_render_nav_response(..)"]
|
||||||
pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) -> RenderNavResponse {
|
pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) -> RenderNavResponse {
|
||||||
let col_id = app.columns.get_column_id_at_index(col);
|
let col_id = get_active_columns(&app.accounts, &app.decks_cache).get_column_id_at_index(col);
|
||||||
// TODO(jb55): clean up this router_mut mess by using Router<R> in egui-nav directly
|
// TODO(jb55): clean up this router_mut mess by using Router<R> in egui-nav directly
|
||||||
|
|
||||||
let nav_response = Nav::new(app.columns().column(col).router().routes().clone())
|
let nav_response = Nav::new(app.columns().column(col).router().routes().clone())
|
||||||
@@ -252,7 +256,7 @@ pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) -> RenderNavRe
|
|||||||
NavUiType::Title => NavTitle::new(
|
NavUiType::Title => NavTitle::new(
|
||||||
&app.ndb,
|
&app.ndb,
|
||||||
&mut app.img_cache,
|
&mut app.img_cache,
|
||||||
&app.columns,
|
get_active_columns_mut(&app.accounts, &mut app.decks_cache),
|
||||||
app.accounts.get_selected_account().map(|a| &a.pubkey),
|
app.accounts.get_selected_account().map(|a| &a.pubkey),
|
||||||
nav.routes_arr(),
|
nav.routes_arr(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
column::Columns,
|
column::Columns,
|
||||||
|
decks::DecksCache,
|
||||||
error::{Error, FilterError},
|
error::{Error, FilterError},
|
||||||
filter::{self, FilterState, FilterStates},
|
filter::{self, FilterState, FilterStates},
|
||||||
muted::MuteFun,
|
muted::MuteFun,
|
||||||
@@ -601,12 +602,16 @@ pub fn copy_notes_into_timeline(
|
|||||||
pub fn setup_initial_nostrdb_subs(
|
pub fn setup_initial_nostrdb_subs(
|
||||||
ndb: &Ndb,
|
ndb: &Ndb,
|
||||||
note_cache: &mut NoteCache,
|
note_cache: &mut NoteCache,
|
||||||
columns: &mut Columns,
|
decks_cache: &mut DecksCache,
|
||||||
is_muted: &MuteFun,
|
is_muted: &MuteFun,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for timeline in columns.timelines_mut() {
|
for decks in decks_cache.account_to_decks.values_mut() {
|
||||||
if let Err(err) = setup_timeline_nostrdb_sub(ndb, note_cache, timeline, is_muted) {
|
for deck in decks.decks_mut() {
|
||||||
error!("setup_initial_nostrdb_subs: {err}");
|
for timeline in deck.columns_mut().timelines_mut() {
|
||||||
|
if let Err(err) = setup_timeline_nostrdb_sub(ndb, note_cache, timeline, is_muted) {
|
||||||
|
error!("setup_initial_nostrdb_subs: {err}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use crate::colors::PINK;
|
|||||||
use crate::imgcache::ImageCache;
|
use crate::imgcache::ImageCache;
|
||||||
use crate::{
|
use crate::{
|
||||||
accounts::Accounts,
|
accounts::Accounts,
|
||||||
route::{Route, Router},
|
|
||||||
ui::{Preview, PreviewConfig, View},
|
ui::{Preview, PreviewConfig, View},
|
||||||
Damus,
|
Damus,
|
||||||
};
|
};
|
||||||
@@ -203,15 +202,12 @@ mod preview {
|
|||||||
|
|
||||||
pub struct AccountsPreview {
|
pub struct AccountsPreview {
|
||||||
app: Damus,
|
app: Damus,
|
||||||
router: Router<Route>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AccountsPreview {
|
impl AccountsPreview {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let app = test_data::test_app();
|
let app = test_data::test_app();
|
||||||
let router = Router::new(vec![Route::accounts()]);
|
AccountsPreview { app }
|
||||||
|
|
||||||
AccountsPreview { app, router }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +220,12 @@ mod preview {
|
|||||||
.ui(ui)
|
.ui(ui)
|
||||||
.inner
|
.inner
|
||||||
{
|
{
|
||||||
process_accounts_view_response(self.app.accounts_mut(), response, &mut self.router);
|
process_accounts_view_response(
|
||||||
|
&mut self.app.accounts,
|
||||||
|
&mut self.app.decks_cache,
|
||||||
|
0,
|
||||||
|
response,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ use egui::{
|
|||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
accounts::AccountsRoute,
|
accounts::{Accounts, AccountsRoute},
|
||||||
|
app::get_active_columns_mut,
|
||||||
app_style, colors,
|
app_style, colors,
|
||||||
column::{Column, Columns},
|
column::Column,
|
||||||
|
decks::DecksCache,
|
||||||
imgcache::ImageCache,
|
imgcache::ImageCache,
|
||||||
route::Route,
|
route::Route,
|
||||||
support::Support,
|
support::Support,
|
||||||
@@ -27,6 +29,7 @@ pub struct DesktopSidePanel<'a> {
|
|||||||
ndb: &'a nostrdb::Ndb,
|
ndb: &'a nostrdb::Ndb,
|
||||||
img_cache: &'a mut ImageCache,
|
img_cache: &'a mut ImageCache,
|
||||||
selected_account: Option<&'a UserAccount>,
|
selected_account: Option<&'a UserAccount>,
|
||||||
|
decks_cache: &'a DecksCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl View for DesktopSidePanel<'_> {
|
impl View for DesktopSidePanel<'_> {
|
||||||
@@ -63,11 +66,13 @@ impl<'a> DesktopSidePanel<'a> {
|
|||||||
ndb: &'a nostrdb::Ndb,
|
ndb: &'a nostrdb::Ndb,
|
||||||
img_cache: &'a mut ImageCache,
|
img_cache: &'a mut ImageCache,
|
||||||
selected_account: Option<&'a UserAccount>,
|
selected_account: Option<&'a UserAccount>,
|
||||||
|
decks_cache: &'a DecksCache,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
ndb,
|
ndb,
|
||||||
img_cache,
|
img_cache,
|
||||||
selected_account,
|
selected_account,
|
||||||
|
decks_cache,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,8 +205,13 @@ impl<'a> DesktopSidePanel<'a> {
|
|||||||
helper.take_animation_response()
|
helper.take_animation_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn perform_action(columns: &mut Columns, support: &mut Support, action: SidePanelAction) {
|
pub fn perform_action(
|
||||||
let router = columns.get_first_router();
|
decks_cache: &mut DecksCache,
|
||||||
|
accounts: &Accounts,
|
||||||
|
support: &mut Support,
|
||||||
|
action: SidePanelAction,
|
||||||
|
) {
|
||||||
|
let router = get_active_columns_mut(accounts, decks_cache).get_first_router();
|
||||||
match action {
|
match action {
|
||||||
SidePanelAction::Panel => {} // TODO
|
SidePanelAction::Panel => {} // TODO
|
||||||
SidePanelAction::Account => {
|
SidePanelAction::Account => {
|
||||||
@@ -232,7 +242,7 @@ impl<'a> DesktopSidePanel<'a> {
|
|||||||
{
|
{
|
||||||
router.go_back();
|
router.go_back();
|
||||||
} else {
|
} else {
|
||||||
columns.new_column_picker();
|
get_active_columns_mut(accounts, decks_cache).new_column_picker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SidePanelAction::ComposeNote => {
|
SidePanelAction::ComposeNote => {
|
||||||
@@ -470,6 +480,7 @@ mod preview {
|
|||||||
use egui_extras::{Size, StripBuilder};
|
use egui_extras::{Size, StripBuilder};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
app::get_active_columns_mut,
|
||||||
test_data,
|
test_data,
|
||||||
ui::{Preview, PreviewConfig},
|
ui::{Preview, PreviewConfig},
|
||||||
};
|
};
|
||||||
@@ -483,7 +494,8 @@ mod preview {
|
|||||||
impl DesktopSidePanelPreview {
|
impl DesktopSidePanelPreview {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let mut app = test_data::test_app();
|
let mut app = test_data::test_app();
|
||||||
app.columns.add_column(Column::new(vec![Route::accounts()]));
|
get_active_columns_mut(&app.accounts, &mut app.decks_cache)
|
||||||
|
.add_column(Column::new(vec![Route::accounts()]));
|
||||||
DesktopSidePanelPreview { app }
|
DesktopSidePanelPreview { app }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -500,11 +512,13 @@ mod preview {
|
|||||||
&self.app.ndb,
|
&self.app.ndb,
|
||||||
&mut self.app.img_cache,
|
&mut self.app.img_cache,
|
||||||
self.app.accounts.get_selected_account(),
|
self.app.accounts.get_selected_account(),
|
||||||
|
&self.app.decks_cache,
|
||||||
);
|
);
|
||||||
let response = panel.show(ui);
|
let response = panel.show(ui);
|
||||||
|
|
||||||
DesktopSidePanel::perform_action(
|
DesktopSidePanel::perform_action(
|
||||||
&mut self.app.columns,
|
&mut self.app.decks_cache,
|
||||||
|
&self.app.accounts,
|
||||||
&mut self.app.support,
|
&mut self.app.support,
|
||||||
response.action,
|
response.action,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user