Skip to content

Commit

Permalink
chore: create the post with title and content
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Liendo committed Sep 24, 2024
1 parent 11f3761 commit 21f3383
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions crates/web/src/components/publisher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,31 @@ use crate::components::text_field::TextField;

#[component]
pub fn Publisher() -> impl IntoView {
let text_title = create_rw_signal(String::default());
let text_content = create_rw_signal(String::default());
let send_post_action = create_action(|content: &String| {
let content = content.to_owned();

let send_post_action = create_action(|data: &(String, String)| {
let (title, content) = data;

let title = title.to_owned();

if title.is_empty() {
()
}

let content = if content.trim().is_empty() {
None
} else {
Some(content.to_owned())
};

async move {
Client::new("http://127.0.0.1:8080")
.unwrap()
.post
.post_create(PostCreateInput {
title: content,
content: None,
title: title,
content: content,
parent_id: None,
})
.await
Expand All @@ -29,14 +43,18 @@ pub fn Publisher() -> impl IntoView {
<img src="https://images.unsplash.com/photo-1534528741775-53994a69daeb?q=80&w=3164&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt="A beautiful image" />
</figure>
</div>
<div id="publisher-form" class="flex flex-col items-start justify-start w-full">
<div id="publisher-form" class="flex flex-col items-start justify-start w-full space-y-2">
<form class="flex flex-col justify-start w-full" on:submit=move |ev| {
ev.prevent_default();
let content = text_content.get();
send_post_action.dispatch(content);
let title = text_title.get();
send_post_action.dispatch((title, content));
}>
<div class="w-full h-12">
<TextField class="w-full" name="content" value=text_content />
<TextField class="w-full" name="title" value=text_title placeholder="Title" />
</div>
<div class="w-full h-12">
<TextField class="w-full" name="content" value=text_content placeholder="Content" />
</div>
<div class="flex justify-end items-center">
<button type="submit">Post</button>
Expand Down

0 comments on commit 21f3383

Please sign in to comment.