Compare commits
No commits in common. "a0a3ebb856cd89a143aa0b234fd73d0806eb498a" and "8b11832c224c1850bf4f87395986c7027f9de684" have entirely different histories.
a0a3ebb856
...
8b11832c22
|
@ -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-175ab564dbb350a3_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
|
<link rel="preload" href="/index-fd3fb1b7ad6689f9_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
|
||||||
<link rel="modulepreload" href="/index-175ab564dbb350a3.js"></head>
|
<link rel="modulepreload" href="/index-fd3fb1b7ad6689f9.js"></head>
|
||||||
<body>
|
<body>
|
||||||
<script type="module">import init from '/index-175ab564dbb350a3.js';init('/index-175ab564dbb350a3_bg.wasm');</script></body></html>
|
<script type="module">import init from '/index-fd3fb1b7ad6689f9.js';init('/index-fd3fb1b7ad6689f9_bg.wasm');</script></body></html>
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{cell::RefCell, marker::PhantomData, str::FromStr};
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::components::Block;
|
use crate::components::Block;
|
||||||
use lan_party_core::event::{
|
use lan_party_core::event::{
|
||||||
|
@ -7,11 +7,11 @@ use lan_party_core::event::{
|
||||||
};
|
};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use paste::paste;
|
use paste::paste;
|
||||||
use sycamore::{builder::prelude::*, component::Prop, prelude::*};
|
use sycamore::prelude::*;
|
||||||
|
|
||||||
macro_rules! editable {
|
macro_rules! editable {
|
||||||
($type:ty => $editor:ty) => {
|
($type:ty => $editor:ty) => {
|
||||||
impl<'s: 'a, 'a, G: Html> Editable<'s, 'a, G> for $type {
|
impl<'a, G: Html> Editable<'a, G> for $type {
|
||||||
type Editor = $editor;
|
type Editor = $editor;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -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_untracked().$field.clone());)*
|
$(let $field = create_signal($cx, $state.get().$field.clone());)*
|
||||||
|
|
||||||
create_effect($cx, || {
|
create_effect($cx, || {
|
||||||
$state.set($t {
|
$state.set($t {
|
||||||
|
@ -48,7 +48,7 @@ macro_rules! edit_struct {
|
||||||
paste! {
|
paste! {
|
||||||
pub struct [<$struct Edit>];
|
pub struct [<$struct Edit>];
|
||||||
|
|
||||||
impl<'s: 'a, 'a, G: Html> Editor<'s, 'a, G, $struct> for [<$struct Edit>] {
|
impl<'a, G: Html> Editor<'a, G, $struct> for [<$struct Edit>] {
|
||||||
fn edit(cx: Scope<'a>, props: EditProps<'a, $struct>) -> View<G> {
|
fn edit(cx: Scope<'a>, props: EditProps<'a, $struct>) -> View<G> {
|
||||||
let state = props.state;
|
let state = props.state;
|
||||||
link_fields!(cx, $($prop,)* => state as $struct);
|
link_fields!(cx, $($prop,)* => state as $struct);
|
||||||
|
@ -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_untracked().as_ref().clone() {
|
$(let $var_name = if let $t::$variant(v) = $state.get().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())
|
||||||
|
@ -90,7 +90,7 @@ macro_rules! edit_enum {
|
||||||
paste! {
|
paste! {
|
||||||
pub struct [<$enum Edit>];
|
pub struct [<$enum Edit>];
|
||||||
|
|
||||||
impl<'s: 'a, 'a, G: Html> Editor<'s, 'a, G, $enum> for [<$enum Edit>] {
|
impl<'a, G: Html> Editor<'a, G, $enum> for [<$enum Edit>] {
|
||||||
fn edit(cx: Scope<'a>, props: EditProps<'a, $enum>) -> View<G> {
|
fn edit(cx: Scope<'a>, props: EditProps<'a, $enum>) -> View<G> {
|
||||||
let state = props.state;
|
let state = props.state;
|
||||||
|
|
||||||
|
@ -104,9 +104,8 @@ 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 $selected.get().as_str() {
|
(match state.get().as_ref().clone() {
|
||||||
$(stringify!($index) => $var_name.edit(cx),)*
|
$($enum::$variant(_) => $var_name.edit(cx),)*
|
||||||
_ => unreachable!()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,40 +128,35 @@ impl<'a, T> From<&'a Signal<T>> for EditProps<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait IntoEdit<'s: 'a, 'a, G: Html> {
|
pub trait IntoEdit<'a, G: Html> {
|
||||||
fn edit(self, cx: BoundedScope<'a, 's>) -> View<G>;
|
fn edit(self, cx: Scope<'a>) -> View<G>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'s: 'a, 'a, G: Html, T: Editable<'s, 'a, G> + 'a> IntoEdit<'s, 'a, G> for &'a Signal<T>
|
impl<'a, G: Html, T: Editable<'a, G>> IntoEdit<'a, G> for &'a Signal<T>
|
||||||
where
|
where
|
||||||
EditProps<'a, T>: From<&'a Signal<T>>,
|
EditProps<'a, T>: From<&'a Signal<T>>,
|
||||||
{
|
{
|
||||||
fn edit(self, cx: BoundedScope<'a, 's>) -> View<G> {
|
fn edit(self, cx: Scope<'a>) -> View<G> {
|
||||||
T::edit(cx, self.into())
|
T::edit(cx, self.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Edit<'s: 'a, 'a, G: Html>: Sized {
|
pub trait Edit<'a, G: Html>: Sized {
|
||||||
fn edit(cx: BoundedScope<'a, 's>, props: EditProps<'a, Self>) -> View<G>;
|
fn edit(cx: Scope<'a>, props: EditProps<'a, Self>) -> View<G>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'s: 'a, 'a, G, E, Type> Edit<'s, 'a, G> for Type
|
impl<'a, G: Html, E: Editor<'a, G, Type>, Type: Editable<'a, G, Editor = E>> Edit<'a, G> for Type {
|
||||||
where
|
fn edit(cx: Scope<'a>, props: EditProps<'a, Self>) -> View<G> {
|
||||||
G: Html,
|
|
||||||
E: Editor<'s, 'a, G, Type>,
|
|
||||||
Type: Editable<'s, 'a, G, Editor = E> + 'a,
|
|
||||||
{
|
|
||||||
fn edit(cx: BoundedScope<'a, 's>, props: EditProps<'a, Self>) -> View<G> {
|
|
||||||
E::edit(cx, props)
|
E::edit(cx, props)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Editor<'s: 'a, 'a, G: Html, Type: 'a>: Sized {
|
pub trait Editor<'a, G: Html, Type>: Sized {
|
||||||
fn edit(cx: BoundedScope<'a, 's>, props: EditProps<'a, Type>) -> View<G>;
|
fn edit(cx: Scope<'a>, props: EditProps<'a, Type>) -> View<G>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Editable<'s: 'a, 'a, G: Html>: Sized + 'a {
|
pub trait Editable<'a, G: Html>: Sized {
|
||||||
type Editor: Editor<'s, 'a, G, Self>;
|
type Editor: Editor<'a, G, Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
edit_struct!(EventSpec => ("Name", name), ("Description", description), ("Event type", event_type));
|
edit_struct!(EventSpec => ("Name", name), ("Description", description), ("Event type", event_type));
|
||||||
|
@ -174,12 +168,12 @@ edit_enum!(EventTypeSpec => selected =>
|
||||||
);
|
);
|
||||||
|
|
||||||
edit_struct!(TestSpec => ("Number of players", num_players));
|
edit_struct!(TestSpec => ("Number of players", num_players));
|
||||||
edit_struct!(TeamGameSpec => ("Win rewards", win_rewards));
|
edit_struct!(TeamGameSpec => );
|
||||||
edit_struct!(FreeForAllGameSpec => );
|
edit_struct!(FreeForAllGameSpec => );
|
||||||
|
|
||||||
pub struct StringEdit;
|
pub struct StringEdit;
|
||||||
|
|
||||||
impl<'s: 'a, 'a, G: Html> Editor<'s, 'a, G, String> for StringEdit {
|
impl<'a, G: Html> Editor<'a, G, String> for StringEdit {
|
||||||
fn edit(cx: Scope<'a>, props: EditProps<'a, String>) -> View<G> {
|
fn edit(cx: Scope<'a>, props: EditProps<'a, String>) -> View<G> {
|
||||||
view! { cx,
|
view! { cx,
|
||||||
input(bind:value=props.state)
|
input(bind:value=props.state)
|
||||||
|
@ -191,9 +185,9 @@ editable!(String => StringEdit);
|
||||||
|
|
||||||
pub struct StubEdit;
|
pub struct StubEdit;
|
||||||
|
|
||||||
impl<'s: 'a, 'a, G: Html, T> Editor<'s, 'a, G, T> for StubEdit
|
impl<'a, G: Html, T> Editor<'a, G, T> for StubEdit
|
||||||
where
|
where
|
||||||
T: Editable<'s, 'a, G, Editor = StubEdit>,
|
T: Editable<'a, G, Editor = StubEdit>,
|
||||||
{
|
{
|
||||||
fn edit(cx: Scope<'a>, _props: EditProps<'a, T>) -> View<G> {
|
fn edit(cx: Scope<'a>, _props: EditProps<'a, T>) -> View<G> {
|
||||||
view! { cx,
|
view! { cx,
|
||||||
|
@ -202,14 +196,16 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//editable!(EventTypeSpec => StubEdit);
|
||||||
|
|
||||||
pub struct InputEdit;
|
pub struct InputEdit;
|
||||||
|
|
||||||
impl<'s: 'a, 'a, G: Html, T> Editor<'s, 'a, G, T> for InputEdit
|
impl<'a, G: Html, T> Editor<'a, G, T> for InputEdit
|
||||||
where
|
where
|
||||||
T: Editable<'s, '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_untracked().to_string());
|
let value = create_signal(cx, props.state.get().to_string());
|
||||||
|
|
||||||
create_effect(cx, || {
|
create_effect(cx, || {
|
||||||
props
|
props
|
||||||
|
@ -236,7 +232,7 @@ editable!(f32 => InputEdit);
|
||||||
|
|
||||||
pub struct BoolEdit;
|
pub struct BoolEdit;
|
||||||
|
|
||||||
impl<'s: 'a, 'a, G: Html> Editor<'s, 'a, G, bool> for BoolEdit {
|
impl<'a, G: Html> Editor<'a, G, bool> for BoolEdit {
|
||||||
fn edit(cx: Scope<'a>, props: EditProps<'a, bool>) -> View<G> {
|
fn edit(cx: Scope<'a>, props: EditProps<'a, bool>) -> View<G> {
|
||||||
view! { cx,
|
view! { cx,
|
||||||
input(type="checkbox", bind:checked=props.state)
|
input(type="checkbox", bind:checked=props.state)
|
||||||
|
@ -246,145 +242,7 @@ impl<'s: 'a, 'a, G: Html> Editor<'s, 'a, G, bool> for BoolEdit {
|
||||||
|
|
||||||
editable!(bool => BoolEdit);
|
editable!(bool => BoolEdit);
|
||||||
|
|
||||||
pub struct VecEdit;
|
#[derive(Default, Clone)]
|
||||||
|
|
||||||
impl<'s: 'a, 'a, G, T, I> Editor<'s, 'a, G, I> for VecEdit
|
|
||||||
where
|
|
||||||
G: Html,
|
|
||||||
T: Editable<'s, 'a, G> + Clone + PartialEq + 'a,
|
|
||||||
I: IntoIterator<Item = T> + FromIterator<T> + Clone + 'a,
|
|
||||||
{
|
|
||||||
fn edit(cx: BoundedScope<'a, 's>, props: EditProps<'a, I>) -> View<G> {
|
|
||||||
let vec: &'a Signal<Vec<&'a Signal<T>>> = 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()
|
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.map(|x| x.get().as_ref().clone())
|
|
||||||
.collect(),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
let test = Indexed(
|
|
||||||
cx,
|
|
||||||
IndexedProps::builder()
|
|
||||||
.iterable(vec)
|
|
||||||
.view(|cx: BoundedScope<'_, '_>, x: &'a Signal<T>| {
|
|
||||||
//view! { cx, (T::edit(cx, EditProps { state: x })) }
|
|
||||||
T::edit(cx, EditProps { state: x })
|
|
||||||
})
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
test
|
|
||||||
|
|
||||||
/*
|
|
||||||
//view! { cx, "Vec" }
|
|
||||||
view! { cx,
|
|
||||||
Indexed(
|
|
||||||
iterable=vec,
|
|
||||||
view=|cx: BoundedScope<'_, 'a>, x: &'a Signal<T>| {
|
|
||||||
view! { cx,
|
|
||||||
//(T::edit(cx, EditProps { state: x }))
|
|
||||||
(something_with_signal(cx, EditProps { state: x }))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
view! { cx,
|
|
||||||
(View::new_fragment((vec.get().try_borrow().unwrap().clone().into_iter().map(|s: &'a Signal<T>| {
|
|
||||||
view! { cx, (T::edit(cx, s.into())) }
|
|
||||||
})).collect()))
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
#[component]
|
|
||||||
pub fn VecTest<
|
|
||||||
'a,
|
|
||||||
G: Html,
|
|
||||||
T: 'a + PartialEq + Clone + Editable<'a, G, Editor = E>,
|
|
||||||
E: Editor<'a, G, T>,
|
|
||||||
>(
|
|
||||||
cx: Scope<'a>,
|
|
||||||
props: EditProps<'a, Vec<T>>,
|
|
||||||
) -> View<G> {
|
|
||||||
/*
|
|
||||||
let signals: &'a Signal<Vec<&'a Signal<String>>> = create_signal(
|
|
||||||
cx,
|
|
||||||
vec![
|
|
||||||
create_signal(cx, String::new()),
|
|
||||||
create_signal(cx, String::new()),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
||||||
let signals = create_signal(
|
|
||||||
cx,
|
|
||||||
props
|
|
||||||
.state
|
|
||||||
.get()
|
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.map(|s| create_signal(cx, s))
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
);
|
|
||||||
|
|
||||||
view! { cx,
|
|
||||||
Indexed(
|
|
||||||
iterable=signals,
|
|
||||||
view=|cx: BoundedScope<'_, 'a>, signal: &'a Signal<T>| {
|
|
||||||
view! { cx,
|
|
||||||
//(something_with_signal(cx, SignalWrapper(signal)))
|
|
||||||
//(E::edit(cx, EditProps { state: signal }))
|
|
||||||
//(T::edit(cx, EditProps { state: signal }))
|
|
||||||
//(signal.edit(cx))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
pub struct SignalWrapper<'a, T>(&'a Signal<T>);
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn something_with_signal<'a, G: Html, T: 'a>(
|
|
||||||
cx: Scope<'a>,
|
|
||||||
signal: EditProps<'a, T>,
|
|
||||||
) -> View<G> {
|
|
||||||
drop(signal);
|
|
||||||
view! { cx, "Something" }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'s: 'a, 'a, G, T> Editable<'s, 'a, G> for Vec<T>
|
|
||||||
where
|
|
||||||
G: Html,
|
|
||||||
T: Editable<'s, '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,
|
||||||
|
@ -392,7 +250,7 @@ pub struct Test {
|
||||||
|
|
||||||
edit_struct!(Test => ("Inner", inner), ("Inner 2", inner2));
|
edit_struct!(Test => ("Inner", inner), ("Inner 2", inner2));
|
||||||
|
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone)]
|
||||||
pub struct TestInner {
|
pub struct TestInner {
|
||||||
some_text: String,
|
some_text: String,
|
||||||
some_number: usize,
|
some_number: usize,
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
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,11 +11,13 @@ 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()) {
|
||||||
(event_spec.edit(cx))
|
EventSpec::edit(EditProps { state: event_spec })
|
||||||
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