mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-01-23 18:24:19 +01:00
24
src/nav.rs
24
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<TimelineRouteResponse> {
|
||||
) -> Option<AfterRouteExecution> {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
43
src/ui/add_column.rs
Normal file
43
src/ui/add_column.rs
Normal file
@@ -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<AddColumnResponse> {
|
||||
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::<dyn Widget>,
|
||||
// route: Route,
|
||||
// }
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user