push column picker immediately to new column
instead of pushing to temporary column first Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
27
src/app.rs
27
src/app.rs
@@ -3,7 +3,7 @@ use crate::{
|
|||||||
app_creation::setup_cc,
|
app_creation::setup_cc,
|
||||||
app_style::user_requested_visuals_change,
|
app_style::user_requested_visuals_change,
|
||||||
args::Args,
|
args::Args,
|
||||||
column::{Column, Columns},
|
column::Columns,
|
||||||
draft::Drafts,
|
draft::Drafts,
|
||||||
error::{Error, FilterError},
|
error::{Error, FilterError},
|
||||||
filter::{self, FilterState},
|
filter::{self, FilterState},
|
||||||
@@ -13,7 +13,6 @@ use crate::{
|
|||||||
nav,
|
nav,
|
||||||
note::NoteRef,
|
note::NoteRef,
|
||||||
notecache::{CachedNote, NoteCache},
|
notecache::{CachedNote, NoteCache},
|
||||||
route::Route,
|
|
||||||
subscriptions::{SubKind, Subscriptions},
|
subscriptions::{SubKind, Subscriptions},
|
||||||
thread::Threads,
|
thread::Threads,
|
||||||
timeline::{Timeline, TimelineId, TimelineKind, ViewFilter},
|
timeline::{Timeline, TimelineId, TimelineKind, ViewFilter},
|
||||||
@@ -699,11 +698,7 @@ impl Damus {
|
|||||||
let debug = parsed_args.debug;
|
let debug = parsed_args.debug;
|
||||||
|
|
||||||
if columns.columns().is_empty() {
|
if columns.columns().is_empty() {
|
||||||
let filter = Filter::from_json(include_str!("../queries/timeline.json")).unwrap();
|
columns.new_column_picker();
|
||||||
columns.add_timeline(Timeline::new(
|
|
||||||
TimelineKind::Generic,
|
|
||||||
FilterState::ready(vec![filter]),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@@ -770,7 +765,7 @@ impl Damus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_new_timeline(&mut self, timeline_id: TimelineId) {
|
pub fn subscribe_new_timeline(&mut self, timeline_id: TimelineId) {
|
||||||
self.state = DamusState::NewTimelineSub(timeline_id);
|
self.state = DamusState::NewTimelineSub(timeline_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -993,22 +988,8 @@ fn timelines_view(ui: &mut egui::Ui, sizes: Size, app: &mut Damus, columns: usiz
|
|||||||
)
|
)
|
||||||
.show(ui);
|
.show(ui);
|
||||||
|
|
||||||
let router = if let Some(router) = app
|
|
||||||
.columns
|
|
||||||
.columns_mut()
|
|
||||||
.get_mut(0)
|
|
||||||
.map(|c: &mut Column| c.router_mut())
|
|
||||||
{
|
|
||||||
router
|
|
||||||
} else {
|
|
||||||
// TODO(jb55): Maybe we should have an empty column route?
|
|
||||||
let columns = app.columns.columns_mut();
|
|
||||||
columns.push(Column::new(vec![Route::accounts()]));
|
|
||||||
columns[0].router_mut()
|
|
||||||
};
|
|
||||||
|
|
||||||
if side_panel.response.clicked() {
|
if side_panel.response.clicked() {
|
||||||
DesktopSidePanel::perform_action(router, side_panel.action);
|
DesktopSidePanel::perform_action(app.columns_mut(), side_panel.action);
|
||||||
}
|
}
|
||||||
|
|
||||||
// vertical sidebar line
|
// vertical sidebar line
|
||||||
|
|||||||
@@ -47,6 +47,22 @@ impl Columns {
|
|||||||
self.columns.push(Column::new(routes))
|
self.columns.push(Column::new(routes))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_timeline_to_column(&mut self, col: usize, timeline: Timeline) -> bool {
|
||||||
|
if let Some(column) = self.columns.get_mut(col) {
|
||||||
|
column
|
||||||
|
.router_mut()
|
||||||
|
.route_to_replaced(Route::timeline(timeline.id));
|
||||||
|
self.timelines.push(timeline);
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_column_picker(&mut self) {
|
||||||
|
self.columns.push(Column::new(vec![Route::AddColumn]));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn columns_mut(&mut self) -> &mut Vec<Column> {
|
pub fn columns_mut(&mut self) -> &mut Vec<Column> {
|
||||||
&mut self.columns
|
&mut self.columns
|
||||||
}
|
}
|
||||||
|
|||||||
34
src/nav.rs
34
src/nav.rs
@@ -78,9 +78,21 @@ pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) {
|
|||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
Route::AddColumn => AddColumnView::new(&app.ndb, app.accounts.get_selected_account())
|
Route::AddColumn => {
|
||||||
.ui(ui)
|
let resp = AddColumnView::new(&app.ndb, app.accounts.get_selected_account()).ui(ui);
|
||||||
.map(AfterRouteExecution::AddColumn),
|
|
||||||
|
if let Some(resp) = resp {
|
||||||
|
match resp {
|
||||||
|
AddColumnResponse::Timeline(timeline) => {
|
||||||
|
let id = timeline.id;
|
||||||
|
if app.columns_mut().add_timeline_to_column(col, timeline) {
|
||||||
|
app.subscribe_new_timeline(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(after_route_execution) = nav_response.inner {
|
if let Some(after_route_execution) = nav_response.inner {
|
||||||
@@ -95,16 +107,6 @@ pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterRouteExecution::AddColumn(add_column_resp) => {
|
|
||||||
match add_column_resp {
|
|
||||||
AddColumnResponse::Timeline(timeline) => {
|
|
||||||
app.add_new_timeline(timeline.id);
|
|
||||||
app.columns_mut().add_timeline(timeline);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
app.columns_mut().column_mut(col).router_mut().go_back();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +122,10 @@ pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if let Some(NavAction::Navigated) = nav_response.action {
|
} else if let Some(NavAction::Navigated) = nav_response.action {
|
||||||
app.columns_mut().column_mut(col).router_mut().navigating = false;
|
let cur_router = app.columns_mut().column_mut(col).router_mut();
|
||||||
|
cur_router.navigating = false;
|
||||||
|
if cur_router.is_replacing() {
|
||||||
|
cur_router.remove_previous_route();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
src/route.rs
24
src/route.rs
@@ -61,6 +61,7 @@ pub struct Router<R: Clone> {
|
|||||||
routes: Vec<R>,
|
routes: Vec<R>,
|
||||||
pub returning: bool,
|
pub returning: bool,
|
||||||
pub navigating: bool,
|
pub navigating: bool,
|
||||||
|
replacing: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: Clone> Router<R> {
|
impl<R: Clone> Router<R> {
|
||||||
@@ -70,10 +71,12 @@ impl<R: Clone> Router<R> {
|
|||||||
}
|
}
|
||||||
let returning = false;
|
let returning = false;
|
||||||
let navigating = false;
|
let navigating = false;
|
||||||
|
let replacing = false;
|
||||||
Router {
|
Router {
|
||||||
routes,
|
routes,
|
||||||
returning,
|
returning,
|
||||||
navigating,
|
navigating,
|
||||||
|
replacing,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +85,13 @@ impl<R: Clone> Router<R> {
|
|||||||
self.routes.push(route);
|
self.routes.push(route);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Route to R. Then when it is successfully placed, should call `remove_previous_route`
|
||||||
|
pub fn route_to_replaced(&mut self, route: R) {
|
||||||
|
self.navigating = true;
|
||||||
|
self.replacing = true;
|
||||||
|
self.routes.push(route);
|
||||||
|
}
|
||||||
|
|
||||||
/// Go back, start the returning process
|
/// Go back, start the returning process
|
||||||
pub fn go_back(&mut self) -> Option<R> {
|
pub fn go_back(&mut self) -> Option<R> {
|
||||||
if self.returning || self.routes.len() == 1 {
|
if self.returning || self.routes.len() == 1 {
|
||||||
@@ -100,6 +110,20 @@ impl<R: Clone> Router<R> {
|
|||||||
self.routes.pop()
|
self.routes.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn remove_previous_route(&mut self) -> Option<R> {
|
||||||
|
let num_routes = self.routes.len();
|
||||||
|
if num_routes <= 1 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
self.returning = false;
|
||||||
|
self.replacing = false;
|
||||||
|
Some(self.routes.remove(num_routes - 2))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_replacing(&self) -> bool {
|
||||||
|
self.replacing
|
||||||
|
}
|
||||||
|
|
||||||
pub fn top(&self) -> &R {
|
pub fn top(&self) -> &R {
|
||||||
self.routes.last().expect("routes can't be empty")
|
self.routes.last().expect("routes can't be empty")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use crate::{
|
|||||||
timeline::TimelineId,
|
timeline::TimelineId,
|
||||||
ui::{
|
ui::{
|
||||||
self,
|
self,
|
||||||
add_column::AddColumnResponse,
|
|
||||||
note::{
|
note::{
|
||||||
post::{PostAction, PostResponse},
|
post::{PostAction, PostResponse},
|
||||||
QuoteRepostView,
|
QuoteRepostView,
|
||||||
@@ -29,7 +28,6 @@ pub enum TimelineRoute {
|
|||||||
|
|
||||||
pub enum AfterRouteExecution {
|
pub enum AfterRouteExecution {
|
||||||
Post(PostResponse),
|
Post(PostResponse),
|
||||||
AddColumn(AddColumnResponse),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AfterRouteExecution {
|
impl AfterRouteExecution {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use tracing::info;
|
|||||||
use crate::{
|
use crate::{
|
||||||
account_manager::AccountsRoute,
|
account_manager::AccountsRoute,
|
||||||
colors,
|
colors,
|
||||||
column::Column,
|
column::{Column, Columns},
|
||||||
imgcache::ImageCache,
|
imgcache::ImageCache,
|
||||||
route::{Route, Router},
|
route::{Route, Router},
|
||||||
user_account::UserAccount,
|
user_account::UserAccount,
|
||||||
@@ -162,7 +162,8 @@ impl<'a> DesktopSidePanel<'a> {
|
|||||||
helper.take_animation_response()
|
helper.take_animation_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn perform_action(router: &mut Router<Route>, action: SidePanelAction) {
|
pub fn perform_action(columns: &mut Columns, action: SidePanelAction) {
|
||||||
|
let router = get_first_router(columns);
|
||||||
match action {
|
match action {
|
||||||
SidePanelAction::Panel => {} // TODO
|
SidePanelAction::Panel => {} // TODO
|
||||||
SidePanelAction::Account => {
|
SidePanelAction::Account => {
|
||||||
@@ -189,7 +190,7 @@ impl<'a> DesktopSidePanel<'a> {
|
|||||||
if router.routes().iter().any(|&r| r == Route::AddColumn) {
|
if router.routes().iter().any(|&r| r == Route::AddColumn) {
|
||||||
router.go_back();
|
router.go_back();
|
||||||
} else {
|
} else {
|
||||||
router.route_to(Route::AddColumn);
|
columns.new_column_picker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SidePanelAction::ComposeNote => {
|
SidePanelAction::ComposeNote => {
|
||||||
@@ -233,6 +234,17 @@ fn settings_button(dark_mode: bool) -> impl Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_first_router(columns: &mut Columns) -> &mut Router<Route> {
|
||||||
|
if columns.columns().is_empty() {
|
||||||
|
columns.new_column_picker();
|
||||||
|
}
|
||||||
|
columns
|
||||||
|
.columns_mut()
|
||||||
|
.get_mut(0)
|
||||||
|
.expect("There should be at least one column")
|
||||||
|
.router_mut()
|
||||||
|
}
|
||||||
|
|
||||||
fn add_column_button(dark_mode: bool) -> impl Widget {
|
fn add_column_button(dark_mode: bool) -> impl Widget {
|
||||||
let _ = dark_mode;
|
let _ = dark_mode;
|
||||||
move |ui: &mut egui::Ui| {
|
move |ui: &mut egui::Ui| {
|
||||||
@@ -391,10 +403,7 @@ mod preview {
|
|||||||
);
|
);
|
||||||
let response = panel.show(ui);
|
let response = panel.show(ui);
|
||||||
|
|
||||||
DesktopSidePanel::perform_action(
|
DesktopSidePanel::perform_action(&mut self.app.columns, response.action);
|
||||||
self.app.columns.columns_mut()[0].router_mut(),
|
|
||||||
response.action,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user