add_api #4
10
Cargo.toml
10
Cargo.toml
@@ -6,15 +6,19 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
perseus = { version = "0.4.2", features = ["hydrate"] }
|
perseus = { version = "0.4.2", features = ["hydrate"] }
|
||||||
sycamore = {version = "0.8.2", features = ["suspense", "web", "wasm-bindgen-interning",]}
|
sycamore = { version = "0.8.2", features = [
|
||||||
|
"suspense",
|
||||||
|
"web",
|
||||||
|
"wasm-bindgen-interning",
|
||||||
|
] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
once_cell = "1.18.0"
|
once_cell = "1.18.0"
|
||||||
web-sys = "0.3.64"
|
web-sys = "0.3.64"
|
||||||
cfg-if = { version = "1.0.0", features = [] }
|
cfg-if = "1.0.0"
|
||||||
|
chrono = { version = "0.4.31", features = ["serde"] }
|
||||||
|
|
||||||
[target.'cfg(engine)'.dev-dependencies]
|
[target.'cfg(engine)'.dev-dependencies]
|
||||||
fantoccini = "0.19"
|
fantoccini = "0.19"
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ use sycamore::prelude::*;
|
|||||||
|
|
||||||
#[derive(Prop)]
|
#[derive(Prop)]
|
||||||
pub struct LayoutProps<'a, G: Html> {
|
pub struct LayoutProps<'a, G: Html> {
|
||||||
/// The title of the page, which will be displayed in the header.
|
|
||||||
pub title: &'a str,
|
pub title: &'a str,
|
||||||
/// The content to put inside the layout.
|
|
||||||
pub children: Children<'a, G>,
|
pub children: Children<'a, G>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,11 +13,7 @@ pub fn Layout<'a, G: Html>(
|
|||||||
) -> View<G> {
|
) -> View<G> {
|
||||||
let children = children.call(cx);
|
let children = children.call(cx);
|
||||||
|
|
||||||
// example params
|
|
||||||
// p { (title.to_string()) }
|
|
||||||
|
|
||||||
view! { cx,
|
view! { cx,
|
||||||
// These elements are styled with bright colors for demonstration purposes
|
|
||||||
header {
|
header {
|
||||||
div (class = "flex items-center justify-between") {
|
div (class = "flex items-center justify-between") {
|
||||||
div (class = "w-full text-gray-700 md:text-center text-2xl font-semibold") {
|
div (class = "w-full text-gray-700 md:text-center text-2xl font-semibold") {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
pub mod pool_match;
|
pub mod pool_match;
|
||||||
|
pub mod user;
|
||||||
|
|
||||||
#[cfg(engine)]
|
#[cfg(engine)]
|
||||||
pub mod store;
|
pub mod store;
|
||||||
|
|||||||
@@ -1,11 +1,56 @@
|
|||||||
|
use crate::data::user::PlayerId;
|
||||||
|
use chrono::serde::ts_seconds;
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
pub type MatchId = u32;
|
||||||
pub struct PoolMatch {
|
|
||||||
pub players: Vec<String>,
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub winner: String,
|
pub enum MatchData {
|
||||||
|
Standard8Ball {
|
||||||
|
winner: PlayerId,
|
||||||
|
loser: PlayerId,
|
||||||
|
},
|
||||||
|
Standard9Ball {
|
||||||
|
winner: PlayerId,
|
||||||
|
loser: PlayerId,
|
||||||
|
},
|
||||||
|
CutThroat {
|
||||||
|
winner: PlayerId,
|
||||||
|
losers: [PlayerId; 2],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
|
pub struct PoolMatch {
|
||||||
|
pub id: MatchId,
|
||||||
|
pub data: MatchData,
|
||||||
|
#[serde(with = "ts_seconds")]
|
||||||
|
pub time: DateTime<Utc>,
|
||||||
|
}
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct PoolMatchList {
|
pub struct PoolMatchList {
|
||||||
pub pool_matches: Vec<PoolMatch>,
|
pub pool_matches: Vec<PoolMatch>,
|
||||||
|
pub max_id: MatchId,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PoolMatch {
|
||||||
|
pub fn new(data: MatchData, time: DateTime<Utc>) -> PoolMatch {
|
||||||
|
PoolMatch { id: 0, data, time }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PoolMatchList {
|
||||||
|
pub fn new() -> PoolMatchList {
|
||||||
|
PoolMatchList {
|
||||||
|
pool_matches: vec![],
|
||||||
|
max_id: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_pool_match(&mut self, mut pool_match: PoolMatch) {
|
||||||
|
pool_match.id = self.max_id + 1;
|
||||||
|
self.max_id += 1;
|
||||||
|
self.pool_matches.push(pool_match);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
|
// (Server only) In-memory data storage and persistent storage
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use std::sync::Mutex;
|
|
||||||
use serde::{Serialize, Deserialize};
|
|
||||||
use crate::data::pool_match::PoolMatchList;
|
use crate::data::pool_match::PoolMatchList;
|
||||||
use std::fs;
|
use once_cell::sync::Lazy;
|
||||||
use std::path::Path;
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::{fs, path::Path, sync::Mutex};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct Store {
|
pub struct Store {
|
||||||
@@ -16,11 +14,9 @@ impl Store {
|
|||||||
fn new() -> Store {
|
fn new() -> Store {
|
||||||
fs::create_dir_all("data").unwrap();
|
fs::create_dir_all("data").unwrap();
|
||||||
match Path::new("data/store.json").exists() {
|
match Path::new("data/store.json").exists() {
|
||||||
false => {
|
false => Store {
|
||||||
Store {
|
matches: PoolMatchList::new(),
|
||||||
matches: PoolMatchList { pool_matches: vec![] },
|
},
|
||||||
}
|
|
||||||
}
|
|
||||||
true => {
|
true => {
|
||||||
let contents = fs::read_to_string("data/store.json").unwrap();
|
let contents = fs::read_to_string("data/store.json").unwrap();
|
||||||
serde_json::from_str(&contents).unwrap()
|
serde_json::from_str(&contents).unwrap()
|
||||||
@@ -35,6 +31,4 @@ impl Store {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static DATA: Lazy<Mutex<Store>> = Lazy::new(|| {
|
pub static DATA: Lazy<Mutex<Store>> = Lazy::new(|| Mutex::new(Store::new()));
|
||||||
Mutex::new(Store::new())
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
|
|
||||||
pub const MATCH: &str = "/api/post-match";
|
pub const MATCH: &str = "/api/post-match";
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
use axum::{
|
|
||||||
extract::Json,
|
|
||||||
};
|
|
||||||
use crate::data::pool_match::{PoolMatch, PoolMatchList};
|
|
||||||
use std::thread;
|
|
||||||
use crate::data::store::DATA;
|
|
||||||
|
|
||||||
pub async fn post_match(Json(pool_match): Json<PoolMatch>) -> Json<PoolMatchList> {
|
|
||||||
// Update the store with the new match
|
|
||||||
let matches = thread::spawn(move || {
|
|
||||||
// Get the store
|
|
||||||
let mut store = DATA.lock().unwrap();
|
|
||||||
// Add the match
|
|
||||||
(*store).matches.pool_matches.push(pool_match);
|
|
||||||
// Return all pool matches
|
|
||||||
(*store).matches.clone()
|
|
||||||
}).join().unwrap();
|
|
||||||
|
|
||||||
Json(matches)
|
|
||||||
}
|
|
||||||
25
src/main.rs
25
src/main.rs
@@ -1,28 +1,26 @@
|
|||||||
mod components;
|
mod components;
|
||||||
mod templates;
|
|
||||||
mod data;
|
mod data;
|
||||||
|
mod endpoints;
|
||||||
mod error_views;
|
mod error_views;
|
||||||
#[cfg(engine)]
|
#[cfg(engine)]
|
||||||
mod handler;
|
mod server;
|
||||||
mod endpoints;
|
mod templates;
|
||||||
|
|
||||||
use perseus::prelude::*;
|
use perseus::prelude::*;
|
||||||
use sycamore::prelude::view;
|
use sycamore::prelude::view;
|
||||||
|
|
||||||
#[cfg(engine)]
|
cfg_if::cfg_if! {
|
||||||
use axum::routing::post;
|
if #[cfg(engine)] {
|
||||||
#[cfg(engine)]
|
use std::net::SocketAddr;
|
||||||
use perseus::{
|
use perseus::{
|
||||||
i18n::TranslationsManager,
|
i18n::TranslationsManager,
|
||||||
server::ServerOptions,
|
server::ServerOptions,
|
||||||
stores::MutableStore,
|
stores::MutableStore,
|
||||||
turbine::Turbine,
|
turbine::Turbine,
|
||||||
};
|
};
|
||||||
#[cfg(engine)]
|
use crate::server::routes::register_routes;
|
||||||
use crate::endpoints::MATCH;
|
}
|
||||||
#[cfg(engine)]
|
}
|
||||||
use crate::handler::post_match;
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(engine)]
|
#[cfg(engine)]
|
||||||
pub async fn dflt_server<M: MutableStore + 'static, T: TranslationsManager + 'static>(
|
pub async fn dflt_server<M: MutableStore + 'static, T: TranslationsManager + 'static>(
|
||||||
@@ -30,13 +28,12 @@ pub async fn dflt_server<M: MutableStore + 'static, T: TranslationsManager + 'st
|
|||||||
opts: ServerOptions,
|
opts: ServerOptions,
|
||||||
(host, port): (String, u16),
|
(host, port): (String, u16),
|
||||||
) {
|
) {
|
||||||
use std::net::SocketAddr;
|
|
||||||
|
|
||||||
let addr: SocketAddr = format!("{}:{}", host, port)
|
let addr: SocketAddr = format!("{}:{}", host, port)
|
||||||
.parse()
|
.parse()
|
||||||
.expect("Invalid address provided to bind to.");
|
.expect("Invalid address provided to bind to.");
|
||||||
let mut app = perseus_axum::get_router(turbine, opts).await;
|
let mut app = perseus_axum::get_router(turbine, opts).await;
|
||||||
app = app.route(MATCH, post(post_match));
|
|
||||||
|
app = register_routes(app);
|
||||||
|
|
||||||
axum::Server::bind(&addr)
|
axum::Server::bind(&addr)
|
||||||
.serve(app.into_make_service())
|
.serve(app.into_make_service())
|
||||||
|
|||||||
2
src/server/mod.rs
Normal file
2
src/server/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod routes;
|
||||||
|
|
||||||
34
src/server/routes.rs
Normal file
34
src/server/routes.rs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// (Server only) Routes
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
data::{
|
||||||
|
pool_match::{PoolMatch, PoolMatchList},
|
||||||
|
store::DATA,
|
||||||
|
},
|
||||||
|
endpoints::MATCH,
|
||||||
|
};
|
||||||
|
use axum::{
|
||||||
|
extract::Json,
|
||||||
|
routing::{post, Router},
|
||||||
|
};
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
|
pub fn register_routes(app: Router) -> Router {
|
||||||
|
let app = app.route(MATCH, post(post_match));
|
||||||
|
app
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn post_match(Json(pool_match): Json<PoolMatch>) -> Json<PoolMatchList> {
|
||||||
|
// Update the store with the new match
|
||||||
|
let matches = thread::spawn(move || {
|
||||||
|
// Get the store
|
||||||
|
let mut data = DATA.lock().unwrap();
|
||||||
|
(*data).matches.add_pool_match(pool_match);
|
||||||
|
println!("{:?}", (*data).matches.pool_matches);
|
||||||
|
(*data).matches.clone()
|
||||||
|
})
|
||||||
|
.join()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Json(matches)
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
use crate::components::layout::Layout;
|
use crate::{components::layout::Layout, data::pool_match::MatchData};
|
||||||
use perseus::prelude::*;
|
use perseus::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use web_sys::{Event};
|
use web_sys::Event;
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(client)] {
|
if #[cfg(client)] {
|
||||||
@@ -10,10 +10,10 @@ cfg_if::cfg_if! {
|
|||||||
use crate::templates::global_state::AppStateRx;
|
use crate::templates::global_state::AppStateRx;
|
||||||
use crate::endpoints::MATCH;
|
use crate::endpoints::MATCH;
|
||||||
use crate::templates::get_api_path;
|
use crate::templates::get_api_path;
|
||||||
|
use chrono::Utc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Reactive page
|
// Reactive page
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
||||||
@@ -22,20 +22,16 @@ struct PageState {
|
|||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn add_game_form_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStateRx) -> View<G> {
|
fn add_game_form_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStateRx) -> View<G> {
|
||||||
|
|
||||||
let handle_add_match = move |_event: Event| {
|
let handle_add_match = move |_event: Event| {
|
||||||
#[cfg(client)]
|
#[cfg(client)]
|
||||||
{
|
{
|
||||||
|
// state.name.get().as_ref().clone()
|
||||||
spawn_local_scoped(cx, async move {
|
spawn_local_scoped(cx, async move {
|
||||||
let new_match = PoolMatch {
|
let new_match = PoolMatch::new(MatchData::Standard8Ball { winner: 1, loser: 2 }, Utc::now());
|
||||||
players: vec![],
|
|
||||||
winner: state.name.get().as_ref().clone(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let new_matches = client.post(get_api_path(MATCH).as_str())
|
let new_matches = client
|
||||||
|
.post(get_api_path(MATCH).as_str())
|
||||||
.json(&new_match)
|
.json(&new_match)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
@@ -45,7 +41,6 @@ fn add_game_form_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStat
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
|
let global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
|
||||||
global_state.matches.set(new_matches);
|
global_state.matches.set(new_matches);
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -75,7 +70,9 @@ async fn get_request_state(
|
|||||||
_info: StateGeneratorInfo<()>,
|
_info: StateGeneratorInfo<()>,
|
||||||
_req: Request,
|
_req: Request,
|
||||||
) -> Result<PageState, BlamedError<std::convert::Infallible>> {
|
) -> Result<PageState, BlamedError<std::convert::Infallible>> {
|
||||||
Ok(PageState { name: "Ferris".to_string() })
|
Ok(PageState {
|
||||||
|
name: "Ferris".to_string(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[engine_only_fn]
|
#[engine_only_fn]
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// Not a page, global state that is shared between all pages
|
||||||
|
|
||||||
|
use crate::data::pool_match::PoolMatchList;
|
||||||
use perseus::{prelude::*, state::GlobalStateCreator};
|
use perseus::{prelude::*, state::GlobalStateCreator};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@@ -5,12 +8,9 @@ cfg_if::cfg_if! {
|
|||||||
if #[cfg(engine)] {
|
if #[cfg(engine)] {
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(engine)]
|
|
||||||
use crate::data::store::DATA;
|
use crate::data::store::DATA;
|
||||||
use crate::data::pool_match::PoolMatchList;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, ReactiveState, Clone)]
|
#[derive(Serialize, Deserialize, ReactiveState, Clone)]
|
||||||
#[rx(alias = "AppStateRx")]
|
#[rx(alias = "AppStateRx")]
|
||||||
@@ -26,15 +26,12 @@ pub fn get_global_state_creator() -> GlobalStateCreator {
|
|||||||
|
|
||||||
#[engine_only_fn]
|
#[engine_only_fn]
|
||||||
fn get_state() -> AppState {
|
fn get_state() -> AppState {
|
||||||
let matches = thread::spawn(move || {
|
let matches = thread::spawn(move || DATA.lock().unwrap().deref().matches.clone())
|
||||||
DATA.lock().unwrap().deref().matches.clone()
|
.join()
|
||||||
}).join().unwrap();
|
.unwrap();
|
||||||
|
|
||||||
AppState {
|
AppState { matches }
|
||||||
matches
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[engine_only_fn]
|
#[engine_only_fn]
|
||||||
pub async fn get_build_state() -> AppState {
|
pub async fn get_build_state() -> AppState {
|
||||||
|
|||||||
@@ -20,8 +20,5 @@ fn head(cx: Scope) -> View<SsrNode> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_template<G: Html>() -> Template<G> {
|
pub fn get_template<G: Html>() -> Template<G> {
|
||||||
Template::build("")
|
Template::build("").view(index_page).head(head).build()
|
||||||
.view(index_page)
|
|
||||||
.head(head)
|
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
pub mod index;
|
|
||||||
pub mod add_game_form;
|
pub mod add_game_form;
|
||||||
|
pub mod global_state;
|
||||||
|
pub mod index;
|
||||||
pub mod one_v_one_board;
|
pub mod one_v_one_board;
|
||||||
pub mod overall_board;
|
pub mod overall_board;
|
||||||
pub mod global_state;
|
|
||||||
|
|
||||||
#[cfg(client)]
|
#[cfg(client)]
|
||||||
use perseus::utils::get_path_prefix_client;
|
use perseus::utils::get_path_prefix_client;
|
||||||
|
|||||||
@@ -3,18 +3,13 @@ use perseus::prelude::*;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
|
|
||||||
// Reactive page
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
||||||
#[rx(alias = "PageStateRx")]
|
#[rx(alias = "PageStateRx")]
|
||||||
struct PageState {
|
struct PageState {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fn one_v_one_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, _state: &'a PageStateRx) -> View<G> {
|
fn one_v_one_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, _state: &'a PageStateRx) -> View<G> {
|
||||||
view! { cx,
|
view! { cx,
|
||||||
Layout(title = "1v1 Leaderboard") {
|
Layout(title = "1v1 Leaderboard") {
|
||||||
// Anything we put in here will be rendered inside the `<main>` block of the layout
|
|
||||||
p { "leaderboard" }
|
p { "leaderboard" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,9 +30,6 @@ fn head(cx: Scope) -> View<SsrNode> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Template
|
|
||||||
|
|
||||||
pub fn get_template<G: Html>() -> Template<G> {
|
pub fn get_template<G: Html>() -> Template<G> {
|
||||||
Template::build("one-v-one-board")
|
Template::build("one-v-one-board")
|
||||||
.request_state_fn(get_request_state)
|
.request_state_fn(get_request_state)
|
||||||
|
|||||||
@@ -1,23 +1,18 @@
|
|||||||
use crate::components::layout::Layout;
|
use crate::{components::layout::Layout, templates::global_state::AppStateRx};
|
||||||
|
|
||||||
use perseus::prelude::*;
|
use perseus::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use crate::templates::global_state::AppStateRx;
|
|
||||||
|
|
||||||
// Reactive page
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
||||||
#[rx(alias = "PageStateRx")]
|
#[rx(alias = "PageStateRx")]
|
||||||
struct PageState {
|
struct PageState {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fn overall_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, _state: &'a PageStateRx) -> View<G> {
|
fn overall_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, _state: &'a PageStateRx) -> View<G> {
|
||||||
let global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
|
let global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
|
||||||
|
|
||||||
view! { cx,
|
view! { cx,
|
||||||
Layout(title = "Overall Leaderboard") {
|
Layout(title = "Overall Leaderboard") {
|
||||||
// Anything we put in here will be rendered inside the `<main>` block of the layout
|
|
||||||
ul {
|
ul {
|
||||||
(View::new_fragment(
|
(View::new_fragment(
|
||||||
global_state.matches.get()
|
global_state.matches.get()
|
||||||
@@ -29,7 +24,7 @@ fn overall_board_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, _state: &'a PageSta
|
|||||||
let game = item.clone();
|
let game = item.clone();
|
||||||
view! { cx,
|
view! { cx,
|
||||||
li {
|
li {
|
||||||
(game.winner)
|
(game.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -55,9 +50,6 @@ fn head(cx: Scope) -> View<SsrNode> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Template
|
|
||||||
|
|
||||||
pub fn get_template<G: Html>() -> Template<G> {
|
pub fn get_template<G: Html>() -> Template<G> {
|
||||||
Template::build("overall-board")
|
Template::build("overall-board")
|
||||||
.request_state_fn(get_request_state)
|
.request_state_fn(get_request_state)
|
||||||
|
|||||||
Reference in New Issue
Block a user