Commit before update of dioxus
This commit is contained in:
parent
ec195dfbf7
commit
fdd029ffd7
@ -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 {
|
||||
|
@ -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<Steps>, title: Signal<String>, body: Signal<String>) ->
|
||||
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<Steps>, title: Signal<String>, body: Signal<String>) ->
|
||||
r#type: "text",
|
||||
required: true,
|
||||
name: "title",
|
||||
value: "{title}",
|
||||
class: "input input-bordered w-full",
|
||||
}
|
||||
}
|
||||
@ -113,7 +119,6 @@ fn Message(step: Signal<Steps>, title: Signal<String>, body: Signal<String>) ->
|
||||
},
|
||||
textarea {
|
||||
name: "body",
|
||||
value: "{body}",
|
||||
class: "textarea textarea-bordered w-full",
|
||||
required: true,
|
||||
}
|
||||
@ -130,39 +135,6 @@ fn Message(step: Signal<Steps>, title: Signal<String>, body: Signal<String>) ->
|
||||
}
|
||||
}
|
||||
|
||||
#[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<Steps>, targets: Signal<HashMap<u32, Target>>) -> Element {
|
||||
let mut target_id = use_signal(|| 1);
|
||||
@ -172,52 +144,56 @@ fn TargetSelect(step: Signal<Steps>, targets: Signal<HashMap<u32, Target>>) -> 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<Steps>, targets: Signal<HashMap<u32, Target>>) -> E
|
||||
fn TargetEntry(mut targets: Signal<HashMap<u32, Target>>, 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::<crate::Groups>();
|
||||
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" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
pub mod member;
|
||||
pub mod news;
|
||||
pub mod session;
|
||||
pub mod user;
|
||||
|
68
src/util/model/news.rs
Normal file
68
src/util/model/news.rs
Normal file
@ -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<Target>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
impl News {
|
||||
// pub async fn new(
|
||||
// title: String,
|
||||
// body: String,
|
||||
// targets: Vec<Target>,
|
||||
// ) -> Result<Self, crate::Error> {
|
||||
// }
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
fn fetch_targets(targets: Vec<Target>) {
|
||||
let mut transaction = DB.query(BeginStatement::default());
|
||||
|
||||
for target in targets {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user