Compare commits
1 Commits
843572b487
...
eae628bd62
| Author | SHA1 | Date | |
|---|---|---|---|
|
eae628bd62
|
@@ -1 +1,2 @@
|
|||||||
|
|
||||||
pub mod footer;
|
pub mod footer;
|
||||||
|
|||||||
@@ -45,20 +45,6 @@ impl fmt::Display for ErrorLocation {
|
|||||||
|
|
||||||
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
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)]
|
#[derive(Debug, Clone, Deserialize, Serialize, thiserror::Error)]
|
||||||
pub struct Error {
|
pub struct Error {
|
||||||
#[source]
|
#[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
|
/// Display this error as a modal dialog activated by a checkbox with the given id
|
||||||
pub fn as_modal(&self, id: String) -> Element {
|
pub fn as_modal(&self, id: String) -> Element {
|
||||||
rsx! {
|
rsx! {
|
||||||
@@ -193,46 +173,42 @@ impl Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert this error into an alert label, tied to the given modal id
|
|
||||||
fn as_alert_for(&self, modal_id: String) -> Element {
|
|
||||||
rsx! {
|
|
||||||
label {
|
|
||||||
class: "alert alert-error alert-soft cursor-pointer",
|
|
||||||
role: "alert",
|
|
||||||
r#for: modal_id,
|
|
||||||
lucide_dioxus::CircleAlert {}
|
|
||||||
|
|
||||||
p {
|
|
||||||
class: "max-w-120 text-ellipsis line-clamp-3",
|
|
||||||
{self.top_message()}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert this error to a toast message, which opens a modal when clicked
|
/// Convert this error to a toast message, which opens a modal when clicked
|
||||||
pub fn as_toast(&self) -> Element {
|
pub fn as_toast(&self) -> Element {
|
||||||
let modal_id = rand_modal_id();
|
// 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! {
|
rsx! {
|
||||||
{self.as_modal(modal_id.clone())}
|
{self.as_modal(modal_id.clone())}
|
||||||
|
|
||||||
div {
|
div {
|
||||||
class: "toast z-99",
|
class: "toast z-99",
|
||||||
{self.as_alert_for(modal_id)}
|
|
||||||
|
label {
|
||||||
|
class: "alert alert-error alert-soft cursor-pointer",
|
||||||
|
role: "alert",
|
||||||
|
r#for: modal_id,
|
||||||
|
lucide_dioxus::CircleAlert {}
|
||||||
|
|
||||||
|
p {
|
||||||
|
class: "max-w-120 text-ellipsis line-clamp-3",
|
||||||
|
{self.top_message()}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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)}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
|
|||||||
Reference in New Issue
Block a user