diff --git a/Cargo.lock b/Cargo.lock index c779b60..ad0faa5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,6 +56,21 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.79" @@ -364,6 +379,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.0", +] + [[package]] name = "ciborium" version = "0.2.2" @@ -456,6 +485,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + [[package]] name = "cpufeatures" version = "0.2.12" @@ -1190,6 +1225,29 @@ dependencies = [ "tokio", ] +[[package]] +name = "iana-time-zone" +version = "0.1.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -2415,6 +2473,7 @@ version = "0.1.0" dependencies = [ "app", "axum", + "chrono", "femark", "leptos", "leptos_axum", @@ -3528,6 +3587,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/app/src/components/api.rs b/app/src/components/api.rs index 0468472..6419da7 100644 --- a/app/src/components/api.rs +++ b/app/src/components/api.rs @@ -1,9 +1,27 @@ -use crate::components::ui::articles::*; use leptos::*; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +pub enum ArticleType { + All, + Blog, + Game, + Project, +} + +#[derive(Clone, Serialize, Deserialize)] +#[cfg_attr(feature = "ssr", derive(sqlx::FromRow))] +pub struct Article { + pub content_type: String, + pub title: String, + pub date: String, // make datetime? + pub content: String, +} #[server] pub async fn get_articles(article_type: ArticleType) -> Result, ServerFnError> { use sqlx::*; + let query = match article_type { ArticleType::All => "select * from blog order by date", ArticleType::Blog => "select * from blog where content_type like 'blog'", @@ -13,9 +31,7 @@ pub async fn get_articles(article_type: ArticleType) -> Result, Ser let pool: SqlitePool = use_context::().expect("couldn't get pool context"); - let result = sqlx::query_as::<_, Article>(query) - .fetch_all(&pool) - .await?; + let articles: Vec
= sqlx::query_as::<_, Article>(query).fetch_all(&pool).await?; - Ok(result) + Ok(articles) } diff --git a/app/src/components/ui/articles.rs b/app/src/components/ui/articles.rs index 1bdcb47..860cb99 100644 --- a/app/src/components/ui/articles.rs +++ b/app/src/components/ui/articles.rs @@ -1,24 +1,6 @@ use crate::components::api::*; use crate::components::ui::containers::*; use leptos::*; -use serde::*; - -#[derive(Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "ssr", derive(sqlx::FromRow))] -pub struct Article { - pub content_type: String, - pub title: String, - pub date: String, // make datetime? - pub content: String, -} - -#[derive(Clone, Copy, Debug, Serialize, Deserialize)] -pub enum ArticleType { - All, - Blog, - Game, - Project, -} #[component] pub fn Article(data: Article) -> impl IntoView { diff --git a/app/src/components/ui/cards.rs b/app/src/components/ui/cards.rs index 8da563e..b46f2db 100644 --- a/app/src/components/ui/cards.rs +++ b/app/src/components/ui/cards.rs @@ -1,4 +1,4 @@ -use crate::components::ui::articles::*; +use crate::components::api::*; use leptos::*; use crate::components::api::get_articles; @@ -7,17 +7,15 @@ use crate::components::api::get_articles; pub fn Card(data: Article) -> impl IntoView { view! {
-

- {&data.title} -

+

{&data.title}


{&data.date} -

- "[image]" -

+

"[image]"

