Added form struct
This commit is contained in:
parent
64e04063a7
commit
ec195dfbf7
@ -10,9 +10,35 @@ enum Steps {
|
||||
Done,
|
||||
}
|
||||
|
||||
#[derive(Props, Clone, PartialEq, Debug)]
|
||||
struct Form {
|
||||
title: Signal<String>,
|
||||
body: Signal<String>,
|
||||
targets: Signal<HashMap<u32, Target>>,
|
||||
}
|
||||
|
||||
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<Steps>) -> Element {
|
||||
fn Message(step: Signal<Steps>, title: Signal<String>, body: Signal<String>) -> 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<Steps>) -> 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<Steps>) -> 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<Steps>) -> Element {
|
||||
let mut targets: Signal<HashMap<u32, Target>> = use_signal(|| {
|
||||
HashMap::from([(
|
||||
0,
|
||||
Target {
|
||||
kind: TargetKind::None,
|
||||
value: String::new(),
|
||||
},
|
||||
)])
|
||||
});
|
||||
|
||||
fn TargetSelect(step: Signal<Steps>, targets: Signal<HashMap<u32, Target>>) -> Element {
|
||||
let mut target_id = use_signal(|| 1);
|
||||
|
||||
let target_ids = use_memo(move || {
|
||||
|
Loading…
Reference in New Issue
Block a user