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;
|
display: contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.size-6 {
|
.size-6 {
|
||||||
width: 1.5rem;
|
width: 1.5rem;
|
||||||
height: 1.5rem;
|
height: 1.5rem;
|
||||||
@ -3392,12 +3396,12 @@ details.collapse summary::-webkit-details-marker {
|
|||||||
min-height: 4rem;
|
min-height: 4rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.w-1\/2 {
|
.w-1\/3 {
|
||||||
width: 50%;
|
width: 33.333333%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.w-1\/4 {
|
.w-2\/3 {
|
||||||
width: 25%;
|
width: 66.666667%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.w-80 {
|
.w-80 {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use crate::util::model::news::{Target, TargetKind};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
@ -65,11 +66,20 @@ pub fn NewsCreate() -> Element {
|
|||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
class: "flex flex-col gap-y-5",
|
class: "flex flex-col gap-y-5",
|
||||||
match *step.read() {
|
div {
|
||||||
Steps::Message => rsx! { Message { step: step, title: form.title, body: form.body } },
|
class: if let Steps::Message = *step.read() { "" } else { "hidden" },
|
||||||
Steps::Targets => rsx! { TargetSelect { step: step, targets: form.targets } },
|
Message {
|
||||||
Steps::Verify => rsx! { { } },
|
step: step,
|
||||||
Steps::Done => rsx! { { } },
|
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| {
|
let submit = move |event: FormEvent| {
|
||||||
title.set(event.values()["title"].as_value());
|
title.set(event.values()["title"].as_value());
|
||||||
body.set(event.values()["body"].as_value());
|
body.set(event.values()["body"].as_value());
|
||||||
|
|
||||||
tracing::info!("{title}");
|
|
||||||
|
|
||||||
step.set(Steps::Targets);
|
step.set(Steps::Targets);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -101,7 +108,6 @@ fn Message(step: Signal<Steps>, title: Signal<String>, body: Signal<String>) ->
|
|||||||
r#type: "text",
|
r#type: "text",
|
||||||
required: true,
|
required: true,
|
||||||
name: "title",
|
name: "title",
|
||||||
value: "{title}",
|
|
||||||
class: "input input-bordered w-full",
|
class: "input input-bordered w-full",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,7 +119,6 @@ fn Message(step: Signal<Steps>, title: Signal<String>, body: Signal<String>) ->
|
|||||||
},
|
},
|
||||||
textarea {
|
textarea {
|
||||||
name: "body",
|
name: "body",
|
||||||
value: "{body}",
|
|
||||||
class: "textarea textarea-bordered w-full",
|
class: "textarea textarea-bordered w-full",
|
||||||
required: true,
|
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]
|
#[component]
|
||||||
fn TargetSelect(step: Signal<Steps>, targets: Signal<HashMap<u32, Target>>) -> Element {
|
fn TargetSelect(step: Signal<Steps>, targets: Signal<HashMap<u32, Target>>) -> Element {
|
||||||
let mut target_id = use_signal(|| 1);
|
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();
|
filtered_targets.sort_unstable();
|
||||||
|
|
||||||
tracing::info!("targets updated");
|
|
||||||
|
|
||||||
filtered_targets
|
filtered_targets
|
||||||
});
|
});
|
||||||
|
|
||||||
rsx! {
|
let submit = move |_| {
|
||||||
label {
|
step.set(Steps::Verify);
|
||||||
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;
|
|
||||||
|
|
||||||
|
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 {
|
||||||
div {
|
class: "w-full flex gap-x-3 justify-end",
|
||||||
class: "w-full flex gap-x-3 justify-end",
|
button {
|
||||||
button {
|
class: "btn",
|
||||||
class: "btn",
|
r#type: "button",
|
||||||
onclick: move |_| {
|
onclick: move |_| {
|
||||||
step.set(Steps::Message)
|
step.set(Steps::Message)
|
||||||
},
|
},
|
||||||
"Terug",
|
"Terug",
|
||||||
}
|
}
|
||||||
button {
|
button {
|
||||||
class: "btn btn-primary",
|
class: "btn btn-primary",
|
||||||
onclick: move |_| {
|
"Volgende",
|
||||||
step.set(Steps::Verify)
|
}
|
||||||
},
|
|
||||||
"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 {
|
fn TargetEntry(mut targets: Signal<HashMap<u32, Target>>, id: u32) -> Element {
|
||||||
let kind = use_memo(move || targets.read().get(&id).unwrap().kind);
|
let kind = use_memo(move || targets.read().get(&id).unwrap().kind);
|
||||||
|
|
||||||
tracing::info!("Comonent rendered!");
|
|
||||||
|
|
||||||
rsx! {
|
rsx! {
|
||||||
div {
|
div {
|
||||||
class: "join w-full mt-3",
|
class: "join w-full mt-3",
|
||||||
select {
|
select {
|
||||||
class: "select select-bordered join-item w-1/2",
|
class: "select select-bordered join-item w-1/3",
|
||||||
|
required: true,
|
||||||
oninput: move |event| {
|
oninput: move |event| {
|
||||||
let target_kind = TargetKind::from_string(&event.value());
|
let target_kind = TargetKind::from_string(&event.value());
|
||||||
targets.write().get_mut(&id).unwrap().kind = target_kind;
|
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: "all", "Iedereen" }
|
||||||
option { value: "group", "Groep" }
|
option { value: "group", "Groep" }
|
||||||
option { value: "day", "Dag" }
|
option { value: "day", "Dag" }
|
||||||
@ -262,16 +237,19 @@ fn TargetValueInput(
|
|||||||
let groups = use_context::<crate::Groups>();
|
let groups = use_context::<crate::Groups>();
|
||||||
let value = use_memo(move || targets.read().get(&id).unwrap().value.clone());
|
let value = use_memo(move || targets.read().get(&id).unwrap().value.clone());
|
||||||
|
|
||||||
|
tracing::info!("Input rendered");
|
||||||
|
|
||||||
rsx! {
|
rsx! {
|
||||||
match target_kind() {
|
match target_kind() {
|
||||||
TargetKind::Group => {
|
TargetKind::Group => {
|
||||||
rsx! {
|
rsx! {
|
||||||
select {
|
select {
|
||||||
class: "select select-bordered join-item w-1/2",
|
class: "select select-bordered join-item w-2/3",
|
||||||
|
required: true,
|
||||||
oninput: move |event| {
|
oninput: move |event| {
|
||||||
targets.write().get_mut(&id).unwrap().value = event.value();
|
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 {
|
for (group_id, group_name) in groups.0 {
|
||||||
option { value: group_id, "{group_name}" }
|
option { value: group_id, "{group_name}" }
|
||||||
}
|
}
|
||||||
@ -281,11 +259,12 @@ fn TargetValueInput(
|
|||||||
TargetKind::Day => {
|
TargetKind::Day => {
|
||||||
rsx! {
|
rsx! {
|
||||||
select {
|
select {
|
||||||
class: "select select-bordered join-item w-1/2",
|
class: "select select-bordered join-item w-2/3",
|
||||||
|
required: true,
|
||||||
oninput: move |event| {
|
oninput: move |event| {
|
||||||
targets.write().get_mut(&id).unwrap().value = event.value();
|
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 {
|
option {
|
||||||
value: "friday",
|
value: "friday",
|
||||||
"Vrijdag",
|
"Vrijdag",
|
||||||
@ -300,8 +279,9 @@ fn TargetValueInput(
|
|||||||
TargetKind::Hourgroup => {
|
TargetKind::Hourgroup => {
|
||||||
rsx! {
|
rsx! {
|
||||||
select {
|
select {
|
||||||
class: "select select-bordered join-item w-1/4",
|
class: "select select-bordered join-item w-1/3",
|
||||||
option { disabled: true, selected: true, "Selecteer een uur" }
|
required: true,
|
||||||
|
option { disabled: true, selected: true, value: "", "Selecteer een uur" }
|
||||||
option {
|
option {
|
||||||
value: "a",
|
value: "a",
|
||||||
"A",
|
"A",
|
||||||
@ -328,8 +308,9 @@ fn TargetValueInput(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
class: "select select-bordered join-item w-1/4",
|
class: "select select-bordered join-item w-1/3",
|
||||||
option { disabled: true, selected: true, "Selecteer een groep" }
|
required: true,
|
||||||
|
option { disabled: true, selected: true, value: "", "Selecteer een groep" }
|
||||||
for i in 1..7 {
|
for i in 1..7 {
|
||||||
option { "{i}" }
|
option { "{i}" }
|
||||||
}
|
}
|
||||||
@ -339,8 +320,9 @@ fn TargetValueInput(
|
|||||||
TargetKind::Hour => {
|
TargetKind::Hour => {
|
||||||
rsx! {
|
rsx! {
|
||||||
select {
|
select {
|
||||||
class: "select select-bordered join-item w-1/2",
|
class: "select select-bordered join-item w-2/3",
|
||||||
option { disabled: true, selected: true, "Selecteer een uur" }
|
required: true,
|
||||||
|
option { disabled: true, selected: true, value: "", "Selecteer een uur" }
|
||||||
option {
|
option {
|
||||||
value: "a",
|
value: "a",
|
||||||
"A",
|
"A",
|
||||||
@ -371,8 +353,8 @@ fn TargetValueInput(
|
|||||||
TargetKind::Member | TargetKind::Account => {
|
TargetKind::Member | TargetKind::Account => {
|
||||||
rsx! {
|
rsx! {
|
||||||
input {
|
input {
|
||||||
class: "input input-bordered join-item w-1/2",
|
class: "input input-bordered join-item w-2/3",
|
||||||
value: "{value}",
|
required: true,
|
||||||
oninput: move |event| {
|
oninput: move |event| {
|
||||||
targets.write().get_mut(&id).unwrap().value = event.value();
|
targets.write().get_mut(&id).unwrap().value = event.value();
|
||||||
},
|
},
|
||||||
@ -380,7 +362,7 @@ fn TargetValueInput(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => rsx! {
|
_ => 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 member;
|
||||||
|
pub mod news;
|
||||||
pub mod session;
|
pub mod session;
|
||||||
pub mod user;
|
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