Conversation
Owner
Author
|
this is quite a WIP branch, but it works at this point, and i dont want to lose my local changes (for the 3rd time), hence the upload :D testers are welcome! |
…makefile, don't forget though
Merged
b6c200c to
84bb86e
Compare
Collaborator
|
as DioxusLabs/dioxus#5089 has been fixed, it's time to see how it works!
don't forget to run diff --git a/src/app/home/actions.rs b/src/app/home/actions.rs
--- a/src/app/home/actions.rs
+++ b/src/app/home/actions.rs
@@ -30,19 +30,16 @@ pub fn handle_user_join(
return;
}
- let _ok_none = crate::backend::endpoints::join(u.clone()).await;
- match crate::backend::endpoints::auth_state().await {
- Ok(uname) => {
- popup_normal(toast_api, format!("Üdv, {}", uname));
+ match crate::backend::endpoints::join(u.clone()).await {
+ Ok(_) => {
+ popup_normal(toast_api, format!("Üdv, {u}"));
auth.write().joined = true; // TODO auth.reset(_somefield)
auth.write().password = String::new();
auth.write().show_password_prompt = false;
}
- Err(e) => {
- popup_error(
- toast_api,
- format!("Hiba: {}", e.message.unwrap_or("ismeretlen hiba".into())),
- );
+ Err(http_err) => {
+ error!("couldn't join: {http_err}");
+ popup_error(toast_api, format!("Hiba: {http_err}"));
}
}
}); // spawn async move
@@ -216,11 +213,8 @@ pub fn handle_logout(
popup_normal(toast_api, format!("Viszlát, {}", auth.read().username));
auth.set(AuthState::default());
}
- Err(e) => {
- popup_error(
- toast_api,
- format!("Hiba: {}", e.message.unwrap_or("ismeretlen hiba".into())),
- );
+ Err(http_err) => {
+ popup_error(toast_api, format!("Hiba: {http_err}"));
}
}
}); |
Merged
…ts -> /app/components
Collaborator
|
better toasts with proc macro to generate fn-s for them: diff --git a/src/app/home/actions.rs b/src/app/home/actions.rs
index fd2a772..dd5ee1a 100644
--- a/src/app/home/actions.rs
+++ b/src/app/home/actions.rs
@@ -5,7 +5,7 @@ use crate::{
app::home::{
models::AuthState,
utils::{
- parse_puzzle_csv, popup_error, popup_normal, validate_puzzle_id,
+ parse_puzzle_csv, popup_error, popup_normal, popup_success, validate_puzzle_id,
validate_puzzle_solution, validate_puzzle_value,
},
},
@@ -33,17 +33,12 @@ pub fn handle_user_join(
let _ok_none = crate::backend::endpoints::join(u.clone()).await;
match crate::backend::endpoints::auth_state().await {
Ok(uname) => {
- popup_normal(toast_api, format!("Üdv, {}", uname));
+ popup_success(toast_api, format!("Üdv, {}", uname));
auth.write().joined = true; // TODO auth.reset(_somefield)
auth.write().password = String::new();
auth.write().show_password_prompt = false;
}
- Err(e) => {
- popup_error(
- toast_api,
- format!("Hiba: {}", e.message.unwrap_or("ismeretlen hiba".into())),
- );
- }
+ Err(e) => popup_error(toast_api, e),
}
}); // spawn async move
} // move
@@ -70,10 +65,7 @@ pub fn handle_admin_join(
auth.write().joined = true;
popup_normal(toast_api, msg);
}
- Err(e) => popup_error(
- toast_api,
- format!("Hiba: {}", e.message.unwrap_or("ismeretlen hiba".into())),
- ),
+ Err(e) => popup_error(toast_api, e),
}
}
}); // spawn async move
@@ -104,7 +96,7 @@ pub fn handle_user_submit(
puzzle_solution.set(String::new());
}
Err(e) => {
- popup_error(toast_api, format!("Hiba: {}", e));
+ popup_error(toast_api, e);
}
}
});
@@ -160,10 +152,7 @@ pub fn handle_admin_submit(
// password.set(String::new()); NOTE should remember password?
}
Err(e) => {
- popup_error(
- toast_api,
- format!("Hiba: {}", e.message.unwrap_or("ismeretlen hiba".into())),
- );
+ popup_error(toast_api, e);
}
}
});
@@ -217,10 +206,7 @@ pub fn handle_logout(
auth.set(AuthState::default());
}
Err(e) => {
- popup_error(
- toast_api,
- format!("Hiba: {}", e.message.unwrap_or("ismeretlen hiba".into())),
- );
+ popup_error(toast_api, e);
}
}
});
diff --git a/src/app/home/utils.rs b/src/app/home/utils.rs
index 48525ad..48498e0 100644
--- a/src/app/home/utils.rs
+++ b/src/app/home/utils.rs
@@ -65,25 +65,23 @@ pub fn parse_puzzle_csv(csv_text: &str, toast_api: Toasts) -> PuzzleSolutions {
puzzles
}
-pub fn popup_error(toast_api: Toasts, text: impl std::fmt::Display) {
- toast_api.error(
- "".to_string(),
- ToastOptions::new()
- .description(text)
- .duration(Duration::from_secs(3))
- .permanent(false),
- );
+macro_rules! gen_toast {
+ ($func_name:ident, $kind:ident, title: $title:literal, timeout: $timeout:expr) => {
+ pub fn $func_name(toast_api: Toasts, text: impl std::fmt::Display) {
+ toast_api.$kind(
+ $title.to_string(),
+ ToastOptions::new()
+ .description(text)
+ .duration(Duration::from_secs($timeout))
+ .permanent(false),
+ );
+ }
+ };
}
-pub fn popup_normal(toast_api: Toasts, text: impl std::fmt::Display) {
- toast_api.info(
- "".to_string(),
- ToastOptions::new()
- .description(text)
- .duration(Duration::from_secs(3))
- .permanent(false),
- );
-}
+gen_toast!(popup_normal, info, title: "Info", timeout: 5);
+gen_toast!(popup_success, success, title: "Siker", timeout: 6);
+gen_toast!(popup_error, error, title: "Hiba", timeout: 12);
pub fn get_points_of(team: &(String, SolvedPuzzles), puzzles: Vec<(PuzzleId, PuzzleValue)>) -> u32 {
puzzles
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #21
set_admin_passwordendpoint