-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fbfdfaf
commit 4f4103d
Showing
11 changed files
with
255 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,18 @@ | ||
use eframe::egui::{self, TextEdit, Ui}; | ||
use eframe::egui::{self}; | ||
|
||
use crate::auth::AuthClient; | ||
use crate::{auth::AuthClient, view::ActiveView}; | ||
|
||
#[derive(Default)] | ||
pub struct App { | ||
auth_client: AuthClient, | ||
|
||
username: String, | ||
password: String, | ||
email: String, | ||
|
||
active_view: ActiveView, | ||
} | ||
|
||
#[derive(Default)] | ||
enum ActiveView { | ||
#[default] | ||
Login, | ||
SignUp, | ||
Browsing, | ||
} | ||
|
||
impl eframe::App for App { | ||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { | ||
egui::CentralPanel::default().show(ctx, |ui| { | ||
match self.active_view { | ||
ActiveView::Login => self.draw_login(ui), | ||
ActiveView::SignUp => self.draw_sign_up(ui), | ||
ActiveView::Browsing => self.draw_browsing(ui), | ||
}; | ||
}); | ||
} | ||
} | ||
|
||
impl App { | ||
fn draw_login(&mut self, ui: &mut Ui) { | ||
ui.horizontal(|ui| { | ||
ui.label("Username: "); | ||
ui.text_edit_singleline(&mut self.username); | ||
}); | ||
|
||
ui.horizontal(|ui| { | ||
ui.label("Password: "); | ||
let pw_entry = TextEdit::singleline(&mut self.password).password(true); | ||
ui.add(pw_entry); | ||
}); | ||
|
||
if ui.button("Sign Up").clicked() { | ||
self.active_view = ActiveView::SignUp; | ||
} | ||
|
||
if ui.button("Login").clicked() { | ||
self.auth_client.try_login(&self.username, &self.password); | ||
//TODO: Lock entries while waiting | ||
//TODO: Show an animation thing | ||
self.clear_text(); | ||
} | ||
|
||
if ui.button("Login as Guest").clicked() { | ||
println!("TODO: Login as guest!") | ||
} | ||
} | ||
|
||
fn draw_sign_up(&mut self, ui: &mut Ui) { | ||
ui.horizontal(|ui| { | ||
ui.label("Username: "); | ||
ui.text_edit_singleline(&mut self.username); | ||
}); | ||
|
||
ui.horizontal(|ui| { | ||
ui.label("Email Address: "); | ||
let email = TextEdit::singleline(&mut self.email); | ||
ui.add(email); | ||
}); | ||
|
||
ui.horizontal(|ui| { | ||
ui.label("Password: "); | ||
let pw_entry = TextEdit::singleline(&mut self.password).password(true); | ||
ui.add(pw_entry); | ||
self.active_view.draw(ui, &mut self.auth_client); | ||
}); | ||
|
||
if ui.button("Register").clicked() { | ||
self.auth_client | ||
.try_register(&self.username, &self.email, &self.password); | ||
// TODO: Lock the entries while waiting... | ||
// TODO: Show an animation thing... | ||
self.clear_text(); | ||
} | ||
|
||
if ui.button("Cancel").clicked() { | ||
self.clear_text(); | ||
self.active_view = ActiveView::Login; | ||
} | ||
} | ||
|
||
fn draw_browsing(&mut self, ui: &mut Ui) { | ||
ui.label("Browsing"); | ||
} | ||
|
||
fn clear_text(&mut self) { | ||
self.username.clear(); | ||
self.email.clear(); | ||
self.password.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
use gamercade_interface::Session; | ||
|
||
#[derive(Default, Debug)] | ||
pub enum AuthState { | ||
// Default State | ||
#[default] | ||
Unauthorized, | ||
|
||
// Holding Tokens | ||
TokensHeld(AuthToken), | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct AuthToken { | ||
pub access_token: String, | ||
pub refresh_token: String, | ||
pub expires_at: u64, | ||
// Holding Session | ||
SessionHeld(Session), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use eframe::egui::Ui; | ||
|
||
use super::ActiveView; | ||
|
||
#[derive(Default)] | ||
pub struct BrowsingView {} | ||
|
||
impl BrowsingView { | ||
pub fn draw(&mut self, ui: &mut Ui) -> Option<ActiveView> { | ||
ui.label("Browsing"); | ||
|
||
None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use eframe::egui::{TextEdit, Ui}; | ||
|
||
use crate::auth::AuthClient; | ||
|
||
use super::ActiveView; | ||
|
||
#[derive(Default)] | ||
pub struct LoginView { | ||
provider: String, | ||
provider_kind: Provider, | ||
password: String, | ||
} | ||
|
||
#[derive(Default)] | ||
enum Provider { | ||
#[default] | ||
Username, | ||
Email, | ||
} | ||
|
||
impl LoginView { | ||
pub fn draw(&mut self, ui: &mut Ui, auth_client: &AuthClient) -> Option<ActiveView> { | ||
ui.horizontal(|ui| { | ||
let text = match self.provider_kind { | ||
Provider::Username => "Username: ", | ||
Provider::Email => "Email: ", | ||
}; | ||
ui.label(text); | ||
ui.text_edit_singleline(&mut self.provider); | ||
}); | ||
|
||
ui.horizontal(|ui| { | ||
ui.label("Password: "); | ||
let pw_entry = TextEdit::singleline(&mut self.password).password(true); | ||
ui.add(pw_entry); | ||
}); | ||
|
||
if ui.button("Sign Up").clicked() { | ||
return Some(ActiveView::sign_up()); | ||
} | ||
|
||
if ui.button("Login").clicked() { | ||
// TODO: Support email login too | ||
auth_client.try_login(&self.provider, &self.password); | ||
//TODO: Lock entries while waiting | ||
//TODO: Show an animation thing | ||
} | ||
|
||
if ui.button("Login as Guest").clicked() { | ||
println!("TODO: Login as guest!") | ||
} | ||
|
||
None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use eframe::egui::Ui; | ||
|
||
use crate::auth::AuthClient; | ||
|
||
use self::{browsing::BrowsingView, login::LoginView, sign_up::SignUpView}; | ||
|
||
mod browsing; | ||
mod login; | ||
mod sign_up; | ||
|
||
pub enum ActiveView { | ||
Login(LoginView), | ||
SignUp(SignUpView), | ||
Browsing(BrowsingView), | ||
} | ||
|
||
impl Default for ActiveView { | ||
fn default() -> Self { | ||
Self::login() | ||
} | ||
} | ||
|
||
impl ActiveView { | ||
fn login() -> Self { | ||
Self::Login(LoginView::default()) | ||
} | ||
|
||
fn sign_up() -> Self { | ||
Self::SignUp(SignUpView::default()) | ||
} | ||
|
||
fn browsing() -> Self { | ||
Self::Browsing(BrowsingView::default()) | ||
} | ||
|
||
pub fn draw(&mut self, ui: &mut Ui, auth_client: &mut AuthClient) { | ||
if let Some(next) = match self { | ||
ActiveView::Login(view) => view.draw(ui, auth_client), | ||
ActiveView::SignUp(view) => view.draw(ui, auth_client), | ||
ActiveView::Browsing(view) => view.draw(ui), | ||
} { | ||
*self = next; | ||
} | ||
} | ||
} |
Oops, something went wrong.