Add working API calls, fix warnings
All checks were successful
Build Crate / build (push) Successful in 7m16s
All checks were successful
Build Crate / build (push) Successful in 7m16s
This commit is contained in:
@@ -1,47 +1,70 @@
|
||||
use std::ops::Deref;
|
||||
use crate::components::layout::Layout;
|
||||
use perseus::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sycamore::prelude::*;
|
||||
use crate::data::global_state::AppStateRx;
|
||||
use web_sys::{window, Event};
|
||||
use crate::data::pool_match::PoolMatch;
|
||||
#[cfg(client)]
|
||||
use perseus::utils::get_path_prefix_client;
|
||||
use crate::templates::get_api_path;
|
||||
use web_sys::{Event};
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(client)] {
|
||||
use crate::data::pool_match::{PoolMatch, PoolMatchList};
|
||||
use crate::templates::global_state::AppStateRx;
|
||||
use crate::endpoints::MATCH;
|
||||
use crate::templates::get_api_path;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Reactive page
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, ReactiveState)]
|
||||
#[rx(alias = "PageStateRx")]
|
||||
struct PageState {}
|
||||
|
||||
struct PageState {
|
||||
name: String,
|
||||
}
|
||||
|
||||
|
||||
fn add_game_form_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 api_path = get_api_path("/api/test");
|
||||
|
||||
let handle_add_match = move |event: Event| {
|
||||
let handle_add_match = move |_event: Event| {
|
||||
#[cfg(client)]
|
||||
{
|
||||
let path = get_api_path("/api/test");
|
||||
println!("{}", path);
|
||||
spawn_local_scoped(cx, async move {
|
||||
reqwest::get(get_api_path("/api/test").as_str()).await.unwrap();
|
||||
let new_match = PoolMatch {
|
||||
players: vec![],
|
||||
winner: state.name.get().as_ref().clone(),
|
||||
};
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let new_matches = client.post(get_api_path(MATCH).as_str())
|
||||
.json(&new_match)
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.json::<PoolMatchList>()
|
||||
.await
|
||||
.unwrap();
|
||||
let global_state = Reactor::<G>::from_cx(cx).get_global_state::<AppStateRx>(cx);
|
||||
global_state.matches.set(new_matches);
|
||||
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
view! { cx,
|
||||
Layout(title = "Add Game Results") {
|
||||
// Anything we put in here will be rendered inside the `<main>` block of the layout
|
||||
button(on:click=handle_add_match) {
|
||||
"Add result"
|
||||
div (class = "flex flex-wrap") {
|
||||
input (bind:value = state.name,
|
||||
class = "appearance-none block w-full bg-gray-200 text-gray-700 border \
|
||||
border-red-500 rounded py-3 px-4 mb-3 leading-tight focus:outline-none \
|
||||
focus:bg-white",)
|
||||
}
|
||||
p {
|
||||
(api_path)
|
||||
div (class = "flex flex-wrap") {
|
||||
button(on:click = handle_add_match,
|
||||
class = "flex-shrink-0 bg-teal-500 hover:bg-teal-700 border-teal-500 \
|
||||
hover:border-teal-700 text-sm border-4 text-white py-1 px-2 rounded",
|
||||
) {
|
||||
"Add result"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,9 +73,9 @@ fn add_game_form_page<'a, G: Html>(cx: BoundedScope<'_, 'a>, state: &'a PageStat
|
||||
#[engine_only_fn]
|
||||
async fn get_request_state(
|
||||
_info: StateGeneratorInfo<()>,
|
||||
req: Request,
|
||||
_req: Request,
|
||||
) -> Result<PageState, BlamedError<std::convert::Infallible>> {
|
||||
Ok(PageState {})
|
||||
Ok(PageState { name: "Ferris".to_string() })
|
||||
}
|
||||
|
||||
#[engine_only_fn]
|
||||
|
||||
Reference in New Issue
Block a user