Fix change page

This commit is contained in:
eraden 2022-05-12 08:38:31 +02:00
parent 45ce1e89f6
commit 19115f0dd9
6 changed files with 107 additions and 9 deletions

75
Cargo.lock generated
View File

@ -1564,6 +1564,8 @@ dependencies = [
"libc", "libc",
"libgit2-sys", "libgit2-sys",
"log", "log",
"openssl-probe",
"openssl-sys",
"url", "url",
] ]
@ -2047,10 +2049,26 @@ checksum = "19e1c899248e606fbfe68dcb31d8b0176ebab833b103824af31bddf4b7457494"
dependencies = [ dependencies = [
"cc", "cc",
"libc", "libc",
"libssh2-sys",
"libz-sys", "libz-sys",
"openssl-sys",
"pkg-config", "pkg-config",
] ]
[[package]]
name = "libssh2-sys"
version = "0.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b094a36eb4b8b8c8a7b4b8ae43b2944502be3e59cd87687595cf6b0a71b3f4ca"
dependencies = [
"cc",
"libc",
"libz-sys",
"openssl-sys",
"pkg-config",
"vcpkg",
]
[[package]] [[package]]
name = "libz-sys" name = "libz-sys"
version = "1.1.6" version = "1.1.6"
@ -2201,6 +2219,15 @@ dependencies = [
"unicase", "unicase",
] ]
[[package]]
name = "minidom"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "332592c2149fc7dd40a64fc9ef6f0d65607284b474cef9817d1fc8c7e7b3608e"
dependencies = [
"quick-xml",
]
[[package]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
version = "0.2.1" version = "0.2.1"
@ -2775,6 +2802,15 @@ version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quick-xml"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26aab6b48e2590e4a64d1ed808749ba06257882b461d01ca71baeb747074a6dd"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.18" version = "1.0.18"
@ -3164,6 +3200,42 @@ dependencies = [
"web-sys", "web-sys",
] ]
[[package]]
name = "seed"
version = "0.9.1"
source = "git+https://github.com/seed-rs/seed#689055ef4f466f28dca621c23f5e2df7438bd1bc"
dependencies = [
"console_error_panic_hook",
"cookie",
"dbg",
"enclose",
"futures",
"getrandom",
"gloo-file",
"gloo-timers",
"gloo-utils",
"indexmap",
"js-sys",
"rand",
"serde",
"serde_json",
"uuid",
"version_check 0.9.4",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
]
[[package]]
name = "seed_heroicons"
version = "0.1.0"
source = "git+https://github.com/mh84/seed_heroicons.git#32569ac5ba9adcffb168fbdaac8b258e99e73d86"
dependencies = [
"git2",
"minidom",
"seed 0.9.1 (git+https://github.com/seed-rs/seed)",
]
[[package]] [[package]]
name = "semver" name = "semver"
version = "0.9.0" version = "0.9.0"
@ -4278,7 +4350,8 @@ dependencies = [
"model", "model",
"pure-rust-locales", "pure-rust-locales",
"rusty-money", "rusty-money",
"seed", "seed 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"seed_heroicons",
"serde", "serde",
"serde-wasm-bindgen", "serde-wasm-bindgen",
"serde_json", "serde_json",

View File

@ -10,6 +10,7 @@ crate-type = ["cdylib"]
model = { path = "../shared/model", features = ["dummy"] } model = { path = "../shared/model", features = ["dummy"] }
seed = { version = "0.9.1", features = [] } seed = { version = "0.9.1", features = [] }
seed_heroicons = { git = "https://github.com/mh84/seed_heroicons.git" }
chrono = { version = "*" } chrono = { version = "*" }
gloo-timers = { version = "*", features = ["futures"] } gloo-timers = { version = "*", features = ["futures"] }

View File

@ -42,6 +42,22 @@ macro_rules! fetch_page {
_ => return, _ => return,
} }
}}; }};
(public page $page: expr, $page_name: ident, $ret: expr) => {{
let p = match $page {
crate::pages::Page::Public(p) => p,
_ => {
*$page = $ret;
return;
}
};
match p {
crate::pages::PublicPage::$page_name(p) => p,
_ => {
*$page = $ret;
return;
}
}
}};
} }
fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model { fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
@ -81,7 +97,7 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
} }
} }
} }
Msg::UrlChanged(subs::UrlChanged(url)) => model.page.page_changed(url), Msg::UrlChanged(subs::UrlChanged(url)) => model.page.page_changed(url, orders),
Msg::Public(pages::public::Msg::Listing(msg)) => { Msg::Public(pages::public::Msg::Listing(msg)) => {
let page = fetch_page!(public model, Listing); let page = fetch_page!(public model, Listing);
pages::public::listing::update(msg, page, &mut orders.proxy(proxy_public_listing)); pages::public::listing::update(msg, page, &mut orders.proxy(proxy_public_listing));

View File

@ -56,18 +56,18 @@ impl Page {
} }
} }
pub fn page_changed(&mut self, url: Url) { pub fn page_changed(&mut self, url: Url, orders: &mut impl Orders<Msg>) {
match url.clone().remaining_path_parts().as_slice() { match url.clone().remaining_path_parts().as_slice() {
[] => { [] => {
let page = crate::fetch_page!(public page self, Listing); let page = crate::fetch_page!(public page self, Listing, Page::init(url, orders));
public::listing::page_changed(url, page); public::listing::page_changed(url, page);
} }
["products", _rest @ ..] => { ["products", _rest @ ..] => {
let page = crate::fetch_page!(public page self, Listing); let page = crate::fetch_page!(public page self, Listing, Page::init(url, orders));
public::listing::page_changed(url, page); public::listing::page_changed(url, page);
} }
["page", ..] => { ["product", ..] => {
let page = crate::fetch_page!(public page self, Product); let page = crate::fetch_page!(public page self, Product, Page::init(url, orders));
public::product::page_changed(url, page); public::product::page_changed(url, page);
} }
["admin"] => {} ["admin"] => {}

View File

@ -1,6 +1,5 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use model::api::Product;
use seed::app::Orders; use seed::app::Orders;
use seed::prelude::*; use seed::prelude::*;
use seed::*; use seed::*;

View File

@ -49,6 +49,13 @@ pub fn view(model: &crate::Model, page: &ProductPage) -> Node<crate::Msg> {
.iter() .iter()
.enumerate() .enumerate()
.map(|(idx, img)| image(idx, img)); .map(|(idx, img)| image(idx, img));
let description = product
.long_description
.as_str()
.split('\n')
.map(|s| div![s]);
let content = div![ let content = div![
C!["max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 mt-6"], C!["max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 mt-6"],
div![ div![
@ -65,10 +72,12 @@ pub fn view(model: &crate::Model, page: &ProductPage) -> Node<crate::Msg> {
h2![ h2![
C!["mb-2 leading-tight tracking-tight font-bold text-gray-800 text-2xl md:text-3xl"], C!["mb-2 leading-tight tracking-tight font-bold text-gray-800 text-2xl md:text-3xl"],
product.name.as_str() product.name.as_str()
] ],
div![description]
] ]
] ]
].map_msg(map_to_global); ].map_msg(map_to_global);
div![ div![
crate::shared::view::public_navbar(model), crate::shared::view::public_navbar(model),
super::layout::view(model.url.clone(), content, None) super::layout::view(model.url.clone(), content, None)