diff --git a/assets/tailwind.css b/assets/tailwind.css index e4dc921..917fc0b 100644 --- a/assets/tailwind.css +++ b/assets/tailwind.css @@ -3352,6 +3352,10 @@ details.collapse summary::-webkit-details-marker { display: contents; } +.hidden { + display: none; +} + .size-6 { width: 1.5rem; height: 1.5rem; @@ -3392,12 +3396,12 @@ details.collapse summary::-webkit-details-marker { min-height: 4rem; } -.w-1\/2 { - width: 50%; +.w-1\/3 { + width: 33.333333%; } -.w-1\/4 { - width: 25%; +.w-2\/3 { + width: 66.666667%; } .w-80 { diff --git a/src/components/news/create.rs b/src/components/news/create.rs index f6767b9..d2ae1da 100644 --- a/src/components/news/create.rs +++ b/src/components/news/create.rs @@ -1,3 +1,4 @@ +use crate::util::model::news::{Target, TargetKind}; use std::collections::HashMap; use dioxus::prelude::*; @@ -65,11 +66,20 @@ pub fn NewsCreate() -> Element { } div { class: "flex flex-col gap-y-5", - match *step.read() { - 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! { { } }, + div { + class: if let Steps::Message = *step.read() { "" } else { "hidden" }, + Message { + step: step, + title: form.title, + body: form.body, + } + } + div { + class: if let Steps::Targets = *step.read() { "" } else { "hidden" }, + TargetSelect { + step: step, + targets: form.targets, + } } } } @@ -81,9 +91,6 @@ fn Message(step: Signal, title: Signal, body: Signal) -> 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); }; @@ -101,7 +108,6 @@ fn Message(step: Signal, title: Signal, body: Signal) -> r#type: "text", required: true, name: "title", - value: "{title}", class: "input input-bordered w-full", } } @@ -113,7 +119,6 @@ fn Message(step: Signal, title: Signal, body: Signal) -> }, textarea { name: "body", - value: "{body}", class: "textarea textarea-bordered w-full", required: true, } @@ -130,39 +135,6 @@ fn Message(step: Signal, title: Signal, body: Signal) -> } } -#[derive(PartialEq, Clone, Copy, Debug)] -enum TargetKind { - None, - All, - Group, - Hourgroup, - Hour, - Member, - Account, - Day, -} - -#[derive(PartialEq, Debug)] -struct Target { - kind: TargetKind, - value: String, -} - -impl TargetKind { - fn from_string(input: &str) -> Self { - match input { - "all" => Self::All, - "group" => Self::Group, - "hourgroup" => Self::Hourgroup, - "hour" => Self::Hour, - "member" => Self::Member, - "account" => Self::Account, - "day" => Self::Day, - _ => Self::None, - } - } -} - #[component] fn TargetSelect(step: Signal, targets: Signal>) -> Element { let mut target_id = use_signal(|| 1); @@ -172,52 +144,56 @@ fn TargetSelect(step: Signal, targets: Signal>) -> E filtered_targets.sort_unstable(); - tracing::info!("targets updated"); - filtered_targets }); - rsx! { - label { - class: "form-control w-full", - div { - class: "label", - span { class: "label-text", "Naar" } - }, - for id in target_ids() { - TargetEntry { key: "{id}", id, targets } - } - button { - class: "btn btn-primary btn-sm mt-3 mr-auto", - r#type: "button", - onclick: move |_| { - let id = target_id(); - let target = Target { - kind: TargetKind::None, - value: String::new(), - }; - targets.write().insert(id, target); - target_id += 1; + let submit = move |_| { + step.set(Steps::Verify); + }; + rsx! { + form { + class: "w-full", + onsubmit: submit, + label { + class: "form-control w-full", + div { + class: "label", + span { class: "label-text", "Naar" } }, - "Conditie toevoegen", + for id in target_ids() { + TargetEntry { key: "{id}", id, targets } + } + button { + class: "btn btn-primary btn-sm mt-3 mr-auto", + r#type: "button", + onclick: move |_| { + let id = target_id(); + let target = Target { + kind: TargetKind::None, + value: String::new(), + }; + targets.write().insert(id, target); + target_id += 1; + + }, + "Conditie toevoegen", + } } - } - div { - class: "w-full flex gap-x-3 justify-end", - button { - class: "btn", - onclick: move |_| { - step.set(Steps::Message) - }, - "Terug", - } - button { - class: "btn btn-primary", - onclick: move |_| { - step.set(Steps::Verify) - }, - "Volgende", + div { + class: "w-full flex gap-x-3 justify-end", + button { + class: "btn", + r#type: "button", + onclick: move |_| { + step.set(Steps::Message) + }, + "Terug", + } + button { + class: "btn btn-primary", + "Volgende", + } } } } @@ -227,19 +203,18 @@ fn TargetSelect(step: Signal, targets: Signal>) -> E fn TargetEntry(mut targets: Signal>, id: u32) -> Element { let kind = use_memo(move || targets.read().get(&id).unwrap().kind); - tracing::info!("Comonent rendered!"); - rsx! { div { class: "join w-full mt-3", select { - class: "select select-bordered join-item w-1/2", + class: "select select-bordered join-item w-1/3", + required: true, oninput: move |event| { let target_kind = TargetKind::from_string(&event.value()); targets.write().get_mut(&id).unwrap().kind = target_kind; - targets.write().get_mut(&id).unwrap().value = String::new(); + targets.write().get_mut(&id).unwrap().value = String::from(""); }, - option { disabled: true, selected: true, "Selecteer een type" }, + option { disabled: true, selected: true, value: "", "Selecteer een type" }, option { value: "all", "Iedereen" } option { value: "group", "Groep" } option { value: "day", "Dag" } @@ -262,16 +237,19 @@ fn TargetValueInput( let groups = use_context::(); let value = use_memo(move || targets.read().get(&id).unwrap().value.clone()); + tracing::info!("Input rendered"); + rsx! { match target_kind() { TargetKind::Group => { rsx! { select { - class: "select select-bordered join-item w-1/2", + class: "select select-bordered join-item w-2/3", + required: true, oninput: move |event| { targets.write().get_mut(&id).unwrap().value = event.value(); }, - option { disabled: true, selected: true, "Selecteer een groep" } + option { disabled: true, selected: true, value: "", "Selecteer een groep" } for (group_id, group_name) in groups.0 { option { value: group_id, "{group_name}" } } @@ -281,11 +259,12 @@ fn TargetValueInput( TargetKind::Day => { rsx! { select { - class: "select select-bordered join-item w-1/2", + class: "select select-bordered join-item w-2/3", + required: true, oninput: move |event| { targets.write().get_mut(&id).unwrap().value = event.value(); }, - option { disabled: true, selected: true, "Selecteer een dag" } + option { disabled: true, selected: true, value: "", "Selecteer een dag" } option { value: "friday", "Vrijdag", @@ -300,8 +279,9 @@ fn TargetValueInput( TargetKind::Hourgroup => { rsx! { select { - class: "select select-bordered join-item w-1/4", - option { disabled: true, selected: true, "Selecteer een uur" } + class: "select select-bordered join-item w-1/3", + required: true, + option { disabled: true, selected: true, value: "", "Selecteer een uur" } option { value: "a", "A", @@ -328,8 +308,9 @@ fn TargetValueInput( } } select { - class: "select select-bordered join-item w-1/4", - option { disabled: true, selected: true, "Selecteer een groep" } + class: "select select-bordered join-item w-1/3", + required: true, + option { disabled: true, selected: true, value: "", "Selecteer een groep" } for i in 1..7 { option { "{i}" } } @@ -339,8 +320,9 @@ fn TargetValueInput( TargetKind::Hour => { rsx! { select { - class: "select select-bordered join-item w-1/2", - option { disabled: true, selected: true, "Selecteer een uur" } + class: "select select-bordered join-item w-2/3", + required: true, + option { disabled: true, selected: true, value: "", "Selecteer een uur" } option { value: "a", "A", @@ -371,8 +353,8 @@ fn TargetValueInput( TargetKind::Member | TargetKind::Account => { rsx! { input { - class: "input input-bordered join-item w-1/2", - value: "{value}", + class: "input input-bordered join-item w-2/3", + required: true, oninput: move |event| { targets.write().get_mut(&id).unwrap().value = event.value(); }, @@ -380,7 +362,7 @@ fn TargetValueInput( } }, _ => rsx! { - div { class: "input input-bordered w-1/2 join-item" } + div { class: "input input-bordered w-2/3 join-item" } } } } diff --git a/src/util/model.rs b/src/util/model.rs index 28735f0..df6c885 100644 --- a/src/util/model.rs +++ b/src/util/model.rs @@ -1,3 +1,4 @@ pub mod member; +pub mod news; pub mod session; pub mod user; diff --git a/src/util/model/news.rs b/src/util/model/news.rs new file mode 100644 index 0000000..2960520 --- /dev/null +++ b/src/util/model/news.rs @@ -0,0 +1,68 @@ +use serde::{Deserialize, Serialize}; + +#[cfg(feature = "server")] +use crate::util::surrealdb::{thing_to_string, DB}; +#[cfg(feature = "server")] +use surrealdb::sql::{ + statements::{BeginStatement, CommitStatement}, + Thing, +}; + +#[derive(PartialEq, Clone, Copy, Debug, Deserialize, Serialize, Eq)] +pub enum TargetKind { + None, + All, + Group, + Hourgroup, + Hour, + Member, + Account, + Day, +} + +impl TargetKind { + pub fn from_string(input: &str) -> Self { + match input { + "all" => Self::All, + "group" => Self::Group, + "hourgroup" => Self::Hourgroup, + "hour" => Self::Hour, + "member" => Self::Member, + "account" => Self::Account, + "day" => Self::Day, + _ => Self::None, + } + } +} + +#[derive(PartialEq, Debug, Deserialize, Serialize, Clone, Eq)] +pub struct Target { + pub kind: TargetKind, + pub value: String, +} + +#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)] +pub struct News { + #[cfg_attr(feature = "server", serde(deserialize_with = "thing_to_string"))] + pub id: String, + pub title: String, + pub body: String, + pub tagets: Vec, +} + +#[cfg(feature = "server")] +impl News { + // pub async fn new( + // title: String, + // body: String, + // targets: Vec, + // ) -> Result { + // } +} + +#[cfg(feature = "server")] +fn fetch_targets(targets: Vec) { + let mut transaction = DB.query(BeginStatement::default()); + + for target in targets {} +}