Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving hackernews examples to stable #2487

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions examples/hackernews/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]

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

[profile.release]
codegen-units = 1
lto = true
Expand All @@ -15,13 +19,13 @@ actix-files = { version = "0.6", optional = true }
actix-web = { version = "4", optional = true, features = ["macros"] }
console_log = "1"
console_error_panic_hook = "0.1"
leptos = { path = "../../leptos", features = ["nightly"] }
leptos_meta = { path = "../../meta", features = ["nightly"] }
leptos = { path = "../../leptos" }
leptos_actix = { path = "../../integrations/actix", optional = true }
leptos_router = { path = "../../router", features = ["nightly"] }
leptos_router = { path = "../../router" }
leptos_meta = { path = "../../meta" }
log = "0.4"
serde = { version = "1", features = ["derive"] }
gloo-net = { version = "0.2", features = ["http"] }
gloo-net = { version = "0.5", features = ["http"] }
reqwest = { version = "0.11", features = ["json"] }
tracing = "0.1"
# openssl = { version = "0.10", features = ["v110"] }
Expand All @@ -32,12 +36,12 @@ web-sys = { version = "0.3", features = ["AbortController", "AbortSignal"] }
csr = ["leptos/csr", "leptos_meta/csr", "leptos_router/csr"]
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
ssr = [
"dep:actix-files",
"dep:actix-web",
"dep:leptos_actix",
"leptos/ssr",
"leptos_meta/ssr",
"leptos_router/ssr",
"dep:actix-files",
"dep:actix-web",
"dep:leptos_actix",
"leptos/ssr",
"leptos_meta/ssr",
"leptos_router/ssr",
]

[profile.wasm-release]
Expand All @@ -51,6 +55,8 @@ denylist = ["actix-files", "actix-web", "leptos_actix"]
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_bin"
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "hackernews"
# 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
20 changes: 13 additions & 7 deletions examples/hackernews/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<link data-trunk rel="rust" data-wasm-opt="z" data-cargo-features="csr"/>
<link data-trunk rel="css" href="./style.css"/>
</head>
<body></body>
</html>
<head>
<link
data-trunk
rel="rust"
data-wasm-opt="z"
data-cargo-features="csr"
data-bin="hackernews_bin"
/>
<link data-trunk rel="css" href="./style.css" />
</head>
<body></body>
</html>
2 changes: 0 additions & 2 deletions examples/hackernews/rust-toolchain.toml

This file was deleted.

1 change: 1 addition & 0 deletions examples/hackernews/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async fn main() -> std::io::Result<()> {
#[cfg(not(feature = "ssr"))]
fn main() {
use hackernews::App;
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/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/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/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
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: 0 additions & 2 deletions examples/hackernews_axum/rust-toolchain.toml

This file was deleted.

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
9 changes: 3 additions & 6 deletions examples/hackernews_islands_axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ codegen-units = 1
lto = true

[dependencies]
leptos_meta = { path = "../../meta" }
console_log = "1.0"
console_error_panic_hook = "0.1"
leptos = { path = "../../leptos", features = [
"nightly",
"experimental-islands",
] }
leptos = { path = "../../leptos", features = ["experimental-islands"] }
leptos_axum = { path = "../../integrations/axum", optional = true, features = [
"experimental-islands",
] }
leptos_meta = { path = "../../meta", features = ["nightly"] }
leptos_router = { path = "../../router", features = ["nightly"] }
leptos_router = { path = "../../router" }
log = "0.4"
simple_logger = "4.0"
serde = { version = "1.0", features = ["derive"] }
Expand Down
14 changes: 7 additions & 7 deletions examples/hackernews_islands_axum/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!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" />
<link data-trunk rel="css" href="./style.css" />
</head>
<body></body>
</html>
2 changes: 0 additions & 2 deletions examples/hackernews_islands_axum/rust-toolchain.toml

This file was deleted.

6 changes: 3 additions & 3 deletions examples/hackernews_islands_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,11 +11,11 @@ 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
children= move | (_, error)| {
children=move | (_, error)| {
let error_string = error.to_string();
view! {

Expand Down
2 changes: 1 addition & 1 deletion examples/hackernews_islands_axum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(lazy_cell)]
#![cfg_attr(feature = "nightly", feature(Lazy_cell))]

use leptos::*;
use leptos_meta::*;
Expand Down
2 changes: 1 addition & 1 deletion examples/hackernews_islands_axum/src/routes/stories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn Stories() -> impl IntoView {
let (pending, set_pending) = create_signal(false);

let hide_more_link = move || {
pending()
pending.get()
|| stories
.map(|stories| {
stories.as_ref().map(|s| s.len() < 28).unwrap_or_default()
Expand Down
6 changes: 3 additions & 3 deletions examples/hackernews_islands_axum/src/routes/story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub async fn fetch_story(
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() {
Ok(RefCell::new(None))
Expand Down Expand Up @@ -94,7 +94,7 @@ pub fn Toggle(children: Children) -> impl IntoView {
view! {
<div class="toggle" class:open=open>
<a on:click=move |_| set_open.update(|n| *n = !*n)>
{move || if open() {
{move || if open.get() {
"[-]"
} else {
"[+] comments collapsed"
Expand All @@ -103,7 +103,7 @@ pub fn Toggle(children: Children) -> impl IntoView {
</div>
<ul
class="comment-children"
style:display=move || if open() {
style:display=move || if open.get() {
"block"
} else {
"none"
Expand Down
2 changes: 1 addition & 1 deletion examples/hackernews_islands_axum/src/routes/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub async fn fetch_user(
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() {
Ok(None)
Expand Down