Add example pages and remove dead code
All checks were successful
Build Crate / build (push) Successful in 4m41s
All checks were successful
Build Crate / build (push) Successful in 4m41s
This commit is contained in:
48
src/templates/add_game_form.rs
Normal file
48
src/templates/add_game_form.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use crate::components::layout::Layout;
|
||||
use perseus::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use sycamore::prelude::*;
|
||||
|
||||
// Reactive page
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
||||
#[rx(alias = "PageStateRx")]
|
||||
struct PageState {
|
||||
|
||||
}
|
||||
|
||||
fn add_game_form_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStateRx) -> View<G> {
|
||||
view! { cx,
|
||||
Layout(title = "Add Game Results") {
|
||||
// Anything we put in here will be rendered inside the `<main>` block of the layout
|
||||
p { "Results" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[engine_only_fn]
|
||||
async fn get_request_state(
|
||||
_info: StateGeneratorInfo<()>,
|
||||
req: Request,
|
||||
) -> Result<PageState, BlamedError<std::convert::Infallible>> {
|
||||
Ok(PageState {})
|
||||
}
|
||||
|
||||
#[engine_only_fn]
|
||||
fn head(cx: Scope) -> View<SsrNode> {
|
||||
view! { cx,
|
||||
title { "Add Game Form" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Template
|
||||
|
||||
pub fn get_template<G: Html>() -> Template<G> {
|
||||
Template::build("add-game-form")
|
||||
.request_state_fn(get_request_state)
|
||||
.view_with_state(add_game_form_page)
|
||||
.head(head)
|
||||
.build()
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::components::layout::Layout;
|
||||
use perseus::prelude::*;
|
||||
use sycamore::prelude::*;
|
||||
use crate::templates::get_path;
|
||||
|
||||
fn index_page<G: Html>(cx: Scope) -> View<G> {
|
||||
view! { cx,
|
||||
@@ -9,7 +8,6 @@ fn index_page<G: Html>(cx: Scope) -> View<G> {
|
||||
// Anything we put in here will be rendered inside the `<main>` block of the layout
|
||||
p { "Hello World!" }
|
||||
br {}
|
||||
a(href = "long") { "Long page" }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +20,7 @@ fn head(cx: Scope) -> View<SsrNode> {
|
||||
}
|
||||
|
||||
pub fn get_template<G: Html>() -> Template<G> {
|
||||
Template::build(get_path("").as_str())
|
||||
Template::build("")
|
||||
.view(index_page)
|
||||
.head(head)
|
||||
.build()
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
use crate::components::layout::Layout;
|
||||
use perseus::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use sycamore::prelude::*;
|
||||
use crate::templates::get_path;
|
||||
|
||||
// Reactive page
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
||||
#[rx(alias = "PageStateRx")]
|
||||
struct PageState {
|
||||
ip: String,
|
||||
text: String,
|
||||
}
|
||||
|
||||
fn request_state_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStateRx) -> View<G> {
|
||||
view! { cx,
|
||||
p {
|
||||
(
|
||||
format!("Your IP address is {}.", state.ip.get())
|
||||
)
|
||||
}
|
||||
p {
|
||||
(
|
||||
state.text.get().repeat(5000)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[engine_only_fn]
|
||||
async fn get_request_state(
|
||||
_info: StateGeneratorInfo<()>,
|
||||
req: Request,
|
||||
) -> Result<PageState, BlamedError<std::convert::Infallible>> {
|
||||
let text = fs::read_to_string("static/test.txt")
|
||||
.unwrap_or("~".to_string())
|
||||
.parse()
|
||||
.unwrap();
|
||||
|
||||
Ok(PageState {
|
||||
ip: format!(
|
||||
"{:?}",
|
||||
req.headers()
|
||||
// NOTE: This header can be trivially spoofed, and may well not be the user's actual
|
||||
// IP address
|
||||
.get("X-Forwarded-For")
|
||||
.unwrap_or(&perseus::http::HeaderValue::from_str("hidden from view!").unwrap())
|
||||
),
|
||||
text,
|
||||
})
|
||||
}
|
||||
|
||||
// Regular page
|
||||
|
||||
fn long_page<G: Html>(cx: Scope) -> View<G> {
|
||||
view! { cx,
|
||||
Layout(title = "Long") {
|
||||
// Anything we put in here will be rendered inside the `<main>` block of the layout
|
||||
a(href = "") { "Index" }
|
||||
br {}
|
||||
p {
|
||||
("This is a test. ".repeat(5000))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[engine_only_fn]
|
||||
fn head(cx: Scope) -> View<SsrNode> {
|
||||
view! { cx,
|
||||
title { "Long Page" }
|
||||
}
|
||||
}
|
||||
|
||||
// Template
|
||||
|
||||
pub fn get_template<G: Html>() -> Template<G> {
|
||||
// Template::build(get_full_path("long")).view(long_page).head(head).build()
|
||||
Template::build(get_path("long").as_str())
|
||||
.request_state_fn(get_request_state)
|
||||
.view_with_state(request_state_page)
|
||||
.head(head)
|
||||
.build()
|
||||
}
|
||||
@@ -1,17 +1,4 @@
|
||||
use std::env;
|
||||
|
||||
pub mod index;
|
||||
pub mod long;
|
||||
|
||||
pub fn get_path(path: &str) -> String {
|
||||
// Get base path
|
||||
match env::var("PERSEUS_BASE_PATH") {
|
||||
Ok(env_path) => {
|
||||
// Strip the slash on both sides for directory consistency
|
||||
// let stripped_env = env_path.trim_start_matches("/").trim_end_matches("/");
|
||||
// format!("{stripped_env}/{path}").to_string().trim_end_matches("/").to_owned()
|
||||
path.to_owned()
|
||||
}
|
||||
Err(_) => path.to_owned(),
|
||||
}
|
||||
}
|
||||
pub mod add_game_form;
|
||||
pub mod one_v_one_board;
|
||||
pub mod overall_board;
|
||||
|
||||
48
src/templates/one_v_one_board.rs
Normal file
48
src/templates/one_v_one_board.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use crate::components::layout::Layout;
|
||||
use perseus::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use sycamore::prelude::*;
|
||||
|
||||
// Reactive page
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
||||
#[rx(alias = "PageStateRx")]
|
||||
struct PageState {
|
||||
|
||||
}
|
||||
|
||||
fn one_v_one_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStateRx) -> View<G> {
|
||||
view! { cx,
|
||||
Layout(title = "1v1 Leaderboard") {
|
||||
// Anything we put in here will be rendered inside the `<main>` block of the layout
|
||||
p { "leaderboard" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[engine_only_fn]
|
||||
async fn get_request_state(
|
||||
_info: StateGeneratorInfo<()>,
|
||||
req: Request,
|
||||
) -> Result<PageState, BlamedError<std::convert::Infallible>> {
|
||||
Ok(PageState {})
|
||||
}
|
||||
|
||||
#[engine_only_fn]
|
||||
fn head(cx: Scope) -> View<SsrNode> {
|
||||
view! { cx,
|
||||
title { "1v1 Leaderboard" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Template
|
||||
|
||||
pub fn get_template<G: Html>() -> Template<G> {
|
||||
Template::build("one-v-one-board")
|
||||
.request_state_fn(get_request_state)
|
||||
.view_with_state(one_v_one_board_page)
|
||||
.head(head)
|
||||
.build()
|
||||
}
|
||||
48
src/templates/overall_board.rs
Normal file
48
src/templates/overall_board.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use crate::components::layout::Layout;
|
||||
use perseus::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use sycamore::prelude::*;
|
||||
|
||||
// Reactive page
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
||||
#[rx(alias = "PageStateRx")]
|
||||
struct PageState {
|
||||
|
||||
}
|
||||
|
||||
fn overall_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStateRx) -> View<G> {
|
||||
view! { cx,
|
||||
Layout(title = "Overall Leaderboard") {
|
||||
// Anything we put in here will be rendered inside the `<main>` block of the layout
|
||||
p { "leaderboard" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[engine_only_fn]
|
||||
async fn get_request_state(
|
||||
_info: StateGeneratorInfo<()>,
|
||||
req: Request,
|
||||
) -> Result<PageState, BlamedError<std::convert::Infallible>> {
|
||||
Ok(PageState {})
|
||||
}
|
||||
|
||||
#[engine_only_fn]
|
||||
fn head(cx: Scope) -> View<SsrNode> {
|
||||
view! { cx,
|
||||
title { "Overall leaderboard" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Template
|
||||
|
||||
pub fn get_template<G: Html>() -> Template<G> {
|
||||
Template::build("overall-board")
|
||||
.request_state_fn(get_request_state)
|
||||
.view_with_state(overall_board_page)
|
||||
.head(head)
|
||||
.build()
|
||||
}
|
||||
Reference in New Issue
Block a user