Skip to content

Commit

Permalink
moved hacker news axum to stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Alt-iOS committed Apr 2, 2024
1 parent 8d93c58 commit f11e21f
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/hackernews/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ denylist = ["actix-files", "actix-web", "leptos_actix"]
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]

[package.metadata.leptos]
#Added to avoid name collition with lib package
#Had to change default name of the bin to avoid name collition with lib package when using trunk, this lets cargo_leptos know what the name will be
bin-exe-name = "hackernews_bin"
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "hackernews"
Expand Down
14 changes: 10 additions & 4 deletions examples/hackernews_axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@ edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]

[[bin]]
name = "hackernews_axum_bin"
path = "./src/main.rs"

[profile.release]
codegen-units = 1
lto = true

[dependencies]
console_log = "1.0"
console_error_panic_hook = "0.1"
leptos = { path = "../../leptos", features = ["nightly"] }
leptos = { path = "../../leptos" }
leptos_axum = { path = "../../integrations/axum", optional = true }
leptos_meta = { path = "../../meta", features = ["nightly"] }
leptos_router = { path = "../../router", features = ["nightly"] }
leptos_meta = { path = "../../meta" }
leptos_router = { path = "../../router" }
log = "0.4"
simple_logger = "4.0"
serde = { version = "1.0", features = ["derive"] }
tracing = "0.1"
gloo-net = { version = "0.4", features = ["http"] }
gloo-net = { version = "0.5", features = ["http"] }
reqwest = { version = "0.11", features = ["json"] }
axum = { version = "0.7", optional = true }
tower = { version = "0.4", optional = true }
Expand Down Expand Up @@ -52,6 +56,8 @@ denylist = ["axum", "tower", "tower-http", "tokio", "http", "leptos_axum"]
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]

[package.metadata.leptos]
#Had to change default name of the bin to avoid name collition with lib package when using trunk, this lets cargo_leptos know what the name will be
bin-exe-name = "hackernews_axum_bin"
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "hackernews_axum"
# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
Expand Down
19 changes: 12 additions & 7 deletions examples/hackernews_axum/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<link data-trunk rel="rust" data-wasm-opt="z"/>
<link data-trunk rel="css" href="/style.css"/>
</head>
<body></body>
</html>
<head>
<link
data-trunk
rel="rust"
data-wasm-opt="z"
data-bin="hackernews_axum_bin"
/>
<link data-trunk rel="css" href="/style.css" />
</head>
<body></body>
</html>
2 changes: 1 addition & 1 deletion examples/hackernews_axum/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly-2024-03-31"
channel = "stable"
4 changes: 2 additions & 2 deletions examples/hackernews_axum/src/error_template.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use leptos::{view, Errors, For, IntoView, RwSignal, View};
use leptos::{view, Errors, For, IntoView, RwSignal, SignalGet, View};

// A basic function to display errors served by the error boundaries. Feel free to do more complicated things
// here than just displaying them
Expand All @@ -11,7 +11,7 @@ pub fn error_template(errors: Option<RwSignal<Errors>>) -> View {
<h1>"Errors"</h1>
<For
// a function that returns the items we're iterating over; a signal is fine
each=errors
each={move || errors.get()}
// a unique key for each item as a reference
key=|(key, _)| key.clone()
// renders each item to a view
Expand Down
1 change: 1 addition & 0 deletions examples/hackernews_axum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async fn main() {
#[cfg(not(feature = "ssr"))]
pub fn main() {
use hackernews_axum::*;
use leptos::mount_to_body;

_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
Expand Down
2 changes: 1 addition & 1 deletion examples/hackernews_axum/src/routes/stories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn Stories() -> impl IntoView {

let hide_more_link = move || {
stories.get().unwrap_or(None).unwrap_or_default().len() < 28
|| pending()
|| pending.get()
};

view! {
Expand Down
6 changes: 3 additions & 3 deletions examples/hackernews_axum/src/routes/story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use leptos_router::*;
pub fn Story() -> impl IntoView {
let params = use_params_map();
let story = create_resource(
move || params().get("id").cloned().unwrap_or_default(),
move || params.get().get("id").cloned().unwrap_or_default(),
move |id| async move {
if id.is_empty() {
None
Expand Down Expand Up @@ -87,15 +87,15 @@ pub fn Comment(comment: api::Comment) -> impl IntoView {
<a on:click=move |_| set_open.update(|n| *n = !*n)>
{
let comments_len = comment.comments.len();
move || if open() {
move || if open.get() {
"[-]".into()
} else {
format!("[+] {}{} collapsed", comments_len, pluralize(comments_len))
}
}
</a>
</div>
{move || open().then({
{move || open.get().then({
let comments = comment.comments.clone();
move || view! {
<ul class="comment-children">
Expand Down
2 changes: 1 addition & 1 deletion examples/hackernews_axum/src/routes/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use leptos_router::*;
pub fn User() -> impl IntoView {
let params = use_params_map();
let user = create_resource(
move || params().get("id").cloned().unwrap_or_default(),
move || params.get().get("id").cloned().unwrap_or_default(),
move |id| async move {
if id.is_empty() {
None
Expand Down

0 comments on commit f11e21f

Please sign in to comment.