Skip to content

Commit da5f84f

Browse files
committed
add intro page and general improvements
1 parent e4d2915 commit da5f84f

File tree

9 files changed

+105
-12
lines changed

9 files changed

+105
-12
lines changed

example/start-csr/bun.lockb

1.99 KB
Binary file not shown.

example/start-csr/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dependencies": {},
77
"devDependencies": {
88
"@tailwindcss/forms": "^0.5.7",
9+
"@tailwindcss/typography": "^0.5.10",
910
"concurrently": "^8.2.2",
1011
"tailwindcss": "^3.4.1"
1112
}

example/start-csr/src/layout.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use leptos::*;
44
use leptos_meta::Html;
55
use leptos_query::query_persister::{IndexedDbPersister, LocalStoragePersister};
66
use leptos_query::use_query_client;
7+
use leptos_theme::theme::use_theme;
8+
use leptos_theme::types::Theme;
79
use leptos_use::storage::use_local_storage;
810
use leptos_use::utils::FromToStringCodec;
911

@@ -12,11 +14,14 @@ use crate::components::switch::Switch;
1214
#[component]
1315
pub fn Layout(children: Children) -> impl IntoView {
1416
view! {
15-
<div class="relative flex min-h-screen flex-col bg-background">
16-
<div class="flex-1 items-start grid grid-cols-[180px_minmax(0,1fr)] md:gap-6 lg:grid-cols-[200px_minmax(0,1fr)] lg:gap-10">
17-
<aside class="h-full w-full shrink-0 border-r">
17+
<div class="relative flex h-screen flex-col bg-background">
18+
<div class="flex-1 items-start grid grid-cols-[180px_minmax(0,1fr)] lg:grid-cols-[200px_minmax(0,1fr)]">
19+
<aside class="h-screen w-full shrink-0 border-r">
1820
<div class="relative overflow-hidden h-full py-6 pr-6 lg:py-8 px-2 md:px-4">
1921
<SidebarLink href="/">Home</SidebarLink>
22+
<div class="text-sm">
23+
<SidebarLink href="/intro">Why Leptos Query</SidebarLink>
24+
</div>
2025
<div class="py-2"></div>
2126
<h4 class="rounded-md px-2 py-1 text-base font-semibold">Examples</h4>
2227
<div class="grid grid-flow-row auto-rows-max text-sm">
@@ -29,7 +34,9 @@ pub fn Layout(children: Children) -> impl IntoView {
2934
</div>
3035
</div>
3136
</aside>
32-
<main class="container relative py-6 lg:py-8">{children()}</main>
37+
<main class="container relative py-6 lg:py-8 overflow-y-auto max-h-screen">
38+
{children()}
39+
</main>
3340
</div>
3441
</div>
3542
}
@@ -41,7 +48,7 @@ fn ThemeToggle() -> impl IntoView {
4148
let is_dark = Signal::derive(move || current_theme.get() == Theme::Dark);
4249

4350
view! {
44-
// <Html class=move || if is_dark.get() { "dark" } else { "" }/>
51+
<Html class=move || if is_dark.get() { "dark" } else { "" }/>
4552
<label
4653
for="dark-mode-toggle"
4754
class="text-xs font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"

example/start-csr/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub fn App() -> impl IntoView {
6262
<Route path="/" view=Home/>
6363
<Route path="/single" view=pages::single::QueryVsResource/>
6464
<Route path="/todos" view=pages::interactive::Interactive/>
65+
<Route path="/intro" view=pages::intro::Introduction/>
6566
<Route path="/*" view=NotFound/>
6667
</Routes>
6768
</Router>

example/start-csr/src/pages/home.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ pub fn Home() -> impl IntoView {
4242

4343
<div class="flex w-full items-center justify-center space-x-4">
4444
<a
45-
class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground shadow hover:bg-primary/90 h-9 px-4 py-2 w-28"
45+
class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground shadow hover:bg-primary/90 h-9 px-4 py-2 w-24 lg:w-28"
46+
href="/intro"
47+
>
48+
Overview
49+
</a>
50+
<a
51+
class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground h-9 px-4 py-2 w-24 lg:w-28"
4652
href="https://docs.rs/leptos_query/latest/leptos_query/"
4753
target="_blank"
4854
rel="noopener noreferrer"
@@ -52,10 +58,10 @@ pub fn Home() -> impl IntoView {
5258
<a
5359
target="_blank"
5460
rel="noopener noreferrer"
55-
class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foAreground h-9 px-4 py-2 w-28"
61+
class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground h-9 px-4 py-2 w-24 lg:w-28"
5662
href="https://github.com/nicoburniske/leptos_query"
5763
>
58-
<svg viewBox="0 0 438.549 438.549" class="mr-2 h-4 w-4">
64+
<svg viewBox="0 0 438.549 438.549" class="mr-2 h-4 w-4 flex-none">
5965
<path
6066
fill="currentColor"
6167
d="M409.132 114.573c-19.608-33.596-46.205-60.194-79.798-79.8-33.598-19.607-70.277-29.408-110.063-29.408-39.781 0-76.472 9.804-110.063 29.408-33.596 19.605-60.192 46.204-79.8 79.8C9.803 148.168 0 184.854 0 224.63c0 47.78 13.94 90.745 41.827 128.906 27.884 38.164 63.906 64.572 108.063 79.227 5.14.954 8.945.283 11.419-1.996 2.475-2.282 3.711-5.14 3.711-8.562 0-.571-.049-5.708-.144-15.417a2549.81 2549.81 0 01-.144-25.406l-6.567 1.136c-4.187.767-9.469 1.092-15.846 1-6.374-.089-12.991-.757-19.842-1.999-6.854-1.231-13.229-4.086-19.13-8.559-5.898-4.473-10.085-10.328-12.56-17.556l-2.855-6.57c-1.903-4.374-4.899-9.233-8.992-14.559-4.093-5.331-8.232-8.945-12.419-10.848l-1.999-1.431c-1.332-.951-2.568-2.098-3.711-3.429-1.142-1.331-1.997-2.663-2.568-3.997-.572-1.335-.098-2.43 1.427-3.289 1.525-.859 4.281-1.276 8.28-1.276l5.708.853c3.807.763 8.516 3.042 14.133 6.851 5.614 3.806 10.229 8.754 13.846 14.842 4.38 7.806 9.657 13.754 15.846 17.847 6.184 4.093 12.419 6.136 18.699 6.136 6.28 0 11.704-.476 16.274-1.423 4.565-.952 8.848-2.383 12.847-4.285 1.713-12.758 6.377-22.559 13.988-29.41-10.848-1.14-20.601-2.857-29.264-5.14-8.658-2.286-17.605-5.996-26.835-11.14-9.235-5.137-16.896-11.516-22.985-19.126-6.09-7.614-11.088-17.61-14.987-29.979-3.901-12.374-5.852-26.648-5.852-42.826 0-23.035 7.52-42.637 22.557-58.817-7.044-17.318-6.379-36.732 1.997-58.24 5.52-1.715 13.706-.428 24.554 3.853 10.85 4.283 18.794 7.952 23.84 10.994 5.046 3.041 9.089 5.618 12.135 7.708 17.705-4.947 35.976-7.421 54.818-7.421s37.117 2.474 54.823 7.421l10.849-6.849c7.419-4.57 16.18-8.758 26.262-12.565 10.088-3.805 17.802-4.853 23.134-3.138 8.562 21.509 9.325 40.922 2.279 58.24 15.036 16.18 22.559 35.787 22.559 58.817 0 16.178-1.958 30.497-5.853 42.966-3.9 12.471-8.941 22.457-15.125 29.979-6.191 7.521-13.901 13.85-23.131 18.986-9.232 5.14-18.182 8.85-26.84 11.136-8.662 2.286-18.415 4.004-29.263 5.146 9.894 8.562 14.842 22.077 14.842 40.539v60.237c0 3.422 1.19 6.279 3.572 8.562 2.379 2.279 6.136 2.95 11.276 1.995 44.163-14.653 80.185-41.062 108.068-79.226 27.88-38.161 41.825-81.126 41.825-128.906-.01-39.771-9.818-76.454-29.414-110.049z"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
use leptos::*;
2+
3+
#[component]
4+
pub fn Introduction() -> impl IntoView {
5+
view! {
6+
<article
7+
class=" p-4 prose dark:prose-invert max-w-[75ch] mx-auto lg:prose-lg prose-zinc
8+
prose-p:text-foreground prose-headings:text-foreground prose-lead:text-foreground prose-li:text-foreground prose-ul:text-foreground prose-ol:text-foreground
9+
prose-hr:border-border prose-hr:my-2
10+
prose-h1:my-1 lg:prose-h1:my-1
11+
prose-h2:my-1 lg:prose-h2:my-1
12+
">
13+
<h1>Why Leptos Query?</h1>
14+
<hr></hr>
15+
<strong>What is a Query? What is async state?</strong>
16+
<p>Broadly, a Query is an async request for data, bound to a unique key. You often (but not always) "don't" own that state on the client.
17+
</p>
18+
<p>
19+
"We'll" call this state <code>Async State</code>.
20+
Here are some common properties:
21+
</p>
22+
<ul>
23+
<li>You do not control or own the "source of truth" on the client</li>
24+
<li>Requires async APIs for fetching data</li>
25+
<li>
26+
Implies shared ownership and can be changed by other people without your knowledge
27+
</li>
28+
<li>
29+
Can potentially become "out of date" in your apps if "you're" not careful
30+
</li>
31+
</ul>
32+
<p>
33+
Very often in programming highly dynamic web apps, you end up creating a client-side state machine to keep some
34+
<code>Async State</code>
35+
in sync with the actual source of truth (usually the server/database or the browser).
36+
</p>
37+
<p>
38+
This helps make your app "feel" more responsive, with instant updates and the like.
39+
</p>
40+
<h4> But there are issues... </h4>
41+
<ul>
42+
<li>"It's" a ton of work to get right</li>
43+
<li>
44+
"It's" incredibly easy to get wrong (have incorrect state, requiring a page refresh)
45+
</li>
46+
<li>
47+
It "doesn't" scale well. The more state you have, the more complex it gets
48+
</li>
49+
</ul>
50+
<h4>Here are some of the common challenges</h4>
51+
<ul>
52+
<li>Knowing when data is "out of date"</li>
53+
<li>Updating "out of date" data in the background</li>
54+
<li>No duplicate fetches for same data</li>
55+
<li>Configurable cache lifetimes</li>
56+
<li>Invalidation</li>
57+
<li>Cancellation</li>
58+
<li>Managing memory and garbage collection</li>
59+
<li>Updates (set to new value, update mut existing value, etc.)</li>
60+
<li>Client side persistence (local storage, indexed db, etc.)</li>
61+
</ul>
62+
<p>"Here's" where a Leptos Query comes in.</p>
63+
<h2>Leptos Query to the rescue</h2>
64+
<hr></hr>
65+
<p>
66+
Leptos Query is a client-side Query Manager, helping you manage
67+
<code>Async State</code> for highly dynamic and interactive Leptos web apps, which handles all of the above problems.
68+
</p>
69+
Practically speaking, by using Leptos Query, you will likely:
70+
<ul>
71+
<li>Reduce your code complexity and improve code maintainability by removing a lot of state management from your client side code</li>
72+
<li>Improve the user experience by improving the speed and responsiveness of your app</li>
73+
<li>Have a nicer debugging experience, with the provided Devtools</li>
74+
</ul>
75+
</article>
76+
}
77+
}

example/start-csr/src/pages/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod home;
22
pub mod interactive;
3+
pub mod intro;
34
pub mod not_found;
45
pub mod single;

example/start-csr/src/pages/single.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use crate::components::{skeleton::Skeleton, spinner::Spinner, Loud};
99
#[component]
1010
pub fn QueryVsResource() -> impl IntoView {
1111
view! {
12-
<div class="container mx-auto p-8">
13-
<div class="flex flex-col gap-8">
12+
<div class="container mx-auto p-8 max-w-2xl">
13+
<div class="flex flex-col gap-8 ">
1414
<SingleQuery/>
15-
<div class="h-2 w-full bg-border rounded-xl"></div>
15+
<div class="h-1 w-full bg-border rounded-xl"></div>
1616
<SingleResource/>
1717
</div>
1818
</div>

example/start-csr/tailwind.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ module.exports = {
5151
},
5252
},
5353
},
54-
plugins: [require("@tailwindcss/forms")],
54+
plugins: [require("@tailwindcss/typography"), require("@tailwindcss/forms")],
5555
};

0 commit comments

Comments
 (0)