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/
|
||||
|
||||
@ -1,29 +1,23 @@
|
||||
use sycamore::prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct BaseButtonStateRx {
|
||||
pub label: ReadSignal<String>,
|
||||
pub disabled: ReadSignal<bool>,
|
||||
pub clicked: Signal<bool>,
|
||||
#[derive(Prop)]
|
||||
pub struct BaseButtonStateRx<'a> {
|
||||
pub label: &'a ReadSignal<String>,
|
||||
pub disabled: &'a ReadSignal<bool>,
|
||||
pub clicked: &'a Signal<bool>,
|
||||
}
|
||||
|
||||
#[component(BaseButton<G>)]
|
||||
pub fn create_component(
|
||||
BaseButtonStateRx {
|
||||
label,
|
||||
disabled,
|
||||
clicked,
|
||||
}: BaseButtonStateRx,
|
||||
) -> View<G> {
|
||||
let click_event = cloned!((clicked) => move |_| { clicked.set(true) });
|
||||
#[component]
|
||||
pub fn BaseButton<'a, G: Html>(cx: Scope<'a>, props: BaseButtonStateRx<'a>) -> View<G> {
|
||||
let click_event = |_| props.clicked.set(true);
|
||||
|
||||
view! {
|
||||
view! { cx,
|
||||
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 ",
|
||||
disabled=*disabled.get(),
|
||||
disabled=*props.disabled.get(),
|
||||
on:click=click_event,
|
||||
) {
|
||||
(label.get())
|
||||
(props.label.get())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +1,62 @@
|
||||
use perseus::{ErrorPages, Html};
|
||||
use sycamore::view;
|
||||
use perseus::errors::ClientError;
|
||||
use perseus::prelude::*;
|
||||
use sycamore::prelude::*;
|
||||
|
||||
pub fn get_error_pages<G: Html>() -> ErrorPages<G> {
|
||||
let mut error_pages = ErrorPages::new(|url, status, err, _| {
|
||||
view! {
|
||||
p { (format!("An error with HTTP code {} occurred at '{}': '{}'.", status, url, err)) }
|
||||
pub fn get_error_views<G: Html>() -> ErrorViews<G> {
|
||||
ErrorViews::new(|cx, err, _err_info, _err_pos| {
|
||||
match 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 perseus::{state::GlobalStateCreator, RenderFnResult};
|
||||
use perseus::state::GlobalStateCreator;
|
||||
|
||||
pub fn get_global_state_creator() -> GlobalStateCreator {
|
||||
GlobalStateCreator::new().build_state_fn(get_build_state)
|
||||
}
|
||||
|
||||
#[perseus::make_rx(AppStateRx)]
|
||||
#[derive(Serialize, Deserialize, ReactiveState)]
|
||||
#[rx(alias = "AppStateRx")]
|
||||
pub struct AppState {
|
||||
pub dark_mode: bool,
|
||||
pub config: Config,
|
||||
}
|
||||
|
||||
#[perseus::autoserde(global_build_state)]
|
||||
pub async fn get_build_state() -> RenderFnResult<AppState> {
|
||||
#[engine_only_fn]
|
||||
pub async fn get_build_state(_locale: String) -> AppState {
|
||||
use crate::env::Config;
|
||||
let config = Config::new();
|
||||
Ok(AppState {
|
||||
AppState {
|
||||
config,
|
||||
dark_mode: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue