reintroduce account management

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2024-06-23 19:46:58 -04:00
parent ac0821db79
commit 6afb618089
9 changed files with 181 additions and 21 deletions

View File

@@ -5,7 +5,7 @@ use crate::{
ui::{profile_preview_controller, Preview, PreviewConfig, View},
Damus,
};
use egui::{Align, Button, Frame, Image, Layout, RichText, ScrollArea, Vec2};
use egui::{Align, Button, Frame, Image, Layout, Response, RichText, ScrollArea, Vec2};
use super::profile::preview::SimpleProfilePreview;
use super::profile::ProfilePreviewOp;
@@ -13,14 +13,26 @@ use super::profile::ProfilePreviewOp;
pub struct AccountManagementView {}
impl AccountManagementView {
fn show(app: &mut Damus, ui: &mut egui::Ui) {
Frame::none().outer_margin(24.0).show(ui, |ui| {
Self::top_section_buttons_widget(ui);
ui.add_space(8.0);
scroll_area().show(ui, |ui| {
Self::show_accounts(app, ui);
});
});
pub fn ui(app: &mut Damus, ui: &mut egui::Ui) -> Option<Response> {
if app.is_mobile() {
AccountManagementView::show_mobile(app, ui);
None
} else {
Some(AccountManagementView::show(app, ui))
}
}
fn show(app: &mut Damus, ui: &mut egui::Ui) -> Response {
Frame::none()
.outer_margin(24.0)
.show(ui, |ui| {
Self::top_section_buttons_widget(ui);
ui.add_space(8.0);
scroll_area().show(ui, |ui| {
Self::show_accounts(app, ui);
});
})
.response
}
fn show_accounts(app: &mut Damus, ui: &mut egui::Ui) {

View File

@@ -1,5 +1,5 @@
use crate::{
account_manager::UserAccount, colors::PINK, profile::DisplayName,
account_manager::UserAccount, colors::PINK, profile::DisplayName, route::Route,
ui::profile_preview_controller, Damus, Result,
};
@@ -27,6 +27,10 @@ struct AccountSelectResponse {
impl AccountSelectionWidget {
pub fn ui(app: &mut Damus, ui: &mut egui::Ui) {
if !app.show_account_switcher {
return;
}
if app.is_mobile() {
Self::show_mobile(ui);
} else {
@@ -54,7 +58,8 @@ impl AccountSelectionWidget {
}
AccountSelectAction::OpenAccountManagement => {
app.show_account_switcher = false;
// TODO: push account management to global popup router
app.global_nav.push(Route::ManageAccount);
app.show_global_popup = true;
}
}
}

53
src/ui/global_popup.rs Normal file
View File

@@ -0,0 +1,53 @@
use std::{cell::RefCell, rc::Rc};
use egui::Sense;
use egui_nav::{Nav, NavAction};
use crate::{
fixed_window::{FixedWindow, FixedWindowResponse},
route::Route,
Damus,
};
static MARGIN: f32 = 100.0;
pub struct DesktopGlobalPopup {}
impl DesktopGlobalPopup {
pub fn show(routes: Vec<Route>, app: &mut Damus, ui: &mut egui::Ui) {
if routes.is_empty() || !app.show_global_popup {
return;
}
let rect = ui.ctx().screen_rect().shrink(MARGIN);
let title = if let Some(first) = routes.first() {
// TODO(kernelkind): not a great way of getting the title of the routes 'grouping'
Some(first.title())
} else {
None
};
let app_ctx = Rc::new(RefCell::new(app));
let resp = FixedWindow::maybe_with_title(title).show(ui, rect, |ui| {
let nav_response = Nav::new(routes).navigating(false).show(ui, |ui, nav| {
if let Some(resp) = nav.top().show_global_popup(&mut app_ctx.borrow_mut(), ui) {
ui.allocate_rect(resp.rect, Sense::hover())
} else {
ui.label("") // TODO(kernelkind): not a great practice
}
});
if let Some(NavAction::Returned) = nav_response.action {
app_ctx.borrow_mut().global_nav.pop();
}
nav_response.inner
});
if resp == FixedWindowResponse::Closed {
app_ctx.borrow_mut().global_nav.pop();
app_ctx.borrow_mut().show_global_popup = false;
}
}
}

View File

@@ -2,6 +2,7 @@ pub mod account_login_view;
pub mod account_management;
pub mod account_switcher;
pub mod anim;
pub mod global_popup;
pub mod mention;
pub mod note;
pub mod preview;
@@ -12,6 +13,7 @@ pub mod username;
pub use account_management::AccountManagementView;
pub use account_switcher::AccountSelectionWidget;
pub use global_popup::DesktopGlobalPopup;
pub use mention::Mention;
pub use note::{BarAction, Note, NoteResponse, PostView};
pub use preview::{Preview, PreviewApp, PreviewConfig};

View File

@@ -127,7 +127,7 @@ mod preview {
use crate::{
test_data,
ui::{AccountSelectionWidget, Preview, PreviewConfig},
ui::{AccountSelectionWidget, DesktopGlobalPopup, Preview, PreviewConfig},
};
use super::*;
@@ -157,9 +157,8 @@ mod preview {
});
});
if self.app.show_account_switcher {
AccountSelectionWidget::ui(&mut self.app, ui);
}
AccountSelectionWidget::ui(&mut self.app, ui);
DesktopGlobalPopup::show(self.app.global_nav.clone(), &mut self.app, ui);
}
}