diff --git a/src/components/news/create.rs b/src/components/news/create.rs index 7773f1d..f6767b9 100644 --- a/src/components/news/create.rs +++ b/src/components/news/create.rs @@ -10,9 +10,35 @@ enum Steps { Done, } +#[derive(Props, Clone, PartialEq, Debug)] +struct Form { + title: Signal, + body: Signal, + targets: Signal>, +} + +impl Default for Form { + fn default() -> Self { + Self { + title: use_signal(|| String::new()), + body: use_signal(|| String::new()), + targets: use_signal(|| { + HashMap::from([( + 0, + Target { + kind: TargetKind::None, + value: String::new(), + }, + )]) + }), + } + } +} + #[component] pub fn NewsCreate() -> Element { let step = use_signal(|| Steps::Message); + let form = Form::default(); rsx! { div { @@ -40,10 +66,10 @@ pub fn NewsCreate() -> Element { div { class: "flex flex-col gap-y-5", match *step.read() { - Steps::Message => rsx! { Message { step: step } }, - Steps::Targets => rsx! { TargetSelect { step: step } }, - Steps::Verify => rsx! { Message { step: step } }, - Steps::Done => rsx! { Message { step: step } }, + Steps::Message => rsx! { Message { step: step, title: form.title, body: form.body } }, + Steps::Targets => rsx! { TargetSelect { step: step, targets: form.targets } }, + Steps::Verify => rsx! { { } }, + Steps::Done => rsx! { { } }, } } } @@ -51,10 +77,20 @@ pub fn NewsCreate() -> Element { } #[component] -fn Message(step: Signal) -> Element { +fn Message(step: Signal, title: Signal, body: Signal) -> Element { + let submit = move |event: FormEvent| { + title.set(event.values()["title"].as_value()); + body.set(event.values()["body"].as_value()); + + tracing::info!("{title}"); + + step.set(Steps::Targets); + }; + rsx! { form { class: "flex flex-col w-full gap-y-5", + onsubmit: submit, label { class: "form-control w-full", div { @@ -63,6 +99,9 @@ fn Message(step: Signal) -> Element { }, input { r#type: "text", + required: true, + name: "title", + value: "{title}", class: "input input-bordered w-full", } } @@ -73,24 +112,25 @@ fn Message(step: Signal) -> Element { span { class: "label-text", "Bericht" } }, textarea { + name: "body", + value: "{body}", class: "textarea textarea-bordered w-full", + required: true, } }, div { class: "w-full flex gap-x-3 justify-end", - button { + input { + r#type: "submit", class: "btn btn-primary", - onclick: move |_| { - step.set(Steps::Targets) - }, - "Volgende", + value: "Volgende", } } } } } -#[derive(Eq, PartialEq, Clone, Copy, Debug)] +#[derive(PartialEq, Clone, Copy, Debug)] enum TargetKind { None, All, @@ -102,7 +142,7 @@ enum TargetKind { Day, } -#[derive(Eq, PartialEq)] +#[derive(PartialEq, Debug)] struct Target { kind: TargetKind, value: String, @@ -124,17 +164,7 @@ impl TargetKind { } #[component] -fn TargetSelect(step: Signal) -> Element { - let mut targets: Signal> = use_signal(|| { - HashMap::from([( - 0, - Target { - kind: TargetKind::None, - value: String::new(), - }, - )]) - }); - +fn TargetSelect(step: Signal, targets: Signal>) -> Element { let mut target_id = use_signal(|| 1); let target_ids = use_memo(move || {