toolbar: process actions
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -9,7 +9,8 @@ use notedeck::{
|
|||||||
profile::get_profile_url, App, AppAction, AppContext, NotedeckTextStyle, UserAccount,
|
profile::get_profile_url, App, AppAction, AppContext, NotedeckTextStyle, UserAccount,
|
||||||
WalletType,
|
WalletType,
|
||||||
};
|
};
|
||||||
use notedeck_columns::Damus;
|
use notedeck_columns::{timeline::kind::ListKind, timeline::TimelineKind, Damus};
|
||||||
|
|
||||||
use notedeck_dave::{Dave, DaveAvatar};
|
use notedeck_dave::{Dave, DaveAvatar};
|
||||||
use notedeck_ui::{AnimationHelper, ProfilePic};
|
use notedeck_ui::{AnimationHelper, ProfilePic};
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ impl Default for Chrome {
|
|||||||
|
|
||||||
/// When you click the toolbar button, these actions
|
/// When you click the toolbar button, these actions
|
||||||
/// are returned
|
/// are returned
|
||||||
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub enum ToolbarAction {
|
pub enum ToolbarAction {
|
||||||
Notifications,
|
Notifications,
|
||||||
Dave,
|
Dave,
|
||||||
@@ -52,12 +54,23 @@ pub enum ChromePanelAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ChromePanelAction {
|
impl ChromePanelAction {
|
||||||
|
fn columns_switch(ctx: &AppContext, chrome: &mut Chrome, kind: &TimelineKind) {
|
||||||
|
chrome.switch_to_columns();
|
||||||
|
|
||||||
|
if let Some(active_columns) = chrome
|
||||||
|
.get_columns()
|
||||||
|
.and_then(|cols| cols.decks_cache.active_columns_mut(ctx.accounts))
|
||||||
|
{
|
||||||
|
active_columns.select_by_kind(kind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn columns_navigate(ctx: &AppContext, chrome: &mut Chrome, route: notedeck_columns::Route) {
|
fn columns_navigate(ctx: &AppContext, chrome: &mut Chrome, route: notedeck_columns::Route) {
|
||||||
chrome.switch_to_columns();
|
chrome.switch_to_columns();
|
||||||
|
|
||||||
if let Some(c) = chrome
|
if let Some(c) = chrome
|
||||||
.get_columns()
|
.get_columns()
|
||||||
.and_then(|columns| columns.decks_cache.first_column_mut(ctx.accounts))
|
.and_then(|columns| columns.decks_cache.selected_column_mut(ctx.accounts))
|
||||||
{
|
{
|
||||||
if c.router().routes().iter().any(|r| r == &route) {
|
if c.router().routes().iter().any(|r| r == &route) {
|
||||||
// return if we are already routing to accounts
|
// return if we are already routing to accounts
|
||||||
@@ -78,9 +91,33 @@ impl ChromePanelAction {
|
|||||||
ctx.theme.save(*theme);
|
ctx.theme.save(*theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
Self::Toolbar(_toolbar_action) => {
|
Self::Toolbar(toolbar_action) => match toolbar_action {
|
||||||
tracing::info!("toolbar action");
|
ToolbarAction::Dave => chrome.switch_to_dave(),
|
||||||
}
|
|
||||||
|
ToolbarAction::Home => {
|
||||||
|
if let Some(pubkey) = ctx
|
||||||
|
.accounts
|
||||||
|
.get_selected_account()
|
||||||
|
.map(|acc| acc.key.pubkey)
|
||||||
|
{
|
||||||
|
Self::columns_switch(
|
||||||
|
ctx,
|
||||||
|
chrome,
|
||||||
|
&TimelineKind::List(ListKind::Contact(pubkey)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolbarAction::Notifications => {
|
||||||
|
if let Some(pubkey) = ctx
|
||||||
|
.accounts
|
||||||
|
.get_selected_account()
|
||||||
|
.map(|acc| acc.key.pubkey)
|
||||||
|
{
|
||||||
|
Self::columns_switch(ctx, chrome, &TimelineKind::Notifications(pubkey));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
Self::Support => {
|
Self::Support => {
|
||||||
Self::columns_navigate(ctx, chrome, notedeck_columns::Route::Support);
|
Self::columns_navigate(ctx, chrome, notedeck_columns::Route::Support);
|
||||||
@@ -138,6 +175,14 @@ impl Chrome {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn switch_to_dave(&mut self) {
|
||||||
|
for (i, app) in self.apps.iter().enumerate() {
|
||||||
|
if let NotedeckApp::Dave(_) = app {
|
||||||
|
self.active = i as i32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn switch_to_columns(&mut self) {
|
fn switch_to_columns(&mut self) {
|
||||||
for (i, app) in self.apps.iter().enumerate() {
|
for (i, app) in self.apps.iter().enumerate() {
|
||||||
if let NotedeckApp::Columns(_) = app {
|
if let NotedeckApp::Columns(_) = app {
|
||||||
@@ -282,10 +327,8 @@ impl Chrome {
|
|||||||
action = Some(ToolbarAction::Dave);
|
action = Some(ToolbarAction::Dave);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if index == 2 {
|
} else if index == 2 && notifications_button(ui).clicked() {
|
||||||
if notifications_button(ui).clicked() {
|
action = Some(ToolbarAction::Notifications);
|
||||||
action = Some(ToolbarAction::Notifications);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
action
|
action
|
||||||
@@ -350,7 +393,7 @@ impl Chrome {
|
|||||||
let rect = dave_sidebar_rect(ui);
|
let rect = dave_sidebar_rect(ui);
|
||||||
let dave_resp = dave_button(dave.avatar_mut(), ui, rect);
|
let dave_resp = dave_button(dave.avatar_mut(), ui, rect);
|
||||||
if dave_resp.clicked() {
|
if dave_resp.clicked() {
|
||||||
self.active = 1;
|
self.switch_to_dave();
|
||||||
} else if dave_resp.hovered() {
|
} else if dave_resp.hovered() {
|
||||||
notedeck_ui::show_pointer(ui);
|
notedeck_ui::show_pointer(ui);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -534,9 +534,16 @@ fn render_damus_mobile(
|
|||||||
let mut rect = ui.available_rect_before_wrap();
|
let mut rect = ui.available_rect_before_wrap();
|
||||||
let mut app_action: Option<AppAction> = None;
|
let mut app_action: Option<AppAction> = None;
|
||||||
|
|
||||||
|
let active_col = app.columns_mut(app_ctx.accounts).selected as usize;
|
||||||
if !app.columns(app_ctx.accounts).columns().is_empty() {
|
if !app.columns(app_ctx.accounts).columns().is_empty() {
|
||||||
let r = nav::render_nav(0, ui.available_rect_before_wrap(), app, app_ctx, ui)
|
let r = nav::render_nav(
|
||||||
.process_render_nav_response(app, app_ctx, ui);
|
active_col,
|
||||||
|
ui.available_rect_before_wrap(),
|
||||||
|
app,
|
||||||
|
app_ctx,
|
||||||
|
ui,
|
||||||
|
)
|
||||||
|
.process_render_nav_response(app, app_ctx, ui);
|
||||||
if let Some(r) = &r {
|
if let Some(r) = &r {
|
||||||
match r {
|
match r {
|
||||||
ProcessNavResult::SwitchOccurred => {
|
ProcessNavResult::SwitchOccurred => {
|
||||||
@@ -563,7 +570,7 @@ fn render_damus_mobile(
|
|||||||
.clicked()
|
.clicked()
|
||||||
&& !app.columns(app_ctx.accounts).columns().is_empty()
|
&& !app.columns(app_ctx.accounts).columns().is_empty()
|
||||||
{
|
{
|
||||||
let router = app.columns_mut(app_ctx.accounts).columns_mut()[0].router_mut();
|
let router = app.columns_mut(app_ctx.accounts).selected().router_mut();
|
||||||
if router.top() == &Route::ComposeNote {
|
if router.top() == &Route::ComposeNote {
|
||||||
router.go_back();
|
router.go_back();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ pub struct Columns {
|
|||||||
columns: Vec<Column>,
|
columns: Vec<Column>,
|
||||||
|
|
||||||
/// The selected column for key navigation
|
/// The selected column for key navigation
|
||||||
selected: i32,
|
pub selected: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Columns {
|
impl Columns {
|
||||||
@@ -47,6 +47,35 @@ impl Columns {
|
|||||||
Columns::default()
|
Columns::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Choose which column is selected. If in narrow mode, this
|
||||||
|
/// decides which column to render in the main view
|
||||||
|
pub fn select_column(&mut self, index: i32) {
|
||||||
|
let len = self.columns.len();
|
||||||
|
|
||||||
|
if index < (len as i32) {
|
||||||
|
self.selected = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Select the column based on the timeline kind.
|
||||||
|
///
|
||||||
|
/// TODO: add timeline if missing?
|
||||||
|
pub fn select_by_kind(&mut self, kind: &TimelineKind) {
|
||||||
|
for (i, col) in self.columns.iter().enumerate() {
|
||||||
|
for route in col.router().routes() {
|
||||||
|
if let Some(timeline) = route.timeline_id() {
|
||||||
|
if timeline == kind {
|
||||||
|
tracing::info!("selecting {kind:?} column");
|
||||||
|
self.select_column(i as i32);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tracing::error!("failed to select {kind:?} column");
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_new_timeline_column(
|
pub fn add_new_timeline_column(
|
||||||
&mut self,
|
&mut self,
|
||||||
timeline_cache: &mut TimelineCache,
|
timeline_cache: &mut TimelineCache,
|
||||||
|
|||||||
@@ -37,9 +37,8 @@ impl Default for DecksCache {
|
|||||||
|
|
||||||
impl DecksCache {
|
impl DecksCache {
|
||||||
/// Gets the first column in the currently active user's active deck
|
/// 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> {
|
pub fn selected_column_mut(&mut self, accounts: ¬edeck::Accounts) -> Option<&mut Column> {
|
||||||
self.active_columns_mut(accounts)
|
self.active_columns_mut(accounts).map(|ad| ad.selected())
|
||||||
.and_then(|ad| ad.columns_mut().first_mut())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the active columns
|
/// Gets the active columns
|
||||||
|
|||||||
Reference in New Issue
Block a user