diff --git a/gui/Cargo.toml b/gui/Cargo.toml deleted file mode 100644 index 9dc9b1b..0000000 --- a/gui/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "nextnet-gui" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -eframe = "0.27.2" -egui = "0.27.2" -ehttp = { version = "0.5.0", features = ["json"] } -serde = { version = "1.0.199", features = ["derive"] } -serde_json = "1.0.116" diff --git a/gui/src/api.rs b/gui/src/api.rs deleted file mode 100644 index 17d1091..0000000 --- a/gui/src/api.rs +++ /dev/null @@ -1,50 +0,0 @@ -use ehttp::{fetch, Request}; -use serde::Deserialize; -use serde_json::json; - -pub struct NextAPIClient { - pub url: String, -} - -#[derive(Deserialize, Debug, Default)] -pub struct LoginResponse { - pub error: Option, - pub token: Option, -} - -impl NextAPIClient { - pub fn login( - &self, - email: &str, - password: &str, - mut callback: impl 'static + Send + FnMut(LoginResponse), - ) { - let json_data = json!({ - "email": email, - "password": password - }); - - let json_str_raw: String = json_data.to_string(); - let json_str: &str = json_str_raw.as_str(); - - println!("{}", json_str); - - let mut request = Request::post( - self.url.clone() + "/api/v1/users/login", - json_str.as_bytes().to_vec(), - ); - request.headers.insert("Content-Type", "application/json"); - - fetch(request, move |result: ehttp::Result| { - let res = result.unwrap(); - let json: LoginResponse = res.json().unwrap(); - callback(json); - }); - } -} - -pub fn new(url: String) -> NextAPIClient { - let api_client: NextAPIClient = NextAPIClient { url }; - - return api_client; -} diff --git a/gui/src/components/log_in.rs b/gui/src/components/log_in.rs deleted file mode 100644 index b4cdaaa..0000000 --- a/gui/src/components/log_in.rs +++ /dev/null @@ -1,40 +0,0 @@ -use eframe::egui; -use std::sync::Arc; - -use crate::api; -use crate::ApplicationState; - -pub fn main(state: &mut ApplicationState, api: &api::NextAPIClient, ctx: &eframe::egui::Context) { - egui::Window::new("Log In").show(ctx, move |ui| { - ui.set_max_width(275.0); - - ui.horizontal(|ui| { - ui.label("Email: "); - ui.text_edit_singleline(&mut state.username); - }); - - ui.horizontal(|ui| { - let label = ui.label("Password: "); - ui.add(egui::TextEdit::singleline(&mut state.password).password(true)) - .labelled_by(label.id); - }); - - if ui.button("Login").clicked() { - let token_clone = Arc::clone(&state.token); - api.login( - state.username.as_str(), - state.password.as_str(), - Box::new(move |res: api::LoginResponse| match res.token { - Some(x) => { - let mut token = token_clone.lock().unwrap(); - *token = x; - } - None => { - let mut token = token_clone.lock().unwrap(); - *token = "".to_string(); - } - }), - ); - } - }); -} diff --git a/gui/src/components/mod.rs b/gui/src/components/mod.rs deleted file mode 100644 index cf639a1..0000000 --- a/gui/src/components/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod log_in; diff --git a/gui/src/main.rs b/gui/src/main.rs deleted file mode 100644 index 504295a..0000000 --- a/gui/src/main.rs +++ /dev/null @@ -1,45 +0,0 @@ -use eframe::egui; -use std::sync::{Arc, Mutex}; - -mod api; -mod components; - -pub struct ApplicationState { - token: Arc>, - username: String, - password: String, -} - -fn main() -> Result<(), eframe::Error> { - let api = api::new("http://localhost:3000".to_string()); - - let options = eframe::NativeOptions { - viewport: egui::ViewportBuilder::default().with_inner_size([1280.0, 720.0]), - ..Default::default() - }; - - let mut app_state: ApplicationState = ApplicationState { - token: Arc::new(Mutex::new("".to_string())), - - // /!\ NOT THREAD SAFE FIELDS /!\ - // These are used internally for each application (immediate mode + functions which are stateless, - // and we need *a* state somehow) - - // components/log_in.rs - username: "replace@gmail.com".to_owned(), - password: "replace123".to_owned(), - }; - - eframe::run_simple_native("NextNet GUI", options, move |ctx, _frame| { - egui::CentralPanel::default().show(ctx, |_ui| { - let token_clone = Arc::clone(&app_state.token); - let token = token_clone.lock().unwrap(); - - if *token == "".to_string() { - components::log_in::main(&mut app_state, &api, ctx); - } else { - // ... - } - }); - }) -}