Migrated to dioxus 0.6
This commit is contained in:
parent
fdd029ffd7
commit
a75df84dcb
2359
Cargo.lock
generated
2359
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
32
Cargo.toml
32
Cargo.toml
@ -7,28 +7,40 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
dioxus = { version = "0.5", features = ["fullstack", "router"] }
|
||||
web-sys = { version = "0.3.70", features = ["Window", "Location"] }
|
||||
dioxus = { version = "0.6", features = ["fullstack", "router"] }
|
||||
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-extra = { version = "0.9", features = ["cookie"], optional = true }
|
||||
time = { version = "0.3", optional = true }
|
||||
once_cell = { version = "1.19", optional = true }
|
||||
surrealdb = { version = "2.0", optional = true }
|
||||
thiserror = { version = "1.0" }
|
||||
once_cell = { version = "1.20", optional = true }
|
||||
surrealdb = { version = "2.1", optional = true }
|
||||
thiserror = { version = "2.0" }
|
||||
strum = { version = "0.26", features = ["derive"] }
|
||||
|
||||
csv = { version = "1.3", optional = true }
|
||||
|
||||
# Debug
|
||||
tracing = "0.1"
|
||||
dioxus-logger = "0.5"
|
||||
manganis = "0.2"
|
||||
manganis = "0.6"
|
||||
|
||||
[features]
|
||||
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"]
|
||||
|
||||
[profile]
|
||||
|
||||
[profile.wasm-dev]
|
||||
inherits = "dev"
|
||||
opt-level = 1
|
||||
|
||||
[profile.server-dev]
|
||||
inherits = "dev"
|
||||
|
||||
[profile.android-dev]
|
||||
inherits = "dev"
|
||||
|
@ -2,8 +2,7 @@ use crate::util::model::{
|
||||
member::{Member, MembersMigration},
|
||||
session::Session,
|
||||
};
|
||||
use dioxus::prelude::{dioxus_elements::FileEngine, *};
|
||||
use std::sync::Arc;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct UploadedFile {
|
||||
@ -31,12 +30,12 @@ pub fn Migration() -> Element {
|
||||
li { class: "step step-primary", "Uploaden" },
|
||||
li {
|
||||
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"
|
||||
},
|
||||
li {
|
||||
class: "step",
|
||||
class: if let Steps::Done = *step.read() { { "step-primary" } },
|
||||
class: if let Steps::Done = *step.read() { "step-primary" },
|
||||
"Klaar"
|
||||
},
|
||||
},
|
||||
@ -51,26 +50,23 @@ pub fn Migration() -> Element {
|
||||
|
||||
#[component]
|
||||
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 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 {
|
||||
if let Some(file_engine) = evt.files() {
|
||||
read_files(file_engine).await;
|
||||
}
|
||||
// TODO: Uncomment after bugfix dioxus
|
||||
// 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 {
|
||||
|
@ -50,17 +50,17 @@ pub fn NewsCreate() -> Element {
|
||||
li { class: "step step-primary", "Inhoud" },
|
||||
li {
|
||||
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"
|
||||
}
|
||||
li {
|
||||
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"
|
||||
}
|
||||
li {
|
||||
class: "step",
|
||||
class: if let Steps::Done = *step.read() { { "step-primary" } },
|
||||
class: if let Steps::Done = *step.read() { "step-primary" },
|
||||
"Klaar"
|
||||
}
|
||||
}
|
||||
|
62
src/main.rs
62
src/main.rs
@ -8,7 +8,6 @@ mod util;
|
||||
pub use err::Error;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use tracing::Level;
|
||||
|
||||
// Use routes
|
||||
use components::admin::members::migration::Migration;
|
||||
@ -22,6 +21,7 @@ use components::layout::Global;
|
||||
use components::news::create::NewsCreate;
|
||||
use components::news::News;
|
||||
use components::settings::Settings;
|
||||
use tracing::Level;
|
||||
|
||||
#[derive(Clone, Routable, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
#[rustfmt::skip]
|
||||
@ -49,43 +49,29 @@ pub enum Route {
|
||||
Migration {},
|
||||
}
|
||||
|
||||
const _TAILWIND_URL: &str = manganis::mg!(file("assets/tailwind.css"));
|
||||
#[cfg(feature = "server")]
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
dioxus::logger::init(Level::INFO).expect("Failed to init logger");
|
||||
|
||||
// Initialize surrealdb connection
|
||||
util::surrealdb::initialize()
|
||||
.await
|
||||
.expect("Error while initializing surrealdb");
|
||||
|
||||
let address = dioxus_cli_config::fullstack_address_or_localhost();
|
||||
|
||||
let router = axum::Router::new().serve_dioxus_application(ServeConfigBuilder::default(), App);
|
||||
|
||||
let router = router.into_make_service();
|
||||
let listener = tokio::net::TcpListener::bind(address).await.unwrap();
|
||||
|
||||
axum::serve(listener, router).await.unwrap();
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "server"))]
|
||||
fn main() {
|
||||
// Init logger
|
||||
dioxus_logger::init(Level::INFO).expect("failed to init logger");
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
{
|
||||
use axum::routing::*;
|
||||
|
||||
// Spawn main tokio runtime
|
||||
tokio::runtime::Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(async move {
|
||||
// Initialize surrealdb connection
|
||||
util::surrealdb::initialize()
|
||||
.await
|
||||
.expect("Error while initializing surrealdb");
|
||||
|
||||
// Create axum app
|
||||
let app = Router::new()
|
||||
.serve_dioxus_application(ServeConfig::builder().build(), || {
|
||||
VirtualDom::new(App)
|
||||
})
|
||||
.await;
|
||||
|
||||
// Run axum 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())
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
launch(App);
|
||||
dioxus::launch(App);
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -117,6 +103,10 @@ fn App() -> Element {
|
||||
use_context_provider(|| hours);
|
||||
|
||||
rsx! {
|
||||
document::Stylesheet {
|
||||
href: asset!("assets/tailwind.css")
|
||||
}
|
||||
|
||||
div {
|
||||
class: "h-screen flex flex-col",
|
||||
Router::<Route> {}
|
||||
|
@ -3,8 +3,6 @@ use crate::util::surrealdb::{thing_to_string, DB};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[cfg(feature = "server")]
|
||||
use surrealdb::sql::Thing;
|
||||
|
||||
use super::user::User;
|
||||
|
||||
@ -51,14 +49,10 @@ impl Session {
|
||||
|
||||
cookie.set_same_site(SameSite::Strict);
|
||||
|
||||
server_context()
|
||||
.response_parts_mut()
|
||||
.unwrap()
|
||||
.headers
|
||||
.insert(
|
||||
header::SET_COOKIE,
|
||||
HeaderValue::from_str(&cookie.to_string())?,
|
||||
);
|
||||
server_context().response_parts_mut().headers.insert(
|
||||
header::SET_COOKIE,
|
||||
HeaderValue::from_str(&cookie.to_string())?,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -104,14 +98,10 @@ impl Session {
|
||||
|
||||
cookie.set_same_site(SameSite::Strict);
|
||||
|
||||
server_context()
|
||||
.response_parts_mut()
|
||||
.unwrap()
|
||||
.headers
|
||||
.insert(
|
||||
header::SET_COOKIE,
|
||||
HeaderValue::from_str(&cookie.to_string())?,
|
||||
);
|
||||
server_context().response_parts_mut().headers.insert(
|
||||
header::SET_COOKIE,
|
||||
HeaderValue::from_str(&cookie.to_string())?,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -16,7 +16,11 @@ where
|
||||
}
|
||||
|
||||
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 {
|
||||
username: "root",
|
||||
@ -26,7 +30,7 @@ pub async fn initialize() -> surrealdb::Result<()> {
|
||||
|
||||
DB.use_ns("wrbapp").use_db("wrbapp").await?;
|
||||
|
||||
apply_queries().await?;
|
||||
apply_queries().await.expect("Failed to apply queries");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -47,7 +51,8 @@ async fn apply_queries() -> surrealdb::Result<()> {
|
||||
DEFINE INDEX userEmailIndex ON TABLE user COLUMNS email UNIQUE;
|
||||
",
|
||||
)
|
||||
.await?;
|
||||
.await
|
||||
.expect("Failed to apply user query");
|
||||
|
||||
DB.query(
|
||||
"
|
||||
|
Loading…
Reference in New Issue
Block a user