mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-01-15 22:34:19 +01:00
refactor: rename AccountsManager to Accounts
plz stop with the managers
This commit is contained in:
@@ -2,7 +2,6 @@ use std::cmp::Ordering;
|
||||
|
||||
use enostr::{FilledKeypair, FullKeypair, Keypair};
|
||||
use nostrdb::Ndb;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
column::Columns,
|
||||
@@ -12,34 +11,25 @@ use crate::{
|
||||
storage::{KeyStorageResponse, KeyStorageType},
|
||||
ui::{
|
||||
account_login_view::{AccountLoginResponse, AccountLoginView},
|
||||
account_management::{AccountsView, AccountsViewResponse},
|
||||
accounts::{AccountsView, AccountsViewResponse},
|
||||
},
|
||||
unknowns::SingleUnkIdAction,
|
||||
user_account::UserAccount,
|
||||
};
|
||||
use tracing::{error, info};
|
||||
|
||||
pub use crate::user_account::UserAccount;
|
||||
mod route;
|
||||
|
||||
pub use route::{AccountsRoute, AccountsRouteResponse};
|
||||
|
||||
/// The interface for managing the user's accounts.
|
||||
/// Represents all user-facing operations related to account management.
|
||||
pub struct AccountManager {
|
||||
pub struct Accounts {
|
||||
currently_selected_account: Option<usize>,
|
||||
accounts: Vec<UserAccount>,
|
||||
key_store: KeyStorageType,
|
||||
}
|
||||
|
||||
// TODO(jb55): move to accounts/route.rs
|
||||
pub enum AccountsRouteResponse {
|
||||
Accounts(AccountsViewResponse),
|
||||
AddAccount(AccountLoginResponse),
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)]
|
||||
pub enum AccountsRoute {
|
||||
Accounts,
|
||||
AddAccount,
|
||||
}
|
||||
|
||||
/// Render account management views from a route
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn render_accounts_route(
|
||||
@@ -48,7 +38,7 @@ pub fn render_accounts_route(
|
||||
col: usize,
|
||||
columns: &mut Columns,
|
||||
img_cache: &mut ImageCache,
|
||||
accounts: &mut AccountManager,
|
||||
accounts: &mut Accounts,
|
||||
login_state: &mut AcquireKeyState,
|
||||
route: AccountsRoute,
|
||||
) -> SingleUnkIdAction {
|
||||
@@ -84,7 +74,7 @@ pub fn render_accounts_route(
|
||||
}
|
||||
|
||||
pub fn process_accounts_view_response(
|
||||
manager: &mut AccountManager,
|
||||
manager: &mut Accounts,
|
||||
response: AccountsViewResponse,
|
||||
router: &mut Router<Route>,
|
||||
) {
|
||||
@@ -101,7 +91,7 @@ pub fn process_accounts_view_response(
|
||||
}
|
||||
}
|
||||
|
||||
impl AccountManager {
|
||||
impl Accounts {
|
||||
pub fn new(key_store: KeyStorageType) -> Self {
|
||||
let accounts = if let KeyStorageResponse::ReceivedResult(res) = key_store.get_keys() {
|
||||
res.unwrap_or_default()
|
||||
@@ -110,7 +100,7 @@ impl AccountManager {
|
||||
};
|
||||
|
||||
let currently_selected_account = get_selected_index(&accounts, &key_store);
|
||||
AccountManager {
|
||||
Accounts {
|
||||
currently_selected_account,
|
||||
accounts,
|
||||
key_store,
|
||||
@@ -224,7 +214,7 @@ fn get_selected_index(accounts: &[UserAccount], keystore: &KeyStorageType) -> Op
|
||||
}
|
||||
|
||||
pub fn process_login_view_response(
|
||||
manager: &mut AccountManager,
|
||||
manager: &mut Accounts,
|
||||
response: AccountLoginResponse,
|
||||
) -> SingleUnkIdAction {
|
||||
let r = match response {
|
||||
13
src/accounts/route.rs
Normal file
13
src/accounts/route.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use super::{AccountLoginResponse, AccountsViewResponse};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub enum AccountsRouteResponse {
|
||||
Accounts(AccountsViewResponse),
|
||||
AddAccount(AccountLoginResponse),
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)]
|
||||
pub enum AccountsRoute {
|
||||
Accounts,
|
||||
AddAccount,
|
||||
}
|
||||
19
src/app.rs
19
src/app.rs
@@ -1,10 +1,10 @@
|
||||
use crate::{
|
||||
account_manager::AccountManager,
|
||||
accounts::{Accounts, AccountsRoute},
|
||||
app_creation::setup_cc,
|
||||
app_size_handler::AppSizeHandler,
|
||||
app_style::user_requested_visuals_change,
|
||||
args::Args,
|
||||
column::Columns,
|
||||
column::{Column, Columns},
|
||||
draft::Drafts,
|
||||
filter::FilterState,
|
||||
frame_history::FrameHistory,
|
||||
@@ -13,6 +13,7 @@ use crate::{
|
||||
notecache::NoteCache,
|
||||
notes_holder::NotesHolderStorage,
|
||||
profile::Profile,
|
||||
route::Route,
|
||||
storage::{self, DataPath, DataPathType, Directory, FileKeyStorage, KeyStorageType},
|
||||
subscriptions::{SubKind, Subscriptions},
|
||||
support::Support,
|
||||
@@ -57,7 +58,7 @@ pub struct Damus {
|
||||
pub threads: NotesHolderStorage<Thread>,
|
||||
pub profiles: NotesHolderStorage<Profile>,
|
||||
pub img_cache: ImageCache,
|
||||
pub accounts: AccountManager,
|
||||
pub accounts: Accounts,
|
||||
pub subscriptions: Subscriptions,
|
||||
pub app_rect_handler: AppSizeHandler,
|
||||
pub support: Support,
|
||||
@@ -415,7 +416,7 @@ impl Damus {
|
||||
KeyStorageType::None
|
||||
};
|
||||
|
||||
let mut accounts = AccountManager::new(keystore);
|
||||
let mut accounts = Accounts::new(keystore);
|
||||
|
||||
let num_keys = parsed_args.keys.len();
|
||||
|
||||
@@ -489,7 +490,9 @@ impl Damus {
|
||||
let debug = parsed_args.debug;
|
||||
|
||||
if columns.columns().is_empty() {
|
||||
columns.new_column_picker();
|
||||
columns.add_column(Column::new(vec![Route::Accounts(
|
||||
AccountsRoute::AddAccount,
|
||||
)]));
|
||||
}
|
||||
|
||||
let app_rect_handler = AppSizeHandler::new(&path);
|
||||
@@ -535,11 +538,11 @@ impl Damus {
|
||||
&mut self.img_cache
|
||||
}
|
||||
|
||||
pub fn accounts(&self) -> &AccountManager {
|
||||
pub fn accounts(&self) -> &Accounts {
|
||||
&self.accounts
|
||||
}
|
||||
|
||||
pub fn accounts_mut(&mut self) -> &mut AccountManager {
|
||||
pub fn accounts_mut(&mut self) -> &mut Accounts {
|
||||
&mut self.accounts
|
||||
}
|
||||
|
||||
@@ -603,7 +606,7 @@ impl Damus {
|
||||
&config,
|
||||
)
|
||||
.expect("ndb"),
|
||||
accounts: AccountManager::new(KeyStorageType::None),
|
||||
accounts: Accounts::new(KeyStorageType::None),
|
||||
frame_history: FrameHistory::default(),
|
||||
view_state: ViewState::default(),
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ mod error;
|
||||
//mod note;
|
||||
//mod block;
|
||||
mod abbrev;
|
||||
pub mod account_manager;
|
||||
pub mod accounts;
|
||||
mod actionbar;
|
||||
pub mod app_creation;
|
||||
mod app_size_handler;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
account_manager::render_accounts_route,
|
||||
accounts::render_accounts_route,
|
||||
app_style::{get_font_size, NotedeckTextStyle},
|
||||
column::Columns,
|
||||
fonts::NamedFontFamily,
|
||||
|
||||
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{self};
|
||||
|
||||
use crate::{
|
||||
account_manager::AccountsRoute,
|
||||
accounts::AccountsRoute,
|
||||
column::Columns,
|
||||
timeline::{TimelineId, TimelineRoute},
|
||||
ui::{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
account_manager::AccountManager,
|
||||
accounts::Accounts,
|
||||
column::Columns,
|
||||
draft::Drafts,
|
||||
imgcache::ImageCache,
|
||||
@@ -51,7 +51,7 @@ pub fn render_timeline_route(
|
||||
unknown_ids: &mut UnknownIds,
|
||||
note_cache: &mut NoteCache,
|
||||
threads: &mut NotesHolderStorage<Thread>,
|
||||
accounts: &mut AccountManager,
|
||||
accounts: &mut Accounts,
|
||||
route: TimelineRoute,
|
||||
col: usize,
|
||||
textmode: bool,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::colors::PINK;
|
||||
use crate::imgcache::ImageCache;
|
||||
use crate::{
|
||||
account_manager::AccountManager,
|
||||
accounts::Accounts,
|
||||
route::{Route, Router},
|
||||
ui::{Preview, PreviewConfig, View},
|
||||
Damus,
|
||||
@@ -13,7 +13,7 @@ use super::profile::preview::SimpleProfilePreview;
|
||||
|
||||
pub struct AccountsView<'a> {
|
||||
ndb: &'a Ndb,
|
||||
accounts: &'a AccountManager,
|
||||
accounts: &'a Accounts,
|
||||
img_cache: &'a mut ImageCache,
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ enum ProfilePreviewOp {
|
||||
}
|
||||
|
||||
impl<'a> AccountsView<'a> {
|
||||
pub fn new(ndb: &'a Ndb, accounts: &'a AccountManager, img_cache: &'a mut ImageCache) -> Self {
|
||||
pub fn new(ndb: &'a Ndb, accounts: &'a Accounts, img_cache: &'a mut ImageCache) -> Self {
|
||||
AccountsView {
|
||||
ndb,
|
||||
accounts,
|
||||
@@ -56,7 +56,7 @@ impl<'a> AccountsView<'a> {
|
||||
|
||||
fn show_accounts(
|
||||
ui: &mut Ui,
|
||||
account_manager: &AccountManager,
|
||||
accounts: &Accounts,
|
||||
ndb: &Ndb,
|
||||
img_cache: &mut ImageCache,
|
||||
) -> Option<AccountsViewResponse> {
|
||||
@@ -71,8 +71,8 @@ impl<'a> AccountsView<'a> {
|
||||
return;
|
||||
};
|
||||
|
||||
for i in 0..account_manager.num_accounts() {
|
||||
let account_pubkey = account_manager
|
||||
for i in 0..accounts.num_accounts() {
|
||||
let account_pubkey = accounts
|
||||
.get_account(i)
|
||||
.map(|account| account.pubkey.bytes());
|
||||
|
||||
@@ -83,12 +83,12 @@ impl<'a> AccountsView<'a> {
|
||||
};
|
||||
|
||||
let profile = ndb.get_profile_by_pubkey(&txn, account_pubkey).ok();
|
||||
let is_selected =
|
||||
if let Some(selected) = account_manager.get_selected_account_index() {
|
||||
i == selected
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let is_selected = if let Some(selected) = accounts.get_selected_account_index()
|
||||
{
|
||||
i == selected
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let profile_peview_view = {
|
||||
let width = ui.available_width();
|
||||
@@ -217,7 +217,7 @@ fn selected_widget() -> impl egui::Widget {
|
||||
mod preview {
|
||||
|
||||
use super::*;
|
||||
use crate::{account_manager::process_accounts_view_response, test_data};
|
||||
use crate::{accounts::process_accounts_view_response, test_data};
|
||||
|
||||
pub struct AccountsPreview {
|
||||
app: Damus,
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod account_login_view;
|
||||
pub mod account_management;
|
||||
pub mod accounts;
|
||||
pub mod add_column;
|
||||
pub mod anim;
|
||||
pub mod mention;
|
||||
@@ -13,7 +13,7 @@ pub mod thread;
|
||||
pub mod timeline;
|
||||
pub mod username;
|
||||
|
||||
pub use account_management::AccountsView;
|
||||
pub use accounts::AccountsView;
|
||||
pub use mention::Mention;
|
||||
pub use note::{NoteResponse, NoteView, PostReplyView, PostView};
|
||||
pub use preview::{Preview, PreviewApp, PreviewConfig};
|
||||
|
||||
@@ -2,7 +2,7 @@ use egui::{vec2, Color32, InnerResponse, Layout, Margin, Separator, Stroke, Widg
|
||||
use tracing::info;
|
||||
|
||||
use crate::{
|
||||
account_manager::AccountsRoute,
|
||||
accounts::AccountsRoute,
|
||||
colors,
|
||||
column::{Column, Columns},
|
||||
imgcache::ImageCache,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use notedeck::ui::{
|
||||
account_login_view::AccountLoginView, account_management::AccountsView,
|
||||
add_column::AddColumnView, DesktopSidePanel, PostView, Preview, PreviewApp, PreviewConfig,
|
||||
ProfilePic, ProfilePreview, RelayView,
|
||||
account_login_view::AccountLoginView, accounts::AccountsView, add_column::AddColumnView,
|
||||
DesktopSidePanel, PostView, Preview, PreviewApp, PreviewConfig, ProfilePic, ProfilePreview,
|
||||
RelayView,
|
||||
};
|
||||
use notedeck::{
|
||||
app_creation::{generate_mobile_emulator_native_options, generate_native_options, setup_cc},
|
||||
|
||||
Reference in New Issue
Block a user