- Read more... + + Read more... +

} @@ -33,13 +31,9 @@ pub fn CardBuilder(article_type: ArticleType) -> impl IntoView { let cards_view = move || { data_resource.and_then(|data| { data.iter() - .map(|article| view! { }) + .map(|article| view! { }) .collect_view() }) }; - view! { -
- {cards_view} -
- } + view! {
{cards_view}
} } diff --git a/app/src/routes/blog.rs b/app/src/routes/blog.rs index 4ca740c..cd35cfb 100644 --- a/app/src/routes/blog.rs +++ b/app/src/routes/blog.rs @@ -1,10 +1,10 @@ -use crate::components::ui::articles::*; +use crate::components::api::ArticleType; +use crate::components::ui::articles::ArticleBuilder; use crate::error_template::*; use leptos::*; #[island] pub fn Blog() -> impl IntoView { - view! { "Loading..."

} @@ -12,7 +12,7 @@ pub fn Blog() -> impl IntoView { } }> - +
} diff --git a/app/src/routes/games.rs b/app/src/routes/games.rs index 38e8ca3..be8b0b5 100644 --- a/app/src/routes/games.rs +++ b/app/src/routes/games.rs @@ -1,4 +1,4 @@ -use crate::components::ui::articles::*; +use crate::components::api::ArticleType; use crate::components::ui::cards::*; use crate::error_template::*; use leptos::*; @@ -13,7 +13,7 @@ pub fn Games() -> impl IntoView { } }> - + } diff --git a/app/src/routes/home.rs b/app/src/routes/home.rs index 31f0b42..3b1ea7f 100644 --- a/app/src/routes/home.rs +++ b/app/src/routes/home.rs @@ -1,4 +1,5 @@ -use crate::components::ui::articles::*; +use crate::components::api::ArticleType; +use crate::components::ui::articles::ArticleBuilder; use crate::components::ui::cards::*; use crate::error_template::*; use leptos::*; @@ -13,8 +14,8 @@ pub fn Home() -> impl IntoView { } }> - - + + } diff --git a/app/src/routes/projects.rs b/app/src/routes/projects.rs index 9d5604a..9a1fef3 100644 --- a/app/src/routes/projects.rs +++ b/app/src/routes/projects.rs @@ -1,10 +1,10 @@ -use crate::components::ui::articles::*; +use crate::components::api::ArticleType; +use crate::components::ui::articles::ArticleBuilder; use crate::error_template::*; use leptos::*; #[island] pub fn Projects() -> impl IntoView { - view! { "Loading..."

} @@ -12,7 +12,7 @@ pub fn Projects() -> impl IntoView { } }> - +
} diff --git a/frontend/src/lib.rs b/frontend/src/lib.rs index 566c7f6..ac4eca3 100644 --- a/frontend/src/lib.rs +++ b/frontend/src/lib.rs @@ -1,4 +1,4 @@ -use app::*; // don't remove this when using experimental-islands +use app::*; // https://github.com/leptos-rs/leptos/issues/2083 use leptos::*; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/server/Cargo.toml b/server/Cargo.toml index 92b9445..b388e95 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -16,3 +16,4 @@ sqlx = { version = "0.7", features = ["runtime-tokio-rustls", "sqlite"] } toml = "0.8.8" femark = "0.1.5" serde = "1.0.196" +chrono = "0.4.33" diff --git a/server/src/db.rs b/server/src/db.rs index f718072..5ab7789 100644 --- a/server/src/db.rs +++ b/server/src/db.rs @@ -1,13 +1,24 @@ +use app::components::api::Article; use leptos::*; use serde::*; use sqlx::*; -use app::components::ui::articles::Article; - pub async fn db_build(pool: SqlitePool) -> Result<(), ServerFnError> { - let _ = query("CREATE TABLE blog (content_type TEXT, title TEXT, date TEXT, content TEXT)") - .execute(&pool) - .await?; + let _res = query( + " + CREATE TABLE + blog ( + content_type TEXT, + title TEXT, + date TEXT, + content TEXT + ) + ", + ) + .execute(&pool) + .await?; + + // println!("{:?}", _res); #[derive(Deserialize)] struct ArticleFrontmatter { @@ -40,7 +51,7 @@ pub async fn db_build(pool: SqlitePool) -> Result<(), ServerFnError> { content, }; - let _ = sqlx::query( + let _res = sqlx::query( " INSERT INTO blog (content_type, title, date, content) @@ -54,6 +65,8 @@ pub async fn db_build(pool: SqlitePool) -> Result<(), ServerFnError> { .bind(article.content) .execute(&pool) .await?; + + // println!("{:?}", _res); } } }