Add post page
This commit is contained in:
parent
dcb5026a66
commit
c30d1d5531
2 changed files with 18 additions and 22 deletions
|
@ -1,11 +1,10 @@
|
|||
use leptos::*;
|
||||
use leptos_router::*;
|
||||
use crate::app::models::Post;
|
||||
|
||||
#[server]
|
||||
pub async fn get_posts(
|
||||
folder: String
|
||||
) -> Result<Vec<Post>, ServerFnError> {
|
||||
let posts = Post::get_all(&folder)
|
||||
pub async fn get_posts() -> Result<Vec<Post>, ServerFnError> {
|
||||
let posts = Post::get_all("posts")
|
||||
.map_err(|e| ServerFnError::ServerError(e.to_string()))?;
|
||||
|
||||
Ok(posts)
|
||||
|
@ -13,10 +12,9 @@ pub async fn get_posts(
|
|||
|
||||
#[server]
|
||||
pub async fn get_post(
|
||||
folder: String,
|
||||
slug: String
|
||||
) -> Result<Post, ServerFnError> {
|
||||
let posts = Post::get_all(&folder)
|
||||
let posts = Post::get_all("posts")
|
||||
.map_err(|e| ServerFnError::ServerError(e.to_string()))?;
|
||||
|
||||
let post = posts.into_iter().find(|post| post.slug == slug)
|
||||
|
@ -26,10 +24,8 @@ pub async fn get_post(
|
|||
}
|
||||
|
||||
#[component]
|
||||
pub fn PostList(
|
||||
folder: String
|
||||
) -> impl IntoView {
|
||||
let posts = create_resource(|| (), |_| get_posts("posts".to_string()));
|
||||
pub fn PostList() -> impl IntoView {
|
||||
let posts = create_resource(|| (), |_| get_posts());
|
||||
|
||||
let posts_view = move || {
|
||||
posts.and_then(|posts| {
|
||||
|
@ -55,10 +51,11 @@ pub fn PostList(
|
|||
}
|
||||
|
||||
#[component]
|
||||
pub fn PostElement(
|
||||
folder: String,
|
||||
) -> impl IntoView {
|
||||
let post = create_resource(|| (), |_| get_post("posts".to_string(), "2023-11-26_testing_layout".to_string()));
|
||||
pub fn PostElement() -> impl IntoView {
|
||||
let params = use_params_map();
|
||||
let slug = move || params.with(|params| params.get("slug").cloned().unwrap_or_default());
|
||||
|
||||
let post = create_resource(|| (), move |_| get_post(slug()));
|
||||
|
||||
let post_view = move || {
|
||||
post.and_then(|post| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue