diff --git a/gamercade_app/src/app.rs b/gamercade_app/src/app.rs index 888c7dc..ec95f0c 100644 --- a/gamercade_app/src/app.rs +++ b/gamercade_app/src/app.rs @@ -5,8 +5,8 @@ use crate::{ local_directory::LocalDirectory, modes::{AppMode, ArcadeModeView, LibraryModeView, SettingsModeView}, task_manager::{ - AuthState, AuthorRequest, GameResponse, HttpResponse, PlatformRequest, PlatformResponse, - SuperTaskManager, TagRequest, TaskNotification, + AuthResponse, AuthState, AuthorRequest, GameResponse, HttpResponse, PlatformRequest, + PlatformResponse, SuperTaskManager, TagRequest, TaskNotification, }, }; @@ -85,33 +85,9 @@ impl App { TaskNotification::GlobalPermissionLevels(permissions) => { self.directory.upsert_permission_levesl(&permissions, true); } - TaskNotification::AuthStateChanged(new_state) => { - self.auth_state = new_state; - - self.modes.arcade.login.waiting = false; - - match &self.auth_state { - AuthState::Unauthorized => self.modes.arcade.logged_out(), - AuthState::SessionHeld(session) => { - self.modes.arcade.logged_in(); - self.tasks - .platform - .send(PlatformRequest::FrontPage(FrontPageRequest {})); - self.tasks - .platform - .send(PlatformRequest::VotedGames(session.clone())); - self.tasks - .platform - .send(PlatformRequest::EditableGames(session.clone())); - self.tasks.tags.send(TagRequest::Initialize); - self.tasks.author.send(AuthorRequest::Initialize); - } - } - } - TaskNotification::LoginFailed => { - self.modes.arcade.login.waiting = false; - self.modes.arcade.logged_out(); - } + + TaskNotification::AuthResponse(response) => self.handle_auth_response(response), + TaskNotification::PlatformResponse(response) => { self.handle_platform_response(response) } @@ -121,6 +97,39 @@ impl App { } } + fn handle_auth_response(&mut self, response: AuthResponse) { + match response { + AuthResponse::LoggedIn(new_state) => { + self.auth_state = new_state; + + self.modes.arcade.login.waiting = false; + + match &self.auth_state { + AuthState::Unauthorized => self.modes.arcade.logged_out(), + AuthState::SessionHeld(session) => { + self.modes.arcade.logged_in(); + self.tasks + .platform + .send(PlatformRequest::FrontPage(FrontPageRequest {})); + self.tasks + .platform + .send(PlatformRequest::VotedGames(session.clone())); + self.tasks + .platform + .send(PlatformRequest::EditableGames(session.clone())); + self.tasks.tags.send(TagRequest::Initialize); + self.tasks.author.send(AuthorRequest::Initialize); + } + } + } + AuthResponse::Error(e) => { + self.modes.arcade.login.waiting = false; + self.modes.arcade.logged_out(); + println!("Auth error: {e}"); + } + } + } + fn handle_game_response(&mut self, response: GameResponse) { let mut update = None; match response { diff --git a/gamercade_app/src/task_manager/auth.rs b/gamercade_app/src/task_manager/auth.rs index 44cc3ea..49f98fc 100644 --- a/gamercade_app/src/task_manager/auth.rs +++ b/gamercade_app/src/task_manager/auth.rs @@ -49,6 +49,12 @@ pub enum AuthRequest { SignUp(SignUpRequest), } +#[derive(Debug)] +pub enum AuthResponse { + LoggedIn(AuthState), + Error(String), +} + impl Debug for AuthRequest { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { @@ -87,8 +93,8 @@ async fn handle_login( if let Ok(session) = Session::try_from(response.session.as_slice()) { sender - .send(TaskNotification::AuthStateChanged(AuthState::SessionHeld( - session, + .send(TaskNotification::AuthResponse(AuthResponse::LoggedIn( + AuthState::SessionHeld(session), ))) .await .unwrap(); @@ -98,8 +104,12 @@ async fn handle_login( } } Err(e) => { - sender.send(TaskNotification::LoginFailed).await.unwrap(); - println!("{e}"); + sender + .send(TaskNotification::AuthResponse(AuthResponse::Error( + e.to_string(), + ))) + .await + .unwrap(); } } } @@ -116,8 +126,8 @@ async fn handle_sign_up( if let Ok(session) = Session::try_from(response.session.as_slice()) { sender - .send(TaskNotification::AuthStateChanged(AuthState::SessionHeld( - session, + .send(TaskNotification::AuthResponse(AuthResponse::LoggedIn( + AuthState::SessionHeld(session), ))) .await .unwrap(); diff --git a/gamercade_app/src/task_manager/super_task_manager.rs b/gamercade_app/src/task_manager/super_task_manager.rs index 92e064d..842fce4 100644 --- a/gamercade_app/src/task_manager/super_task_manager.rs +++ b/gamercade_app/src/task_manager/super_task_manager.rs @@ -3,7 +3,7 @@ use tokio::sync::mpsc::{channel, Receiver}; use crate::local_directory::{PermissionLevel, PermissionLevelId, Tag, TagId}; use super::{ - AuthManager, AuthState, AuthorManager, GameManager, GameResponse, HttpManager, HttpResponse, + AuthManager, AuthResponse, AuthorManager, GameManager, GameResponse, HttpManager, HttpResponse, PlatformManager, PlatformResponse, TagManager, SUPER_TASK_CHANNEL_SIZE, }; @@ -11,8 +11,11 @@ use super::{ pub enum TaskNotification { GlobalTags(Vec<(TagId, Tag)>), GlobalPermissionLevels(Vec<(PermissionLevelId, PermissionLevel)>), - AuthStateChanged(AuthState), - LoginFailed, + //AuthStateChanged(AuthState), + //LoginFailed, + + // Auth + AuthResponse(AuthResponse), // Game GameResponse(GameResponse),