Migrated to dioxus 0.6

This commit is contained in:
xeovalyte 2024-12-10 18:38:58 +01:00
parent fdd029ffd7
commit a75df84dcb
Signed by: xeovalyte
SSH Key Fingerprint: SHA256:kSQDrQDmKzljJzfGYcd3m9RqHi4h8rSwkZ3sQ9kBURo
7 changed files with 1115 additions and 1417 deletions

2359
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,28 +7,40 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
serde = { version = "1.0.197", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
dioxus = { version = "0.5", features = ["fullstack", "router"] } dioxus = { version = "0.6", features = ["fullstack", "router"] }
web-sys = { version = "0.3.70", features = ["Window", "Location"] } dioxus-cli-config = { version = "0.6", optional = true }
web-sys = { version = "0.3", features = ["Window", "Location"] }
tokio = { version = "1.38", features = ["macros", "rt-multi-thread"], optional = true } tokio = { version = "1.42", features = ["macros", "rt-multi-thread"], optional = true }
axum = { version = "0.7", optional = true } axum = { version = "0.7", optional = true }
axum-extra = { version = "0.9", features = ["cookie"], optional = true } axum-extra = { version = "0.9", features = ["cookie"], optional = true }
time = { version = "0.3", optional = true } time = { version = "0.3", optional = true }
once_cell = { version = "1.19", optional = true } once_cell = { version = "1.20", optional = true }
surrealdb = { version = "2.0", optional = true } surrealdb = { version = "2.1", optional = true }
thiserror = { version = "1.0" } thiserror = { version = "2.0" }
strum = { version = "0.26", features = ["derive"] } strum = { version = "0.26", features = ["derive"] }
csv = { version = "1.3", optional = true } csv = { version = "1.3", optional = true }
# Debug # Debug
tracing = "0.1" tracing = "0.1"
dioxus-logger = "0.5" manganis = "0.6"
manganis = "0.2"
[features] [features]
default = [] default = []
server = [ "dioxus/axum", "tokio", "axum", "axum-extra", "time", "once_cell", "surrealdb", "csv" ] server = [ "dioxus/server", "dioxus-cli-config", "tokio", "axum", "axum-extra", "time", "once_cell", "surrealdb", "csv" ]
web = ["dioxus/web"] web = ["dioxus/web"]
[profile]
[profile.wasm-dev]
inherits = "dev"
opt-level = 1
[profile.server-dev]
inherits = "dev"
[profile.android-dev]
inherits = "dev"

View File

@ -2,8 +2,7 @@ use crate::util::model::{
member::{Member, MembersMigration}, member::{Member, MembersMigration},
session::Session, session::Session,
}; };
use dioxus::prelude::{dioxus_elements::FileEngine, *}; use dioxus::prelude::*;
use std::sync::Arc;
#[derive(Debug)] #[derive(Debug)]
struct UploadedFile { struct UploadedFile {
@ -31,12 +30,12 @@ pub fn Migration() -> Element {
li { class: "step step-primary", "Uploaden" }, li { class: "step step-primary", "Uploaden" },
li { li {
class: "step", class: "step",
class: if let Steps::Verify | Steps::Done = *step.read() { { "step-primary" } }, class: if let Steps::Verify | Steps::Done = *step.read() { "step-primary" },
"Controleren" "Controleren"
}, },
li { li {
class: "step", class: "step",
class: if let Steps::Done = *step.read() { { "step-primary" } }, class: if let Steps::Done = *step.read() { "step-primary" },
"Klaar" "Klaar"
}, },
}, },
@ -51,26 +50,23 @@ pub fn Migration() -> Element {
#[component] #[component]
fn Upload(step: Signal<Steps>, members_migration: Signal<(u16, MembersMigration)>) -> Element { fn Upload(step: Signal<Steps>, members_migration: Signal<(u16, MembersMigration)>) -> Element {
let mut file_uploaded = use_signal(|| None); let mut file_uploaded: Signal<Option<UploadedFile>> = use_signal(|| None);
let mut loading = use_signal(|| false); let mut loading = use_signal(|| false);
let read_files = move |file_engine: Arc<dyn FileEngine>| async move {
let files = file_engine.files();
for file_name in &files {
if let Some(contents) = file_engine.read_file_to_string(file_name).await {
file_uploaded.set(Some(UploadedFile {
name: file_name.clone(),
contents,
}));
}
}
};
let upload_files = move |evt: FormEvent| async move { let upload_files = move |evt: FormEvent| async move {
if let Some(file_engine) = evt.files() { // TODO: Uncomment after bugfix dioxus
read_files(file_engine).await; // if let Some(file_engine) = &evt.files() {
} // let files = file_engine.files();
// for file_name in &files {
// if let Some(file) = file_engine.read_file_to_string(file_name).await {
// file_uploaded.set(Some(UploadedFile {
// name: file_name.to_owned(),
// contents: file,
// }))
// }
// }
// }
}; };
let sumbit = move |_evt: FormEvent| async move { let sumbit = move |_evt: FormEvent| async move {

View File

@ -50,17 +50,17 @@ pub fn NewsCreate() -> Element {
li { class: "step step-primary", "Inhoud" }, li { class: "step step-primary", "Inhoud" },
li { li {
class: "step", class: "step",
class: if let Steps::Targets | Steps::Done | Steps::Verify = *step.read() { { "step-primary" } }, class: if let Steps::Targets | Steps::Done | Steps::Verify = *step.read() { "step-primary" },
"Naar" "Naar"
} }
li { li {
class: "step", class: "step",
class: if let Steps::Verify | Steps::Done = *step.read() { { "step-primary" } }, class: if let Steps::Verify | Steps::Done = *step.read() { "step-primary" },
"Controleren" "Controleren"
} }
li { li {
class: "step", class: "step",
class: if let Steps::Done = *step.read() { { "step-primary" } }, class: if let Steps::Done = *step.read() { "step-primary" },
"Klaar" "Klaar"
} }
} }

View File

@ -8,7 +8,6 @@ mod util;
pub use err::Error; pub use err::Error;
use dioxus::prelude::*; use dioxus::prelude::*;
use tracing::Level;
// Use routes // Use routes
use components::admin::members::migration::Migration; use components::admin::members::migration::Migration;
@ -22,6 +21,7 @@ use components::layout::Global;
use components::news::create::NewsCreate; use components::news::create::NewsCreate;
use components::news::News; use components::news::News;
use components::settings::Settings; use components::settings::Settings;
use tracing::Level;
#[derive(Clone, Routable, Debug, PartialEq, serde::Serialize, serde::Deserialize)] #[derive(Clone, Routable, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[rustfmt::skip] #[rustfmt::skip]
@ -49,43 +49,29 @@ pub enum Route {
Migration {}, Migration {},
} }
const _TAILWIND_URL: &str = manganis::mg!(file("assets/tailwind.css"));
fn main() {
// Init logger
dioxus_logger::init(Level::INFO).expect("failed to init logger");
#[cfg(feature = "server")] #[cfg(feature = "server")]
{ #[tokio::main]
use axum::routing::*; async fn main() {
dioxus::logger::init(Level::INFO).expect("Failed to init logger");
// Spawn main tokio runtime
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async move {
// Initialize surrealdb connection // Initialize surrealdb connection
util::surrealdb::initialize() util::surrealdb::initialize()
.await .await
.expect("Error while initializing surrealdb"); .expect("Error while initializing surrealdb");
// Create axum app let address = dioxus_cli_config::fullstack_address_or_localhost();
let app = Router::new()
.serve_dioxus_application(ServeConfig::builder().build(), || {
VirtualDom::new(App)
})
.await;
// Run axum app let router = axum::Router::new().serve_dioxus_application(ServeConfigBuilder::default(), App);
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, app.into_make_service()) let router = router.into_make_service();
.await let listener = tokio::net::TcpListener::bind(address).await.unwrap();
.unwrap();
}); axum::serve(listener, router).await.unwrap();
} }
launch(App); #[cfg(not(feature = "server"))]
fn main() {
dioxus::launch(App);
} }
#[derive(Clone)] #[derive(Clone)]
@ -117,6 +103,10 @@ fn App() -> Element {
use_context_provider(|| hours); use_context_provider(|| hours);
rsx! { rsx! {
document::Stylesheet {
href: asset!("assets/tailwind.css")
}
div { div {
class: "h-screen flex flex-col", class: "h-screen flex flex-col",
Router::<Route> {} Router::<Route> {}

View File

@ -3,8 +3,6 @@ use crate::util::surrealdb::{thing_to_string, DB};
use dioxus::prelude::*; use dioxus::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "server")]
use surrealdb::sql::Thing;
use super::user::User; use super::user::User;
@ -51,11 +49,7 @@ impl Session {
cookie.set_same_site(SameSite::Strict); cookie.set_same_site(SameSite::Strict);
server_context() server_context().response_parts_mut().headers.insert(
.response_parts_mut()
.unwrap()
.headers
.insert(
header::SET_COOKIE, header::SET_COOKIE,
HeaderValue::from_str(&cookie.to_string())?, HeaderValue::from_str(&cookie.to_string())?,
); );
@ -104,11 +98,7 @@ impl Session {
cookie.set_same_site(SameSite::Strict); cookie.set_same_site(SameSite::Strict);
server_context() server_context().response_parts_mut().headers.insert(
.response_parts_mut()
.unwrap()
.headers
.insert(
header::SET_COOKIE, header::SET_COOKIE,
HeaderValue::from_str(&cookie.to_string())?, HeaderValue::from_str(&cookie.to_string())?,
); );

View File

@ -16,7 +16,11 @@ where
} }
pub async fn initialize() -> surrealdb::Result<()> { pub async fn initialize() -> surrealdb::Result<()> {
DB.connect::<Ws>("localhost:8000").await?; tracing::info!("Connectiong to surrealdb");
DB.connect::<Ws>("localhost:8000")
.await
.expect("Failed to connect to surrealdb");
DB.signin(Root { DB.signin(Root {
username: "root", username: "root",
@ -26,7 +30,7 @@ pub async fn initialize() -> surrealdb::Result<()> {
DB.use_ns("wrbapp").use_db("wrbapp").await?; DB.use_ns("wrbapp").use_db("wrbapp").await?;
apply_queries().await?; apply_queries().await.expect("Failed to apply queries");
Ok(()) Ok(())
} }
@ -47,7 +51,8 @@ async fn apply_queries() -> surrealdb::Result<()> {
DEFINE INDEX userEmailIndex ON TABLE user COLUMNS email UNIQUE; DEFINE INDEX userEmailIndex ON TABLE user COLUMNS email UNIQUE;
", ",
) )
.await?; .await
.expect("Failed to apply user query");
DB.query( DB.query(
" "