cleanup
This commit is contained in:
parent
f37ebd0445
commit
bfff54c2b2
11 changed files with 130 additions and 55 deletions
68
Cargo.lock
generated
68
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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<Vec<Article>, 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<Vec<Article>, Ser
|
|||
|
||||
let pool: SqlitePool = use_context::<SqlitePool>().expect("couldn't get pool context");
|
||||
|
||||
let result = sqlx::query_as::<_, Article>(query)
|
||||
.fetch_all(&pool)
|
||||
.await?;
|
||||
let articles: Vec<Article> = sqlx::query_as::<_, Article>(query).fetch_all(&pool).await?;
|
||||
|
||||
Ok(result)
|
||||
Ok(articles)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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! {
|
||||
<div class="p-7 my-5 mx-2 w-80 rounded-lg shadow-inner min-w-3/12 max-w-3/12 bg-zinc-900 shadow-zinc-950">
|
||||
<h1 class="text-2xl font-light text-orange-600 max-6-xs">
|
||||
{&data.title}
|
||||
</h1>
|
||||
<h1 class="text-2xl font-light text-orange-600 max-6-xs">{&data.title}</h1>
|
||||
<hr class="opacity-50"/>
|
||||
<span class="pt-0 pb-3.5 text-xs opacity-50 m-t">{&data.date}</span>
|
||||
<p class="text-center">
|
||||
"[image]"
|
||||
</p>
|
||||
<p class="text-center">"[image]"</p>
|
||||
<div inner_html=&data.content></div>
|
||||
<p class="text-right">
|
||||
<a class="text-orange-300 hover:underline" href="https://lickmysa.cc" >Read more...</a>
|
||||
<a class="text-orange-300 hover:underline" href="https://lickmysa.cc">
|
||||
Read more...
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
|
@ -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! {<Card data=article.clone()/> })
|
||||
.map(|article| view! { <Card data=article.clone()/> })
|
||||
.collect_view()
|
||||
})
|
||||
};
|
||||
view! {
|
||||
<div class="flex flex-wrap place-content-evenly mx-auto max-w-8/12">
|
||||
{cards_view}
|
||||
</div>
|
||||
}
|
||||
view! { <div class="flex flex-wrap place-content-evenly mx-auto max-w-11/12">{cards_view}</div> }
|
||||
}
|
||||
|
|
|
@ -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! {
|
||||
<Suspense fallback=move || {
|
||||
view! { <p>"Loading..."</p> }
|
||||
|
@ -12,7 +12,7 @@ pub fn Blog() -> impl IntoView {
|
|||
<ErrorBoundary fallback=|errors| {
|
||||
view! { <ErrorTemplate errors=errors/> }
|
||||
}>
|
||||
<ArticleBuilder article_type={ArticleType::Blog} />
|
||||
<ArticleBuilder article_type=ArticleType::Blog/>
|
||||
</ErrorBoundary>
|
||||
</Suspense>
|
||||
}
|
||||
|
|
|
@ -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 {
|
|||
<ErrorBoundary fallback=|errors| {
|
||||
view! { <ErrorTemplate errors=errors/> }
|
||||
}>
|
||||
<CardBuilder article_type={ArticleType::Game} />
|
||||
<CardBuilder article_type=ArticleType::Game/>
|
||||
</ErrorBoundary>
|
||||
</Suspense>
|
||||
}
|
||||
|
|
|
@ -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 {
|
|||
<ErrorBoundary fallback=|errors| {
|
||||
view! { <ErrorTemplate errors=errors/> }
|
||||
}>
|
||||
<CardBuilder article_type={ArticleType::Game} />
|
||||
<ArticleBuilder article_type={ArticleType::All} />
|
||||
<CardBuilder article_type=ArticleType::Game/>
|
||||
<ArticleBuilder article_type=ArticleType::All/>
|
||||
</ErrorBoundary>
|
||||
</Suspense>
|
||||
}
|
||||
|
|
|
@ -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! {
|
||||
<Suspense fallback=move || {
|
||||
view! { <p>"Loading..."</p> }
|
||||
|
@ -12,7 +12,7 @@ pub fn Projects() -> impl IntoView {
|
|||
<ErrorBoundary fallback=|errors| {
|
||||
view! { <ErrorTemplate errors=errors/> }
|
||||
}>
|
||||
<ArticleBuilder article_type={ArticleType::Project} />
|
||||
<ArticleBuilder article_type=ArticleType::Project/>
|
||||
</ErrorBoundary>
|
||||
</Suspense>
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue