parent
e6d402bced
commit
60061224af
@ -0,0 +1,2 @@
|
|||||||
|
[build]
|
||||||
|
rustflags = ["--cfg", "engine"]
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,2 +1,2 @@
|
|||||||
.perseus/
|
dist/
|
||||||
pkg/
|
pkg/
|
||||||
|
|||||||
@ -1,29 +1,23 @@
|
|||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Prop)]
|
||||||
pub struct BaseButtonStateRx {
|
pub struct BaseButtonStateRx<'a> {
|
||||||
pub label: ReadSignal<String>,
|
pub label: &'a ReadSignal<String>,
|
||||||
pub disabled: ReadSignal<bool>,
|
pub disabled: &'a ReadSignal<bool>,
|
||||||
pub clicked: Signal<bool>,
|
pub clicked: &'a Signal<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component(BaseButton<G>)]
|
#[component]
|
||||||
pub fn create_component(
|
pub fn BaseButton<'a, G: Html>(cx: Scope<'a>, props: BaseButtonStateRx<'a>) -> View<G> {
|
||||||
BaseButtonStateRx {
|
let click_event = |_| props.clicked.set(true);
|
||||||
label,
|
|
||||||
disabled,
|
|
||||||
clicked,
|
|
||||||
}: BaseButtonStateRx,
|
|
||||||
) -> View<G> {
|
|
||||||
let click_event = cloned!((clicked) => move |_| { clicked.set(true) });
|
|
||||||
|
|
||||||
view! {
|
view! { cx,
|
||||||
button (
|
button (
|
||||||
class="my-2 z-0 p-2 bg-slate-300 dark:bg-slate-800 hover:bg-slate-400 dark:hover:bg-slate-900 disabled:cursor-not-allowed hover:cursor-pointer rounded-md ",
|
class="my-2 z-0 p-2 bg-slate-300 dark:bg-slate-800 hover:bg-slate-400 dark:hover:bg-slate-900 disabled:cursor-not-allowed hover:cursor-pointer rounded-md ",
|
||||||
disabled=*disabled.get(),
|
disabled=*props.disabled.get(),
|
||||||
on:click=click_event,
|
on:click=click_event,
|
||||||
) {
|
) {
|
||||||
(label.get())
|
(props.label.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,62 @@
|
|||||||
use perseus::{ErrorPages, Html};
|
use perseus::errors::ClientError;
|
||||||
use sycamore::view;
|
use perseus::prelude::*;
|
||||||
|
use sycamore::prelude::*;
|
||||||
|
|
||||||
pub fn get_error_pages<G: Html>() -> ErrorPages<G> {
|
pub fn get_error_views<G: Html>() -> ErrorViews<G> {
|
||||||
let mut error_pages = ErrorPages::new(|url, status, err, _| {
|
ErrorViews::new(|cx, err, _err_info, _err_pos| {
|
||||||
view! {
|
match err {
|
||||||
p { (format!("An error with HTTP code {} occurred at '{}': '{}'.", status, url, err)) }
|
ClientError::ServerError { status, message: _ } => match status {
|
||||||
|
404 => (
|
||||||
|
view! { cx,
|
||||||
|
title { "Page not found" }
|
||||||
|
},
|
||||||
|
view! { cx,
|
||||||
|
p { "Sorry, that page doesn't seem to exist." }
|
||||||
|
},
|
||||||
|
),
|
||||||
|
// 4xx is a client error
|
||||||
|
_ if (400..500).contains(&status) => (
|
||||||
|
view! { cx,
|
||||||
|
title { "Error" }
|
||||||
|
},
|
||||||
|
view! { cx,
|
||||||
|
p { "There was something wrong with the last request, please try reloading the page." }
|
||||||
|
},
|
||||||
|
),
|
||||||
|
// 5xx is a server error
|
||||||
|
_ => (
|
||||||
|
view! { cx,
|
||||||
|
title { "Error" }
|
||||||
|
},
|
||||||
|
view! { cx,
|
||||||
|
p { "Sorry, our server experienced an internal error. Please try reloading the page." }
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
ClientError::Panic(_) => (
|
||||||
|
view! { cx,
|
||||||
|
title { "Critical error" }
|
||||||
|
},
|
||||||
|
view! { cx,
|
||||||
|
p { "A critical error occured" }
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ClientError::FetchError(_) => (
|
||||||
|
view! { cx,
|
||||||
|
title { "Error" }
|
||||||
|
},
|
||||||
|
view! { cx,
|
||||||
|
p { "A network error occurred, do you have an internet connection? (If you do, try reloading the page.)" }
|
||||||
|
},
|
||||||
|
),
|
||||||
|
_ => (
|
||||||
|
view! { cx,
|
||||||
|
title { "Error" }
|
||||||
|
},
|
||||||
|
view! { cx,
|
||||||
|
p { (format!("An internal error has occurred: '{}'.", err)) }
|
||||||
|
},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
error_pages.add_page(404, |_, _, _, _| {
|
|
||||||
view! {
|
|
||||||
p { "Page not found." }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
error_pages
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,21 +1,26 @@
|
|||||||
|
use perseus::prelude::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::env::Config;
|
use crate::env::Config;
|
||||||
use perseus::{state::GlobalStateCreator, RenderFnResult};
|
use perseus::state::GlobalStateCreator;
|
||||||
|
|
||||||
pub fn get_global_state_creator() -> GlobalStateCreator {
|
pub fn get_global_state_creator() -> GlobalStateCreator {
|
||||||
GlobalStateCreator::new().build_state_fn(get_build_state)
|
GlobalStateCreator::new().build_state_fn(get_build_state)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[perseus::make_rx(AppStateRx)]
|
#[derive(Serialize, Deserialize, ReactiveState)]
|
||||||
|
#[rx(alias = "AppStateRx")]
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
pub dark_mode: bool,
|
pub dark_mode: bool,
|
||||||
pub config: Config,
|
pub config: Config,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[perseus::autoserde(global_build_state)]
|
#[engine_only_fn]
|
||||||
pub async fn get_build_state() -> RenderFnResult<AppState> {
|
pub async fn get_build_state(_locale: String) -> AppState {
|
||||||
|
use crate::env::Config;
|
||||||
let config = Config::new();
|
let config = Config::new();
|
||||||
Ok(AppState {
|
AppState {
|
||||||
config,
|
config,
|
||||||
dark_mode: true,
|
dark_mode: true,
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in new issue