Added form struct
This commit is contained in:
parent
64e04063a7
commit
ec195dfbf7
@ -10,9 +10,35 @@ enum Steps {
|
|||||||
Done,
|
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]
|
#[component]
|
||||||
pub fn NewsCreate() -> Element {
|
pub fn NewsCreate() -> Element {
|
||||||
let step = use_signal(|| Steps::Message);
|
let step = use_signal(|| Steps::Message);
|
||||||
|
let form = Form::default();
|
||||||
|
|
||||||
rsx! {
|
rsx! {
|
||||||
div {
|
div {
|
||||||
@ -40,10 +66,10 @@ pub fn NewsCreate() -> Element {
|
|||||||
div {
|
div {
|
||||||
class: "flex flex-col gap-y-5",
|
class: "flex flex-col gap-y-5",
|
||||||
match *step.read() {
|
match *step.read() {
|
||||||
Steps::Message => rsx! { Message { step: step } },
|
Steps::Message => rsx! { Message { step: step, title: form.title, body: form.body } },
|
||||||
Steps::Targets => rsx! { TargetSelect { step: step } },
|
Steps::Targets => rsx! { TargetSelect { step: step, targets: form.targets } },
|
||||||
Steps::Verify => rsx! { Message { step: step } },
|
Steps::Verify => rsx! { { } },
|
||||||
Steps::Done => rsx! { Message { step: step } },
|
Steps::Done => rsx! { { } },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,10 +77,20 @@ pub fn NewsCreate() -> Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[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! {
|
rsx! {
|
||||||
form {
|
form {
|
||||||
class: "flex flex-col w-full gap-y-5",
|
class: "flex flex-col w-full gap-y-5",
|
||||||
|
onsubmit: submit,
|
||||||
label {
|
label {
|
||||||
class: "form-control w-full",
|
class: "form-control w-full",
|
||||||
div {
|
div {
|
||||||
@ -63,6 +99,9 @@ fn Message(step: Signal<Steps>) -> Element {
|
|||||||
},
|
},
|
||||||
input {
|
input {
|
||||||
r#type: "text",
|
r#type: "text",
|
||||||
|
required: true,
|
||||||
|
name: "title",
|
||||||
|
value: "{title}",
|
||||||
class: "input input-bordered w-full",
|
class: "input input-bordered w-full",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,24 +112,25 @@ fn Message(step: Signal<Steps>) -> Element {
|
|||||||
span { class: "label-text", "Bericht" }
|
span { class: "label-text", "Bericht" }
|
||||||
},
|
},
|
||||||
textarea {
|
textarea {
|
||||||
|
name: "body",
|
||||||
|
value: "{body}",
|
||||||
class: "textarea textarea-bordered w-full",
|
class: "textarea textarea-bordered w-full",
|
||||||
|
required: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
div {
|
div {
|
||||||
class: "w-full flex gap-x-3 justify-end",
|
class: "w-full flex gap-x-3 justify-end",
|
||||||
button {
|
input {
|
||||||
|
r#type: "submit",
|
||||||
class: "btn btn-primary",
|
class: "btn btn-primary",
|
||||||
onclick: move |_| {
|
value: "Volgende",
|
||||||
step.set(Steps::Targets)
|
|
||||||
},
|
|
||||||
"Volgende",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
|
#[derive(PartialEq, Clone, Copy, Debug)]
|
||||||
enum TargetKind {
|
enum TargetKind {
|
||||||
None,
|
None,
|
||||||
All,
|
All,
|
||||||
@ -102,7 +142,7 @@ enum TargetKind {
|
|||||||
Day,
|
Day,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq)]
|
#[derive(PartialEq, Debug)]
|
||||||
struct Target {
|
struct Target {
|
||||||
kind: TargetKind,
|
kind: TargetKind,
|
||||||
value: String,
|
value: String,
|
||||||
@ -124,17 +164,7 @@ impl TargetKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
fn TargetSelect(step: Signal<Steps>) -> Element {
|
fn TargetSelect(step: Signal<Steps>, targets: Signal<HashMap<u32, Target>>) -> Element {
|
||||||
let mut targets: Signal<HashMap<u32, Target>> = use_signal(|| {
|
|
||||||
HashMap::from([(
|
|
||||||
0,
|
|
||||||
Target {
|
|
||||||
kind: TargetKind::None,
|
|
||||||
value: String::new(),
|
|
||||||
},
|
|
||||||
)])
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut target_id = use_signal(|| 1);
|
let mut target_id = use_signal(|| 1);
|
||||||
|
|
||||||
let target_ids = use_memo(move || {
|
let target_ids = use_memo(move || {
|
||||||
|
Loading…
Reference in New Issue
Block a user