Add simple data store
All checks were successful
Build Crate / build (push) Successful in 8m5s

This commit is contained in:
2023-09-20 00:28:16 -04:00
parent 0a1c81c44e
commit ec06340def
10 changed files with 98 additions and 13 deletions

View File

@@ -1,7 +1,6 @@
use crate::components::layout::Layout;
use perseus::prelude::*;
use serde::{Deserialize, Serialize};
use std::fs;
use sycamore::prelude::*;
// Reactive page

View File

@@ -1,7 +1,6 @@
use crate::components::layout::Layout;
use perseus::prelude::*;
use serde::{Deserialize, Serialize};
use std::fs;
use sycamore::prelude::*;
// Reactive page

View File

@@ -1,22 +1,46 @@
use crate::components::layout::Layout;
use perseus::prelude::*;
use serde::{Deserialize, Serialize};
use std::fs;
#[cfg(engine)]
use crate::data::store::DATA;
#[cfg(engine)]
use std::thread;
use sycamore::prelude::*;
use crate::data::pool_match::{
PoolMatchList, PoolMatch
};
// Reactive page
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
#[rx(alias = "PageStateRx")]
struct PageState {
matches: PoolMatchList,
}
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" }
ul {
(View::new_fragment(
state.matches.get()
.pool_matches
.iter()
.rev()
.enumerate()
.map(|(index, item)| {
let game = item.clone();
view! { cx,
li {
(game.winner)
}
}
})
.collect(),
))
}
}
}
}
@@ -26,7 +50,20 @@ async fn get_request_state(
_info: StateGeneratorInfo<()>,
req: Request,
) -> Result<PageState, BlamedError<std::convert::Infallible>> {
Ok(PageState {})
let matches = thread::spawn(move || {
let mut db = DATA.lock().unwrap();
db.matches.pool_matches.push(PoolMatch {
players: vec![],
winner: "lol".to_string(),
});
db.write();
db.matches.clone()
}).join().unwrap();
Ok(PageState {
matches
})
}
#[engine_only_fn]