Skip to content

Commit

Permalink
chore: handle creation errors in publisher component and cleanly disp…
Browse files Browse the repository at this point in the history
…lay error messages on submission
  • Loading branch information
Michael-Liendo committed Sep 27, 2024
1 parent 81621c1 commit 015a71b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/web/src/components/publisher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn Publisher() -> impl IntoView {
Some(content.trim().to_owned())
};

Client::new("http://127.0.0.1:8080")
let result = Client::new("http://127.0.0.1:8080")
.unwrap()
.post
.post_create(PostCreateInput {
Expand All @@ -39,6 +39,10 @@ pub fn Publisher() -> impl IntoView {
parent_id: None,
})
.await;

if let Err(err) = result {
creation_error.set(Some(err.to_string()));
}
}
});

Expand All @@ -58,16 +62,17 @@ pub fn Publisher() -> impl IntoView {
}>
<div class="w-full h-12">
<TextField class="w-full" name="title" value=text_title placeholder="Title" required=true />
<Show when=move || creation_error.get().is_some() fallback=move || ()>
<p class="text-red-500 mb-3">{creation_error.get().unwrap()}</p>
</Show>

</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>
</div>
<Show when=move || creation_error.get().is_some() fallback=move || ()>
<p class="text-red-500 mb-3">{creation_error.get().unwrap()}</p>
</Show>
</form>
</div>
</div>
Expand Down

0 comments on commit 015a71b

Please sign in to comment.