Commit before update of dioxus

This commit is contained in:
xeovalyte 2024-12-10 07:35:09 +01:00
parent ec195dfbf7
commit fdd029ffd7
Signed by: xeovalyte
SSH Key Fingerprint: SHA256:kSQDrQDmKzljJzfGYcd3m9RqHi4h8rSwkZ3sQ9kBURo
4 changed files with 160 additions and 105 deletions

View File

@ -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 {

View File

@ -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,12 +144,17 @@ fn TargetSelect(step: Signal<Steps>, targets: Signal<HashMap<u32, Target>>) -> E
filtered_targets.sort_unstable();
tracing::info!("targets updated");
filtered_targets
});
let submit = move |_| {
step.set(Steps::Verify);
};
rsx! {
form {
class: "w-full",
onsubmit: submit,
label {
class: "form-control w-full",
div {
@ -207,6 +184,7 @@ fn TargetSelect(step: Signal<Steps>, targets: Signal<HashMap<u32, Target>>) -> E
class: "w-full flex gap-x-3 justify-end",
button {
class: "btn",
r#type: "button",
onclick: move |_| {
step.set(Steps::Message)
},
@ -214,32 +192,29 @@ fn TargetSelect(step: Signal<Steps>, targets: Signal<HashMap<u32, Target>>) -> E
}
button {
class: "btn btn-primary",
onclick: move |_| {
step.set(Steps::Verify)
},
"Volgende",
}
}
}
}
}
#[component]
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" }
}
}
}

View File

@ -1,3 +1,4 @@
pub mod member;
pub mod news;
pub mod session;
pub mod user;

68
src/util/model/news.rs Normal file
View 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 {}
}