From 6c8bc1ae274e3c5ca7dec266637b0e130f744612 Mon Sep 17 00:00:00 2001 From: Adam <24621027+adoyle0@users.noreply.github.com> Date: Mon, 15 Jan 2024 16:58:26 -0500 Subject: [PATCH] actually feed articles properly --- doordesk/app/src/components/article.rs | 31 +++--------------------- doordesk/app/src/components/slingshot.rs | 10 +++++++- doordesk/app/src/lib.rs | 22 ++++++++--------- doordesk/app/src/routes.rs | 4 +-- doordesk/app/src/routes/home.rs | 15 +++++++++++- 5 files changed, 39 insertions(+), 43 deletions(-) diff --git a/doordesk/app/src/components/article.rs b/doordesk/app/src/components/article.rs index a99f412..fe468a6 100644 --- a/doordesk/app/src/components/article.rs +++ b/doordesk/app/src/components/article.rs @@ -2,40 +2,17 @@ use crate::components::slingshot::*; use leptos::*; #[component] -pub fn Article() -> impl IntoView { - let data = create_resource( - || (), - |_| async move { - logging::log!("loading data from slingshot"); - slingshot().await - }, - ); +pub fn Article(data: ArticleData) -> impl IntoView { view! {

- {move || match data.get() { - None => "Loading...".to_string(), - Some(data) => data.unwrap().title, - }} - + {&data.title}


- - {move || match data.get() { - None => "Loading...".to_string(), - Some(data) => data.unwrap().date, - }} - - -
- {move || match data.get() { - None => "Loading...".to_string(), - Some(data) => data.unwrap().content, - }} - -
+ {&data.date} +
{&data.content}
} diff --git a/doordesk/app/src/components/slingshot.rs b/doordesk/app/src/components/slingshot.rs index 4d020cc..64054f7 100644 --- a/doordesk/app/src/components/slingshot.rs +++ b/doordesk/app/src/components/slingshot.rs @@ -1,5 +1,12 @@ use leptos::*; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; + +use std::time::Duration; +use std::thread::sleep; + +pub fn fetch(path: &str) -> String { + format!("https://dennis.doordesk.net/{path}") +} #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ArticleData { @@ -18,5 +25,6 @@ pub async fn slingshot() -> Result { content: String::from("Testicles"), }; + sleep(Duration::from_secs(1)); Ok(data) } diff --git a/doordesk/app/src/lib.rs b/doordesk/app/src/lib.rs index 8852da9..a1f3685 100644 --- a/doordesk/app/src/lib.rs +++ b/doordesk/app/src/lib.rs @@ -1,34 +1,29 @@ use crate::error_template::{AppError, ErrorTemplate}; -//use crate::routes::{blog::*, home::*, projects::*}; use leptos::*; use leptos_meta::*; use leptos_router::*; -pub mod error_template; pub mod components; +pub mod error_template; pub mod routes; -use crate::routes::{home::*, blog::*, projects::*}; +// use crate::routes::{blog::*, home::*, projects::*}; +use crate::routes::home::Home; #[component] pub fn App() -> impl IntoView { - // Provides context that manages stylesheets, titles, meta tags, etc. provide_meta_context(); view! { - - // sets the document title - - // content for this welcome page <Router fallback=|| { let mut outside_errors = Errors::default(); outside_errors.insert_with_default_key(AppError::NotFound); view! { <ErrorTemplate outside_errors/> }.into_view() }> - <nav class="bg-gradient-to-b from-zinc-800 to-zinc-900 shadow-lg sticky top-0"> + <nav class="sticky top-0 bg-gradient-to-b shadow-lg from-zinc-800 to-zinc-900"> <ul class="container flex items-center p-3"> <li class="mx-1.5 sm:mx-6">"DoorDesk"</li> <li class="mx-1.5 sm:mx-6"> @@ -42,16 +37,19 @@ pub fn App() -> impl IntoView { <li class="mx-1.5 sm:mx-6"> <A href="/projects">"Projects"</A> </li> + <li class="mx-1.5 sm:mx-6"> + <a href="https://git.doordesk.net">"Git"</a> + </li> </ul> </nav> <main> <Routes> <Route path="" view=Home/> - <Route path="blog" view=Blog/> - <Route path="projects" view=Projects/> + // <Route path="blog" view=Blog/> + // <Route path="projects" view=Projects/> </Routes> </main> - <p class="text-center hover:rotate-180 duration-200 w-8 m-auto"> + <p class="m-auto w-8 text-center duration-200 hover:rotate-180"> <a href="https://open.spotify.com/playlist/3JRNw9gpt1w5ptsw8uDeYc?si=8f7e4191113f41f9"> ":)" </a> diff --git a/doordesk/app/src/routes.rs b/doordesk/app/src/routes.rs index a28ef14..509f52f 100644 --- a/doordesk/app/src/routes.rs +++ b/doordesk/app/src/routes.rs @@ -1,3 +1,3 @@ pub mod home; -pub mod blog; -pub mod projects; +// pub mod blog; +// pub mod projects; diff --git a/doordesk/app/src/routes/home.rs b/doordesk/app/src/routes/home.rs index bffdf21..943ee49 100644 --- a/doordesk/app/src/routes/home.rs +++ b/doordesk/app/src/routes/home.rs @@ -1,7 +1,20 @@ use crate::components::article::*; +use crate::components::slingshot::*; use leptos::*; #[component] pub fn Home() -> impl IntoView { - view! { <Article/> } + let data_resource = create_local_resource(|| (), |_| async move { slingshot().await }); + + view! { + <Suspense fallback=move || { + view! { <p>"Loading..."</p> } + }> + {move || match data_resource.get() { + None => view! { <p>"Loading..."</p> }.into_view(), + Some(data) => view! { <Article data=data.unwrap()/> }.into_view(), + }} + + </Suspense> + } }