From cb542e07d2f2219b29661da2ff5b5d67da6bfcf5 Mon Sep 17 00:00:00 2001 From: xeovalyte Date: Fri, 7 Jun 2024 14:04:19 +0200 Subject: [PATCH] Added modpack view --- Cargo.lock | 195 ++++++++++++++++++++++++++--- Cargo.toml | 1 + Dioxus.toml | 2 +- assets/tailwind.css | 59 ++------- src/components/modpacks.rs | 6 +- src/components/modpacks/modpack.rs | 50 ++++++++ src/components/new.rs | 4 +- src/main.rs | 6 + src/server/modpack.rs | 17 +++ 9 files changed, 265 insertions(+), 75 deletions(-) create mode 100644 src/components/modpacks/modpack.rs diff --git a/Cargo.lock b/Cargo.lock index 921d9f0..8b48e5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,6 +86,12 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea50b14b7a4b9343f8c627a7a53c52076482bd4bdad0a24fd3ec533ed616cc2c" +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + [[package]] name = "anymap" version = "0.12.1" @@ -701,6 +707,17 @@ dependencies = [ "nom", ] +[[package]] +name = "cfb" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d38f2da7a0a2c4ccf0065be06397cc26a81f4e528be095826eee9d4adbb8c60f" +dependencies = [ + "byteorder", + "fnv", + "uuid", +] + [[package]] name = "cfg-expr" version = "0.15.8" @@ -1027,7 +1044,7 @@ version = "0.5.2" source = "git+https://github.com/DioxusLabs/dioxus.git?branch=v0.5#e2002d6ea42f5844a3832ab7f038620ecf977a1c" dependencies = [ "dioxus-config-macro", - "dioxus-core", + "dioxus-core 0.5.2", "dioxus-core-macro", "dioxus-fullstack", "dioxus-hooks", @@ -1061,6 +1078,22 @@ dependencies = [ "quote", ] +[[package]] +name = "dioxus-core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "088daa3f45aaa729e9eef32dc0a9393dd709ee906b092089e5839cad1cad7c85" +dependencies = [ + "futures-channel", + "futures-util", + "generational-box 0.5.1", + "longest-increasing-subsequence", + "rustc-hash", + "slab", + "tracing", + "tracing-subscriber", +] + [[package]] name = "dioxus-core" version = "0.5.2" @@ -1068,7 +1101,7 @@ source = "git+https://github.com/DioxusLabs/dioxus.git?branch=v0.5#e2002d6ea42f5 dependencies = [ "futures-channel", "futures-util", - "generational-box", + "generational-box 0.5.2", "longest-increasing-subsequence", "rustc-hash", "serde", @@ -1139,12 +1172,12 @@ name = "dioxus-hooks" version = "0.5.2" source = "git+https://github.com/DioxusLabs/dioxus.git?branch=v0.5#e2002d6ea42f5844a3832ab7f038620ecf977a1c" dependencies = [ - "dioxus-core", + "dioxus-core 0.5.2", "dioxus-debug-cell", "dioxus-signals", "futures-channel", "futures-util", - "generational-box", + "generational-box 0.5.2", "slab", "thiserror", "tracing", @@ -1155,7 +1188,7 @@ name = "dioxus-hot-reload" version = "0.5.2" source = "git+https://github.com/DioxusLabs/dioxus.git?branch=v0.5#e2002d6ea42f5844a3832ab7f038620ecf977a1c" dependencies = [ - "dioxus-core", + "dioxus-core 0.5.2", "dioxus-html", "dioxus-rsx", "interprocess-docfix", @@ -1169,12 +1202,12 @@ version = "0.5.2" source = "git+https://github.com/DioxusLabs/dioxus.git?branch=v0.5#e2002d6ea42f5844a3832ab7f038620ecf977a1c" dependencies = [ "async-trait", - "dioxus-core", + "dioxus-core 0.5.2", "dioxus-html-internal-macro", "enumset", "euclid", "futures-channel", - "generational-box", + "generational-box 0.5.2", "keyboard-types", "serde", "serde-value", @@ -1201,7 +1234,7 @@ name = "dioxus-interpreter-js" version = "0.5.2" source = "git+https://github.com/DioxusLabs/dioxus.git?branch=v0.5#e2002d6ea42f5844a3832ab7f038620ecf977a1c" dependencies = [ - "dioxus-core", + "dioxus-core 0.5.2", "dioxus-html", "js-sys", "md5", @@ -1217,7 +1250,7 @@ name = "dioxus-lib" version = "0.5.2" source = "git+https://github.com/DioxusLabs/dioxus.git?branch=v0.5#e2002d6ea42f5844a3832ab7f038620ecf977a1c" dependencies = [ - "dioxus-core", + "dioxus-core 0.5.2", "dioxus-core-macro", "dioxus-hooks", "dioxus-html", @@ -1232,13 +1265,13 @@ source = "git+https://github.com/DioxusLabs/dioxus.git?branch=v0.5#e2002d6ea42f5 dependencies = [ "axum", "dioxus-cli-config", - "dioxus-core", + "dioxus-core 0.5.2", "dioxus-hot-reload", "dioxus-html", "dioxus-interpreter-js", "futures-channel", "futures-util", - "generational-box", + "generational-box 0.5.2", "rustc-hash", "serde", "serde_json", @@ -1299,7 +1332,7 @@ name = "dioxus-rsx" version = "0.5.2" source = "git+https://github.com/DioxusLabs/dioxus.git?branch=v0.5#e2002d6ea42f5844a3832ab7f038620ecf977a1c" dependencies = [ - "dioxus-core", + "dioxus-core 0.5.2", "internment", "krates", "proc-macro2", @@ -1313,10 +1346,10 @@ name = "dioxus-signals" version = "0.5.2" source = "git+https://github.com/DioxusLabs/dioxus.git?branch=v0.5#e2002d6ea42f5844a3832ab7f038620ecf977a1c" dependencies = [ - "dioxus-core", + "dioxus-core 0.5.2", "futures-channel", "futures-util", - "generational-box", + "generational-box 0.5.2", "once_cell", "parking_lot", "rustc-hash", @@ -1331,9 +1364,9 @@ dependencies = [ "askama_escape", "async-trait", "chrono", - "dioxus-core", + "dioxus-core 0.5.2", "dioxus-html", - "generational-box", + "generational-box 0.5.2", "http 1.1.0", "lru", "rustc-hash", @@ -1350,12 +1383,12 @@ source = "git+https://github.com/DioxusLabs/dioxus.git?branch=v0.5#e2002d6ea42f5 dependencies = [ "async-trait", "console_error_panic_hook", - "dioxus-core", + "dioxus-core 0.5.2", "dioxus-html", "dioxus-interpreter-js", "futures-channel", "futures-util", - "generational-box", + "generational-box 0.5.2", "js-sys", "rustc-hash", "serde", @@ -1763,6 +1796,15 @@ dependencies = [ "thread_local", ] +[[package]] +name = "generational-box" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f132919c96b85c02a067ceae965fd50ace57111e2f55c7384b95ac191f4d966b" +dependencies = [ + "parking_lot", +] + [[package]] name = "generational-box" version = "0.5.2" @@ -2180,6 +2222,15 @@ dependencies = [ "digest", ] +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" version = "0.2.12" @@ -2319,6 +2370,19 @@ dependencies = [ "tokio-rustls", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper 0.14.29", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "hyper-tls" version = "0.6.0" @@ -2416,6 +2480,15 @@ dependencies = [ "serde", ] +[[package]] +name = "infer" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6c16b11a665b26aeeb9b1d7f954cdeb034be38dd00adab4f2ae921a8fee804" +dependencies = [ + "cfb", +] + [[package]] name = "inout" version = "0.1.3" @@ -2721,6 +2794,46 @@ dependencies = [ "libc", ] +[[package]] +name = "manganis" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c211cfb4529c79b32307b606e83a1bb15d491b3b4a1ab97159b161d7af9d1b72" +dependencies = [ + "dioxus-core 0.5.1", + "manganis-macro", +] + +[[package]] +name = "manganis-common" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "542300f1e7d9313de5b7e5b92d273ba42ab547c068d773559d616aa14987de43" +dependencies = [ + "anyhow", + "base64 0.21.7", + "home", + "infer", + "reqwest 0.11.27", + "serde", + "toml", + "tracing", + "url", +] + +[[package]] +name = "manganis-macro" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "704a0123ac90fa630b21a04fde56c29dfd5a7665c5e8f3639567989daa2d29d1" +dependencies = [ + "manganis-common", + "proc-macro2", + "quote", + "syn 2.0.66", + "tracing-subscriber", +] + [[package]] name = "matchit" version = "0.7.3" @@ -3360,7 +3473,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" dependencies = [ - "toml_edit", + "toml_edit 0.21.1", ] [[package]] @@ -3625,11 +3738,13 @@ dependencies = [ "http-body 0.4.6", "hyper 0.14.29", "hyper-rustls", + "hyper-tls 0.5.0", "ipnet", "js-sys", "log", "mime", "mime_guess", + "native-tls", "once_cell", "percent-encoding", "pin-project-lite", @@ -3641,6 +3756,7 @@ dependencies = [ "sync_wrapper 0.1.2", "system-configuration", "tokio", + "tokio-native-tls", "tokio-rustls", "tokio-util", "tower-service", @@ -3669,7 +3785,7 @@ dependencies = [ "http-body 1.0.0", "http-body-util", "hyper 1.3.1", - "hyper-tls", + "hyper-tls 0.6.0", "hyper-util", "ipnet", "js-sys", @@ -4180,6 +4296,15 @@ dependencies = [ "syn 2.0.66", ] +[[package]] +name = "serde_spanned" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -5075,11 +5200,39 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.19.15", +] + [[package]] name = "toml_datetime" version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap 2.2.6", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] [[package]] name = "toml_edit" @@ -5383,6 +5536,7 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] @@ -5821,6 +5975,7 @@ dependencies = [ "axum-extra", "dioxus", "dioxus-logger", + "manganis", "once_cell", "reqwest 0.12.4", "serde", diff --git a/Cargo.toml b/Cargo.toml index 1ff4d23..eebbcce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ argon2 = { version = "0.5.3", optional = true } axum = { version = "0.7.5", optional = true } axum-extra = { version = "0.9.3", features = [ "cookie" ], optional = true} reqwest = { version = "0.12", features = ["json"] } +manganis = "0.2.2" # Debug tracing = "0.1.40" diff --git a/Dioxus.toml b/Dioxus.toml index 73c500b..e6cca9a 100644 --- a/Dioxus.toml +++ b/Dioxus.toml @@ -31,7 +31,7 @@ watch_path = ["src", "assets"] # CSS style file -style = ["tailwind.css"] +# style = ["tailwind.css"] # Javascript code file script = [] diff --git a/assets/tailwind.css b/assets/tailwind.css index 2d3fbc4..bf3ff0b 100644 --- a/assets/tailwind.css +++ b/assets/tailwind.css @@ -1919,24 +1919,20 @@ input.tab:checked + .tab-content, display: table; } -.w-full { - width: 100%; -} - -.w-96 { - width: 24rem; -} - .w-\[25rem\] { width: 25rem; } +.w-full { + width: 100%; +} + .max-w-2xl { max-width: 42rem; } -.max-w-4xl { - max-width: 56rem; +.max-w-7xl { + max-width: 80rem; } .max-w-lg { @@ -1947,16 +1943,8 @@ input.tab:checked + .tab-content, max-width: 28rem; } -.max-w-5xl { - max-width: 64rem; -} - -.max-w-6xl { - max-width: 72rem; -} - -.max-w-7xl { - max-width: 80rem; +.max-w-xl { + max-width: 36rem; } .flex-1 { @@ -1975,10 +1963,6 @@ input.tab:checked + .tab-content, gap: 1.25rem; } -.gap-10 { - gap: 2.5rem; -} - .gap-8 { gap: 2rem; } @@ -2060,34 +2044,7 @@ input.tab:checked + .tab-content, cursor: pointer; } -.hover\:bg-base-200:hover { - --tw-bg-opacity: 1; - background-color: var(--fallback-b2,oklch(var(--b2)/var(--tw-bg-opacity))); -} - -.hover\:bg-base-200\/80:hover { - background-color: var(--fallback-b2,oklch(var(--b2)/0.8)); -} - -.hover\:bg-base-200\/60:hover { - background-color: var(--fallback-b2,oklch(var(--b2)/0.6)); -} - -.hover\:bg-base-200\/50:hover { - background-color: var(--fallback-b2,oklch(var(--b2)/0.5)); -} - -.hover\:bg-base-300\/100:hover { - background-color: var(--fallback-b3,oklch(var(--b3)/1)); -} - .hover\:bg-base-300:hover { --tw-bg-opacity: 1; background-color: var(--fallback-b3,oklch(var(--b3)/var(--tw-bg-opacity))); -} - -.hover\:shadow-xl:hover { - --tw-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1); - --tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color); - box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow); } \ No newline at end of file diff --git a/src/components/modpacks.rs b/src/components/modpacks.rs index 922645a..3796010 100644 --- a/src/components/modpacks.rs +++ b/src/components/modpacks.rs @@ -1,4 +1,7 @@ +pub mod modpack; + use crate::server::modpack::Modpack; +use crate::Route; use dioxus::prelude::*; #[component] @@ -33,7 +36,8 @@ pub struct ModpackCardProps { #[component] pub fn ModpackCard(props: ModpackCardProps) -> Element { rsx! { - div { + Link { + to: Route::Modpack { id: props.modpack.id }, class: "card w-[25rem] bg-base-200 hover:bg-base-300 hover:cursor-pointer shadow-xl transition-all", div { class: "card-body", diff --git a/src/components/modpacks/modpack.rs b/src/components/modpacks/modpack.rs new file mode 100644 index 0000000..cd206b4 --- /dev/null +++ b/src/components/modpacks/modpack.rs @@ -0,0 +1,50 @@ +use dioxus::prelude::*; + +use crate::server::modpack::Modpack; + +#[component] +pub fn Modpack(id: String) -> Element { + let modpack = use_resource(move || { + to_owned![id]; + async move { get_modpack(id).await } + }); + + rsx! { + div { + class: "max-w-xl w-full mx-auto", + match &*modpack.read_unchecked() { + Some(Ok(response)) => rsx! { + Modpackview { modpack: response.to_owned() } + }, + Some(Err(_)) => rsx! { + "Modpack not found" + }, + None => rsx! { "Loading..." }, + } + + } + } +} + +#[component] +fn Modpackview(modpack: Modpack) -> Element { + rsx! { + h1 { class: "text-2xl font-bold mt-20", "{modpack.name}"} + div { + class: "mt-10", + "For Minecraft ", + b { "{modpack.game_version}" }, + " with ", + b { "{modpack.modloader}" }, + } + } +} + +#[server] +async fn get_modpack(id: String) -> Result { + use crate::server::auth::User; + + User::from_cookie().await?; + + Modpack::get(id).await +} diff --git a/src/components/new.rs b/src/components/new.rs index 90d4f00..0bdb5ec 100644 --- a/src/components/new.rs +++ b/src/components/new.rs @@ -20,14 +20,14 @@ pub fn New() -> Element { }); let submit = move |event: FormEvent| async move { - if let Ok(_modpack_id) = create_modpack( + if let Ok(modpack_id) = create_modpack( event.values()["name"].as_value(), event.values()["game_version"].as_value(), event.values()["modloader"].as_value(), ) .await { - nav.push(Route::Modpacks {}); + nav.push(Route::Modpack { id: modpack_id }); } }; diff --git a/src/main.rs b/src/main.rs index 3c4593a..76f54af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,10 +4,12 @@ mod modrinth; mod server; use dioxus::prelude::*; +use manganis::*; use tracing::{info, Level}; use components::home::Home; use components::layout::authenticated::Authenticated; +use components::modpacks::modpack::Modpack; use components::modpacks::Modpacks; use components::new::New; use server::auth; @@ -19,6 +21,8 @@ pub enum Route { #[layout(Authenticated)] #[route("/modpacks")] Modpacks {}, + #[route("/modpacks/:id")] + Modpack { id: String }, #[route("/new")] New {}, #[end_layout] @@ -30,6 +34,8 @@ fn main() { // Init logger dioxus_logger::init(Level::INFO).expect("failed to init logger"); + const _: &str = manganis::mg!(file("assets/tailwind.css")); + #[cfg(feature = "server")] { use axum::routing::*; diff --git a/src/server/modpack.rs b/src/server/modpack.rs index d4a0d2d..389fa40 100644 --- a/src/server/modpack.rs +++ b/src/server/modpack.rs @@ -60,4 +60,21 @@ impl Modpack { Ok(modpacks) } + + #[cfg(feature = "server")] + pub async fn get(id: String) -> Result { + let mut res = DB + .query("SELECT type::string(id) as id, type::string(owner) as owner_id, name, modloader, game_version, projects FROM modpack WHERE type::string(id) = $id;") + .bind(("id", id)) + .await?; + + let modpack: Option = res.take(0)?; + + match modpack { + Some(m) => Ok(m), + None => Err(ServerFnError::ServerError( + "Could not get modpack".to_string(), + )), + } + } }