Temp
This commit is contained in:
parent
8b11832c22
commit
30d96df00a
|
@ -6,7 +6,7 @@
|
||||||
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@6.9.96/css/materialdesignicons.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@6.9.96/css/materialdesignicons.min.css" rel="stylesheet">
|
||||||
<title>LAN Party</title>
|
<title>LAN Party</title>
|
||||||
|
|
||||||
<link rel="preload" href="/index-fd3fb1b7ad6689f9_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
|
<link rel="preload" href="/index-a2c5ffc914f34da_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
|
||||||
<link rel="modulepreload" href="/index-fd3fb1b7ad6689f9.js"></head>
|
<link rel="modulepreload" href="/index-a2c5ffc914f34da.js"></head>
|
||||||
<body>
|
<body>
|
||||||
<script type="module">import init from '/index-fd3fb1b7ad6689f9.js';init('/index-fd3fb1b7ad6689f9_bg.wasm');</script></body></html>
|
<script type="module">import init from '/index-a2c5ffc914f34da.js';init('/index-a2c5ffc914f34da_bg.wasm');</script></body></html>
|
|
@ -1,4 +1,4 @@
|
||||||
use std::str::FromStr;
|
use std::{marker::PhantomData, str::FromStr};
|
||||||
|
|
||||||
use crate::components::Block;
|
use crate::components::Block;
|
||||||
use lan_party_core::event::{
|
use lan_party_core::event::{
|
||||||
|
@ -32,7 +32,7 @@ macro_rules! edit_fields {
|
||||||
|
|
||||||
macro_rules! link_fields {
|
macro_rules! link_fields {
|
||||||
($cx:ident, $($field:ident),* $(,)? => $state:ident as $t:ident) => {
|
($cx:ident, $($field:ident),* $(,)? => $state:ident as $t:ident) => {
|
||||||
$(let $field = create_signal($cx, $state.get().$field.clone());)*
|
$(let $field = create_signal($cx, $state.get_untracked().$field.clone());)*
|
||||||
|
|
||||||
create_effect($cx, || {
|
create_effect($cx, || {
|
||||||
$state.set($t {
|
$state.set($t {
|
||||||
|
@ -69,7 +69,7 @@ macro_rules! link_variants {
|
||||||
($cx:ident, $selected:ident => $($index:literal: $var_name:ident = $variant:ident: $var_type:ty),* $(,)? => $state:ident as $t:ident) => {
|
($cx:ident, $selected:ident => $($index:literal: $var_name:ident = $variant:ident: $var_type:ty),* $(,)? => $state:ident as $t:ident) => {
|
||||||
let $selected = create_signal($cx, String::from("0"));
|
let $selected = create_signal($cx, String::from("0"));
|
||||||
|
|
||||||
$(let $var_name = if let $t::$variant(v) = $state.get().as_ref().clone() {
|
$(let $var_name = if let $t::$variant(v) = $state.get_untracked().as_ref().clone() {
|
||||||
create_signal($cx, v.clone())
|
create_signal($cx, v.clone())
|
||||||
} else {
|
} else {
|
||||||
create_signal($cx, <$var_type>::default())
|
create_signal($cx, <$var_type>::default())
|
||||||
|
@ -104,8 +104,9 @@ macro_rules! edit_enum {
|
||||||
select(bind:value=$selected) {
|
select(bind:value=$selected) {
|
||||||
$(option(value={stringify!($index)}, selected=$index==0) { (stringify!($variant)) })*
|
$(option(value={stringify!($index)}, selected=$index==0) { (stringify!($variant)) })*
|
||||||
}
|
}
|
||||||
(match state.get().as_ref().clone() {
|
(match $selected.get().as_str() {
|
||||||
$($enum::$variant(_) => $var_name.edit(cx),)*
|
$(stringify!($index) => $var_name.edit(cx),)*
|
||||||
|
_ => unreachable!()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +146,12 @@ pub trait Edit<'a, G: Html>: Sized {
|
||||||
fn edit(cx: Scope<'a>, props: EditProps<'a, Self>) -> View<G>;
|
fn edit(cx: Scope<'a>, props: EditProps<'a, Self>) -> View<G>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, G: Html, E: Editor<'a, G, Type>, Type: Editable<'a, G, Editor = E>> Edit<'a, G> for Type {
|
impl<'a, G, E, Type> Edit<'a, G> for Type
|
||||||
|
where
|
||||||
|
G: Html,
|
||||||
|
E: Editor<'a, G, Type>,
|
||||||
|
Type: Editable<'a, G, Editor = E>,
|
||||||
|
{
|
||||||
fn edit(cx: Scope<'a>, props: EditProps<'a, Self>) -> View<G> {
|
fn edit(cx: Scope<'a>, props: EditProps<'a, Self>) -> View<G> {
|
||||||
E::edit(cx, props)
|
E::edit(cx, props)
|
||||||
}
|
}
|
||||||
|
@ -168,7 +174,7 @@ edit_enum!(EventTypeSpec => selected =>
|
||||||
);
|
);
|
||||||
|
|
||||||
edit_struct!(TestSpec => ("Number of players", num_players));
|
edit_struct!(TestSpec => ("Number of players", num_players));
|
||||||
edit_struct!(TeamGameSpec => );
|
edit_struct!(TeamGameSpec => ("Win rewards", win_rewards));
|
||||||
edit_struct!(FreeForAllGameSpec => );
|
edit_struct!(FreeForAllGameSpec => );
|
||||||
|
|
||||||
pub struct StringEdit;
|
pub struct StringEdit;
|
||||||
|
@ -196,8 +202,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//editable!(EventTypeSpec => StubEdit);
|
|
||||||
|
|
||||||
pub struct InputEdit;
|
pub struct InputEdit;
|
||||||
|
|
||||||
impl<'a, G: Html, T> Editor<'a, G, T> for InputEdit
|
impl<'a, G: Html, T> Editor<'a, G, T> for InputEdit
|
||||||
|
@ -205,7 +209,7 @@ where
|
||||||
T: Editable<'a, G, Editor = InputEdit> + FromStr + ToString + Default,
|
T: Editable<'a, G, Editor = InputEdit> + FromStr + ToString + Default,
|
||||||
{
|
{
|
||||||
fn edit(cx: Scope<'a>, props: EditProps<'a, T>) -> View<G> {
|
fn edit(cx: Scope<'a>, props: EditProps<'a, T>) -> View<G> {
|
||||||
let value = create_signal(cx, props.state.get().to_string());
|
let value = create_signal(cx, props.state.get_untracked().to_string());
|
||||||
|
|
||||||
create_effect(cx, || {
|
create_effect(cx, || {
|
||||||
props
|
props
|
||||||
|
@ -242,7 +246,66 @@ impl<'a, G: Html> Editor<'a, G, bool> for BoolEdit {
|
||||||
|
|
||||||
editable!(bool => BoolEdit);
|
editable!(bool => BoolEdit);
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
pub struct VecEdit;
|
||||||
|
|
||||||
|
impl<'a, G, T, I> Editor<'a, G, I> for VecEdit
|
||||||
|
where
|
||||||
|
G: Html,
|
||||||
|
T: Editable<'a, G> + Clone + PartialEq + 'a,
|
||||||
|
I: IntoIterator<Item = T> + FromIterator<T> + Clone,
|
||||||
|
{
|
||||||
|
fn edit(cx: Scope<'a>, props: EditProps<'a, I>) -> View<G> {
|
||||||
|
let vec = create_signal(
|
||||||
|
cx,
|
||||||
|
props
|
||||||
|
.state
|
||||||
|
.get_untracked()
|
||||||
|
.as_ref()
|
||||||
|
.clone()
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| create_signal(cx, x))
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
);
|
||||||
|
//let signal = create_signal(cx, 0);
|
||||||
|
//let vec2 = vec.get().as_ref().clone();
|
||||||
|
//let signal = create_ref(cx, vec.get(0).unwrap());
|
||||||
|
|
||||||
|
create_effect(cx, || {
|
||||||
|
props.state.set(
|
||||||
|
vec.get()
|
||||||
|
.as_ref()
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.map(|x| x.get().as_ref().clone())
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
view! { cx,
|
||||||
|
Indexed(
|
||||||
|
iterable=vec,
|
||||||
|
view=|cx: BoundedScope<'_, 'a>, x| {
|
||||||
|
let signal = create_ref(cx, x);
|
||||||
|
view! { cx,
|
||||||
|
(T::edit(cx, x.into()))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, G, T> Editable<'a, G> for Vec<T>
|
||||||
|
where
|
||||||
|
G: Html,
|
||||||
|
T: Editable<'a, G> + Clone + PartialEq + 'a,
|
||||||
|
{
|
||||||
|
type Editor = VecEdit;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Clone, Debug)]
|
||||||
pub struct Test {
|
pub struct Test {
|
||||||
inner: TestInner,
|
inner: TestInner,
|
||||||
inner2: TestInner,
|
inner2: TestInner,
|
||||||
|
@ -250,7 +313,7 @@ pub struct Test {
|
||||||
|
|
||||||
edit_struct!(Test => ("Inner", inner), ("Inner 2", inner2));
|
edit_struct!(Test => ("Inner", inner), ("Inner 2", inner2));
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone, Debug)]
|
||||||
pub struct TestInner {
|
pub struct TestInner {
|
||||||
some_text: String,
|
some_text: String,
|
||||||
some_number: usize,
|
some_number: usize,
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
pub mod event;
|
pub mod event;
|
||||||
|
|
||||||
|
use log::debug;
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use web_sys::Event;
|
use web_sys::Event;
|
||||||
|
use yew::use_effect;
|
||||||
|
|
||||||
#[derive(Prop)]
|
#[derive(Prop)]
|
||||||
pub struct Props<F: FnMut(Event)> {
|
pub struct Props<F: FnMut(Event)> {
|
||||||
|
|
|
@ -11,13 +11,11 @@ use crate::components::{
|
||||||
#[component]
|
#[component]
|
||||||
pub fn EventsPage<'a, G: Html>(cx: Scope<'a>) -> View<G> {
|
pub fn EventsPage<'a, G: Html>(cx: Scope<'a>) -> View<G> {
|
||||||
let event_spec = create_signal(cx, EventSpec::default());
|
let event_spec = create_signal(cx, EventSpec::default());
|
||||||
let test = create_signal(cx, Test::default());
|
|
||||||
|
|
||||||
view! { cx,
|
view! { cx,
|
||||||
Block(title="Create new event".into()) {
|
Block(title="Create new event".into()) {
|
||||||
EventSpec::edit(EditProps { state: event_spec })
|
(event_spec.edit(cx))
|
||||||
Button(icon="mdi-check".into(), onclick=move |_| debug!("{:#?}", event_spec.get()))
|
Button(icon="mdi-check".into(), onclick=move |_| debug!("{:#?}", event_spec.get()))
|
||||||
(test.edit(cx))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue