chore: Adds formatting.
Co-authored-by: dess <devessa@users.noreply.github.com>
This commit is contained in:
parent
6cf26da4df
commit
42a6d2ea02
33 changed files with 1235 additions and 1032 deletions
|
@ -3,17 +3,22 @@ use serde::Deserialize;
|
|||
use serde_json::json;
|
||||
|
||||
pub struct NextAPIClient {
|
||||
pub url: String
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Default)]
|
||||
pub struct LoginResponse {
|
||||
pub error: Option<String>,
|
||||
pub token: Option<String>
|
||||
pub token: Option<String>,
|
||||
}
|
||||
|
||||
impl NextAPIClient {
|
||||
pub fn login(&self, email: &str, password: &str, mut callback: impl 'static + Send + FnMut(LoginResponse)) {
|
||||
pub fn login(
|
||||
&self,
|
||||
email: &str,
|
||||
password: &str,
|
||||
mut callback: impl 'static + Send + FnMut(LoginResponse),
|
||||
) {
|
||||
let json_data = json!({
|
||||
"email": email,
|
||||
"password": password
|
||||
|
@ -24,7 +29,10 @@ impl NextAPIClient {
|
|||
|
||||
println!("{}", json_str);
|
||||
|
||||
let mut request = Request::post(self.url.clone() + "/api/v1/users/login", json_str.as_bytes().to_vec());
|
||||
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<ehttp::Response>| {
|
||||
|
@ -36,9 +44,7 @@ impl NextAPIClient {
|
|||
}
|
||||
|
||||
pub fn new(url: String) -> NextAPIClient {
|
||||
let api_client: NextAPIClient = NextAPIClient {
|
||||
url
|
||||
};
|
||||
let api_client: NextAPIClient = NextAPIClient { url };
|
||||
|
||||
return api_client;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::sync::Arc;
|
||||
use eframe::egui;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::api;
|
||||
use crate::ApplicationState;
|
||||
|
@ -12,7 +12,7 @@ pub fn main(state: &mut ApplicationState, api: &api::NextAPIClient, ctx: &eframe
|
|||
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))
|
||||
|
@ -21,18 +21,20 @@ pub fn main(state: &mut ApplicationState, api: &api::NextAPIClient, ctx: &eframe
|
|||
|
||||
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 {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}));
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
pub mod log_in;
|
||||
pub mod log_in;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
use eframe::egui;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
mod components;
|
||||
mod api;
|
||||
mod components;
|
||||
|
||||
pub struct ApplicationState {
|
||||
token: Arc<Mutex<String>>,
|
||||
|
@ -20,21 +20,21 @@ fn main() -> Result<(), eframe::Error> {
|
|||
|
||||
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)
|
||||
// and we need *a* state somehow)
|
||||
|
||||
// components/log_in.rs
|
||||
username: "replace@gmail.com".to_owned(),
|
||||
password: "replace123".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 {
|
||||
|
@ -42,4 +42,4 @@ fn main() -> Result<(), eframe::Error> {
|
|||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue