Skip to content

Commit

Permalink
add functionality to add account buttons
Browse files Browse the repository at this point in the history
Signed-off-by: kernelkind <[email protected]>
  • Loading branch information
kernelkind committed Jul 4, 2024
1 parent d265d48 commit 793b6d7
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 223 deletions.
8 changes: 8 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::error::Error;
use crate::frame_history::FrameHistory;
use crate::imgcache::ImageCache;
use crate::key_storage::KeyStorageType;
use crate::login_manager::LoginManager;
use crate::notecache::{CachedNote, NoteCache};
use crate::relay_pool_manager::RelayPoolManager;
use crate::route::Route;
Expand Down Expand Up @@ -57,6 +58,7 @@ pub struct Damus {
pub img_cache: ImageCache,
pub ndb: Ndb,
pub account_manager: AccountManager,
pub login_manager: LoginManager,

frame_history: crate::frame_history::FrameHistory,
pub show_account_switcher: bool,
Expand Down Expand Up @@ -788,6 +790,8 @@ impl Damus {
account_manager.select_account(0);
}

let login_manager = LoginManager::new();

Self {
is_mobile,
drafts: Drafts::default(),
Expand All @@ -800,6 +804,7 @@ impl Damus {
textmode: false,
ndb: Ndb::new(data_path.as_ref().to_str().expect("db path ok"), &config).expect("ndb"),
account_manager,
login_manager,
//compose: "".to_string(),
frame_history: FrameHistory::default(),
show_account_switcher: false,
Expand Down Expand Up @@ -830,6 +835,7 @@ impl Damus {
textmode: false,
ndb: Ndb::new(data_path.as_ref().to_str().expect("db path ok"), &config).expect("ndb"),
account_manager: AccountManager::new(None, determine_key_storage_type()),
login_manager: LoginManager::new(),
frame_history: FrameHistory::default(),
show_account_switcher: false,
show_global_popup: true,
Expand Down Expand Up @@ -984,6 +990,8 @@ fn render_nav(routes: Vec<Route>, timeline_ind: usize, app: &mut Damus, ui: &mut
None
}

Route::AddAccount => None,

Route::Thread(_key) => {
ui.label("thread view");
None
Expand Down
26 changes: 24 additions & 2 deletions src/route.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
use egui::{Response, RichText};
use egui::{Response, RichText, Vec2};
use enostr::NoteId;
use std::fmt::{self};

use crate::{ui::AccountManagementView, Damus};
use crate::{
app_style::NotedeckTextStyle,
ui::{account_login_view::AccountLoginView, AccountManagementView},
Damus,
};

/// App routing. These describe different places you can go inside Notedeck.
#[derive(Clone, Debug)]
pub enum Route {
Timeline(String),
ManageAccount,
AddAccount,
Thread(NoteId),
Reply(NoteId),
Relays,
Expand All @@ -18,6 +23,7 @@ impl fmt::Display for Route {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Route::ManageAccount => write!(f, "Manage Account"),
Route::AddAccount => write!(f, "Add Account"),
Route::Timeline(name) => write!(f, "{}", name),
Route::Thread(_id) => write!(f, "Thread"),
Route::Reply(_id) => write!(f, "Reply"),
Expand All @@ -30,13 +36,29 @@ impl Route {
pub fn show_global_popup(&self, app: &mut Damus, ui: &mut egui::Ui) -> Option<Response> {
match self {
Route::ManageAccount => AccountManagementView::ui(app, ui),
Route::AddAccount => Some(AccountLoginView::ui(app, ui)),
_ => None,
}
}

pub fn preferred_rect(&self, ui: &mut egui::Ui) -> egui::Rect {
let screen_rect = ui.ctx().screen_rect();
match self {
Route::ManageAccount => screen_rect.shrink(200.0),
Route::AddAccount => {
let size = Vec2::new(560.0, 480.0);
egui::Rect::from_center_size(screen_rect.center(), size)
}
_ => screen_rect,
}
}

pub fn title(&self) -> RichText {
match self {
Route::ManageAccount => RichText::new("Manage Account").size(24.0),
Route::AddAccount => RichText::new("Login")
.text_style(NotedeckTextStyle::Heading2.text_style())
.strong(),
Route::Thread(_) => RichText::new("Thread"),
Route::Reply(_) => RichText::new("Reply"),
Route::Relays => RichText::new("Relays"),
Expand Down
Loading

0 comments on commit 793b6d7

Please sign in to comment.