Skip to content

Commit

Permalink
feat: add loading indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
dancixx committed Nov 5, 2024
1 parent e7d63f1 commit 4e41a08
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
Binary file added public/rust_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use leptos::*;
use leptos_meta::Title;

use crate::api::{select_posts, select_tags};
use crate::loader;

#[component]
pub fn Component() -> impl IntoView {
Expand All @@ -17,7 +18,7 @@ pub fn Component() -> impl IntoView {

view! {
<Title text="Tech Diaries - The Official Rust-DD Developer Blog" />
<Suspense fallback=|| ()>
<Suspense fallback=|| view! { <loader::Component /> }>
<div class="flex flex-row flex-wrap gap-1 px-4 text-xs">
<button
on:click=move |_| selected_tags.update(|prev| prev.clear())
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod error_template;
#[cfg(feature = "ssr")]
pub mod fileserv;
pub mod home;
pub mod loader;
pub mod post;
#[cfg(feature = "ssr")]
pub mod redirect;
Expand Down
11 changes: 11 additions & 0 deletions src/loader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use leptos::*;

#[component]
pub fn Component() -> impl IntoView {
view! {
<div class="flex absolute inset-0 flex-col gap-1 justify-center items-center m-auto">
<img src="/rust_color.png" width=32 height=32 class="animate-spin" />
<p class="text-sm italic text-muted-foreground">Loading...</p>
</div>
}
}
5 changes: 4 additions & 1 deletion src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use leptos_meta::*;
use leptos_router::*;

use crate::api::{increment_views, select_post};
use crate::loader;

#[component]
pub fn Component() -> impl IntoView {
Expand All @@ -26,7 +27,9 @@ pub fn Component() -> impl IntoView {
});

view! {
<Suspense fallback=|| ()>
<Suspense fallback=|| {
view! { <loader::Component /> }
}>
{move || {
post.with(|post| {
let post = post.clone().unwrap_or_default();
Expand Down

0 comments on commit 4e41a08

Please sign in to comment.