From 731f206424f4cff6d9243fea97e89ab30949589d Mon Sep 17 00:00:00 2001 From: kernelkind Date: Wed, 25 Sep 2024 21:32:08 -0400 Subject: [PATCH] basic add column impl Signed-off-by: kernelkind --- src/nav.rs | 24 +++++++++++++++++++----- src/route.rs | 3 +++ src/timeline/route.rs | 14 ++++++++------ src/ui/add_column.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ src/ui/mod.rs | 1 + src/ui/side_panel.rs | 7 +++++-- 6 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 src/ui/add_column.rs diff --git a/src/nav.rs b/src/nav.rs index a0f3983..26409e9 100644 --- a/src/nav.rs +++ b/src/nav.rs @@ -3,8 +3,10 @@ use crate::{ relay_pool_manager::RelayPoolManager, route::Route, thread::thread_unsubscribe, - timeline::route::{render_timeline_route, TimelineRoute, TimelineRouteResponse}, - ui::{self, note::PostAction, RelayView, View}, + timeline::route::{render_timeline_route, AfterRouteExecution, TimelineRoute}, + ui::{ + self, add_column::{AddColumnResponse, AddColumnView}, note::PostAction, RelayView, View + }, Damus, }; @@ -73,12 +75,15 @@ pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) { None } + Route::AddColumn => AddColumnView::new(app.accounts.get_selected_account()) + .ui(ui) + .map(AfterRouteExecution::AddColumn), }); - if let Some(reply_response) = nav_response.inner { + if let Some(after_route_execution) = nav_response.inner { // start returning when we're finished posting - match reply_response { - TimelineRouteResponse::Post(resp) => { + match after_route_execution { + AfterRouteExecution::Post(resp) => { if let Some(action) = resp.action { match action { PostAction::Post(_) => { @@ -87,6 +92,15 @@ 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.columns_mut().add_timeline(timeline); + } + }; + app.columns_mut().column_mut(col).router_mut().go_back(); + } } } diff --git a/src/route.rs b/src/route.rs index f9c3736..2f46923 100644 --- a/src/route.rs +++ b/src/route.rs @@ -13,6 +13,7 @@ pub enum Route { Accounts(AccountsRoute), Relays, ComposeNote, + AddColumn, } impl Route { @@ -125,6 +126,8 @@ impl fmt::Display for Route { AccountsRoute::AddAccount => write!(f, "Add Account"), }, Route::ComposeNote => write!(f, "Compose Note"), + + Route::AddColumn => write!(f, "Add Column"), } } } diff --git a/src/timeline/route.rs b/src/timeline/route.rs index 941002e..1125b0d 100644 --- a/src/timeline/route.rs +++ b/src/timeline/route.rs @@ -8,6 +8,7 @@ use crate::{ timeline::TimelineId, ui::{ self, + add_column::AddColumnResponse, note::{ post::{PostAction, PostResponse}, QuoteRepostView, @@ -26,13 +27,14 @@ pub enum TimelineRoute { Quote(NoteId), } -pub enum TimelineRouteResponse { +pub enum AfterRouteExecution { Post(PostResponse), + AddColumn(AddColumnResponse), } -impl TimelineRouteResponse { +impl AfterRouteExecution { pub fn post(post: PostResponse) -> Self { - TimelineRouteResponse::Post(post) + AfterRouteExecution::Post(post) } } @@ -50,7 +52,7 @@ pub fn render_timeline_route( col: usize, textmode: bool, ui: &mut egui::Ui, -) -> Option { +) -> Option { match route { TimelineRoute::Timeline(timeline_id) => { if let Some(bar_action) = @@ -111,7 +113,7 @@ pub fn render_timeline_route( }); } - Some(TimelineRouteResponse::post(response.inner)) + Some(AfterRouteExecution::post(response.inner)) } TimelineRoute::Quote(id) => { @@ -140,7 +142,7 @@ pub fn render_timeline_route( np.to_quote(seckey, ¬e) }); } - Some(TimelineRouteResponse::post(response.inner)) + Some(AfterRouteExecution::post(response.inner)) } } } diff --git a/src/ui/add_column.rs b/src/ui/add_column.rs new file mode 100644 index 0000000..a174f95 --- /dev/null +++ b/src/ui/add_column.rs @@ -0,0 +1,43 @@ +use egui::{RichText, Ui}; +use nostrdb::FilterBuilder; + +use crate::{app_style::NotedeckTextStyle, timeline::Timeline, user_account::UserAccount}; + +pub enum AddColumnResponse { + Timeline(Timeline), +} + +pub struct AddColumnView<'a> { + cur_account: Option<&'a UserAccount>, +} + +impl<'a> AddColumnView<'a> { + pub fn new(cur_account: Option<&'a UserAccount>) -> Self { + Self { cur_account } + } + + pub fn ui(&mut self, ui: &mut Ui) -> Option { + ui.label(RichText::new("Add column").text_style(NotedeckTextStyle::Heading.text_style())); + + if ui.button("create global timeline").clicked() { + Some(AddColumnResponse::Timeline(create_global_timeline())) + } else { + None + } + } +} + +fn create_global_timeline() -> Timeline { + let filter = FilterBuilder::new().kinds([1]).build(); + Timeline::new( + crate::timeline::TimelineKind::Generic, + crate::filter::FilterState::Ready(vec![filter]), + ) +} + +// struct ColumnOption { +// title: &'static str, +// description: &'static str, +// icon: Box::, +// route: Route, +// } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index ac35e1c..08f239b 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1,5 +1,6 @@ pub mod account_login_view; pub mod account_management; +pub mod add_column; pub mod anim; pub mod mention; pub mod note; diff --git a/src/ui/side_panel.rs b/src/ui/side_panel.rs index cf93ff1..b964059 100644 --- a/src/ui/side_panel.rs +++ b/src/ui/side_panel.rs @@ -186,8 +186,11 @@ impl<'a> DesktopSidePanel<'a> { } } SidePanelAction::Columns => { - // TODO - info!("Clicked columns button"); + if router.routes().iter().any(|&r| r == Route::AddColumn) { + router.go_back(); + } else { + router.route_to(Route::AddColumn); + } } SidePanelAction::ComposeNote => { if router.routes().iter().any(|&r| r == Route::ComposeNote) {