chrome: fix settings view
restore some chrome panel actions Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -6,6 +6,7 @@ use egui::{vec2, Button, Label, Layout, RichText, ThemePreference, Widget};
|
||||
use egui_extras::{Size, StripBuilder};
|
||||
use nostrdb::{ProfileRecord, Transaction};
|
||||
use notedeck::{App, AppContext, NotedeckTextStyle, UserAccount};
|
||||
use notedeck_columns::Damus;
|
||||
use notedeck_dave::{Dave, DaveAvatar};
|
||||
use notedeck_ui::{profile::get_profile_url, AnimationHelper, ProfilePic};
|
||||
|
||||
@@ -26,7 +27,7 @@ pub enum ChromePanelAction {
|
||||
}
|
||||
|
||||
impl ChromePanelAction {
|
||||
fn process(&self, ui: &mut egui::Ui) {
|
||||
fn process(&self, ctx: &AppContext, chrome: &mut Chrome, ui: &mut egui::Ui) {
|
||||
match self {
|
||||
Self::SaveTheme(theme) => {
|
||||
tracing::info!("Switching theme to {:?}", theme);
|
||||
@@ -47,6 +48,23 @@ impl ChromePanelAction {
|
||||
|
||||
Self::Settings => {
|
||||
tracing::info!("Settings view selected");
|
||||
chrome.switch_to_columns();
|
||||
if let Some(c) = chrome
|
||||
.get_columns()
|
||||
.and_then(|columns| columns.decks_cache.first_column_mut(ctx.accounts))
|
||||
{
|
||||
if c.router()
|
||||
.routes()
|
||||
.iter()
|
||||
.any(|r| r == ¬edeck_columns::Route::Relays)
|
||||
{
|
||||
// return if we are already routing to accounts
|
||||
//router.go_back();
|
||||
} else {
|
||||
c.router_mut().route_to(notedeck_columns::Route::relays());
|
||||
//c..route_to(Route::relays());
|
||||
}
|
||||
};
|
||||
// open account
|
||||
}
|
||||
}
|
||||
@@ -62,6 +80,16 @@ impl Chrome {
|
||||
self.apps.push(app);
|
||||
}
|
||||
|
||||
fn get_columns(&mut self) -> Option<&mut Damus> {
|
||||
for app in &mut self.apps {
|
||||
if let NotedeckApp::Columns(cols) = app {
|
||||
return Some(cols);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn get_dave(&mut self) -> Option<&mut Dave> {
|
||||
for app in &mut self.apps {
|
||||
if let NotedeckApp::Dave(dave) = app {
|
||||
@@ -72,6 +100,14 @@ impl Chrome {
|
||||
None
|
||||
}
|
||||
|
||||
fn switch_to_columns(&mut self) {
|
||||
for (i, app) in self.apps.iter().enumerate() {
|
||||
if let NotedeckApp::Columns(_) = app {
|
||||
self.active = i as i32;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_active(&mut self, app: i32) {
|
||||
self.active = app;
|
||||
}
|
||||
@@ -236,6 +272,7 @@ impl Chrome {
|
||||
self.active = 0;
|
||||
}
|
||||
ui.add_space(32.0);
|
||||
|
||||
if let Some(dave) = self.get_dave() {
|
||||
if dave_button(dave.avatar_mut(), ui).clicked() {
|
||||
self.active = 1;
|
||||
@@ -247,7 +284,7 @@ impl Chrome {
|
||||
impl notedeck::App for Chrome {
|
||||
fn update(&mut self, ctx: &mut notedeck::AppContext, ui: &mut egui::Ui) {
|
||||
if let Some(action) = self.show(ctx, ui) {
|
||||
action.process(ui);
|
||||
action.process(ctx, self, ui);
|
||||
}
|
||||
// TODO: unify this constant with the columns side panel width. ui crate?
|
||||
}
|
||||
|
||||
@@ -36,6 +36,17 @@ impl Default for DecksCache {
|
||||
}
|
||||
|
||||
impl DecksCache {
|
||||
/// Gets the first column in the currently active user's active deck
|
||||
pub fn first_column_mut(&mut self, accounts: ¬edeck::Accounts) -> Option<&mut Column> {
|
||||
let Some(account) = accounts.get_selected_account() else {
|
||||
return None;
|
||||
};
|
||||
|
||||
self.decks_mut(&account.key.pubkey)
|
||||
.active_deck_mut()
|
||||
.and_then(|ad| ad.columns_mut().columns_mut().first_mut())
|
||||
}
|
||||
|
||||
pub fn new(mut account_to_decks: HashMap<Pubkey, Decks>) -> Self {
|
||||
let fallback_pubkey = FALLBACK_PUBKEY();
|
||||
account_to_decks.entry(fallback_pubkey).or_default();
|
||||
@@ -179,6 +190,19 @@ impl Decks {
|
||||
&self.decks
|
||||
}
|
||||
|
||||
pub fn active_deck_mut(&mut self) -> Option<&mut Deck> {
|
||||
if self.decks.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let active = self.active_index();
|
||||
if active > (self.decks.len() - 1) {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(&mut self.decks[active])
|
||||
}
|
||||
|
||||
pub fn decks_mut(&mut self) -> &mut Vec<Deck> {
|
||||
&mut self.decks
|
||||
}
|
||||
|
||||
@@ -41,5 +41,6 @@ pub mod storage;
|
||||
pub use app::Damus;
|
||||
pub use error::Error;
|
||||
pub use profile::NostrName;
|
||||
pub use route::Route;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, error::Error>;
|
||||
|
||||
Reference in New Issue
Block a user