|
|
|
|
@@ -45,20 +45,6 @@ impl fmt::Display for ErrorLocation {
|
|
|
|
|
|
|
|
|
|
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
|
|
|
|
|
|
|
|
|
/// Generate a random string to use as an id for the modal
|
|
|
|
|
/// This allows multiple toast/modal to be present
|
|
|
|
|
fn rand_modal_id() -> String {
|
|
|
|
|
use rand::RngExt;
|
|
|
|
|
|
|
|
|
|
let mut rng = rand::rng();
|
|
|
|
|
|
|
|
|
|
let random_str = (0..5)
|
|
|
|
|
.map(|_| rng.sample(rand::distr::Alphanumeric) as char)
|
|
|
|
|
.collect::<String>();
|
|
|
|
|
|
|
|
|
|
format!("err-modal-{random_str}")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, thiserror::Error)]
|
|
|
|
|
pub struct Error {
|
|
|
|
|
#[source]
|
|
|
|
|
@@ -111,12 +97,6 @@ impl Error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get the original cause of this error
|
|
|
|
|
/// Like `std::error::Error::source` but doesn't return an `Option`
|
|
|
|
|
pub fn source(&self) -> &ErrorType {
|
|
|
|
|
&self.source
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Display this error as a modal dialog activated by a checkbox with the given id
|
|
|
|
|
pub fn as_modal(&self, id: String) -> Element {
|
|
|
|
|
rsx! {
|
|
|
|
|
@@ -193,9 +173,28 @@ impl Error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Convert this error into an alert label, tied to the given modal id
|
|
|
|
|
fn as_alert_for(&self, modal_id: String) -> Element {
|
|
|
|
|
/// Convert this error to a toast message, which opens a modal when clicked
|
|
|
|
|
pub fn as_toast(&self) -> Element {
|
|
|
|
|
// Generate a random string to use as an id for the modal
|
|
|
|
|
// This allows multiple toast/modal to be present
|
|
|
|
|
let modal_id = {
|
|
|
|
|
use rand::RngExt;
|
|
|
|
|
|
|
|
|
|
let mut rng = rand::rng();
|
|
|
|
|
|
|
|
|
|
let random_str = (0..5)
|
|
|
|
|
.map(|_| rng.sample(rand::distr::Alphanumeric) as char)
|
|
|
|
|
.collect::<String>();
|
|
|
|
|
|
|
|
|
|
format!("err-modal-{random_str}")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
rsx! {
|
|
|
|
|
{self.as_modal(modal_id.clone())}
|
|
|
|
|
|
|
|
|
|
div {
|
|
|
|
|
class: "toast z-99",
|
|
|
|
|
|
|
|
|
|
label {
|
|
|
|
|
class: "alert alert-error alert-soft cursor-pointer",
|
|
|
|
|
role: "alert",
|
|
|
|
|
@@ -209,29 +208,6 @@ impl Error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Convert this error to a toast message, which opens a modal when clicked
|
|
|
|
|
pub fn as_toast(&self) -> Element {
|
|
|
|
|
let modal_id = rand_modal_id();
|
|
|
|
|
|
|
|
|
|
rsx! {
|
|
|
|
|
{self.as_modal(modal_id.clone())}
|
|
|
|
|
|
|
|
|
|
div {
|
|
|
|
|
class: "toast z-99",
|
|
|
|
|
{self.as_alert_for(modal_id)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Convert this error into an alert label, which opens a modal when clicked
|
|
|
|
|
pub fn as_alert(&self) -> Element {
|
|
|
|
|
let modal_id = rand_modal_id();
|
|
|
|
|
|
|
|
|
|
rsx! {
|
|
|
|
|
{self.as_modal(modal_id.clone())}
|
|
|
|
|
{self.as_alert_for(modal_id)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|