Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
The-DevBlog committed Mar 6, 2024
1 parent 0851af3 commit f96f303
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions devblog/devblog/client/src/components/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ pub fn comment(props: &Props) -> Html {
// edit comment
if !*is_editing && props.comment.username == store.username {
<EditComment id={props.comment.id}
content={props.comment.content.clone()}
content={content.deref().clone()}
is_editing={*is_editing}
on_is_editing={on_is_editing.clone()}
on_edit_save={on_edit_save.clone()}/>
}

// delete comment
if props.comment.username == store.username || store.admin{
if props.comment.username == store.username || store.admin {
<DeleteComment id={props.comment.id.clone()} on_comment_delete={&props.on_comment_delete}/>
}

Expand Down
4 changes: 2 additions & 2 deletions devblog/devblog/client/src/components/comment_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Props {
#[function_component(EditComment)]
pub fn edit_comment(props: &Props) -> Html {
let style = Style::new(STYLE).unwrap();
let content = use_state(|| String::default());
let content = use_state(|| props.content.clone());
let store = use_store_value::<Store>();

let onchange = {
Expand Down Expand Up @@ -83,7 +83,7 @@ pub fn edit_comment(props: &Props) -> Html {

if props.is_editing {
<div class="edit-comment">
<textarea value={props.content.clone()} {onchange}></textarea>
<textarea value={content.deref().clone()} {onchange}></textarea>

<div>
<button onclick={save}>{"Save"}</button>
Expand Down
1 change: 0 additions & 1 deletion devblog/devblog/client/src/components/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub fn post(props: &Props) -> Html {
Callback::from(move |id| {
let mut new_comments = comments_clone.deref().clone();
if let Some(idx) = new_comments.iter().position(|c| c.id == id) {
// log!("IDXXXX: ", idx);
new_comments.remove(idx);
comments_clone.set(new_comments);
}
Expand Down
5 changes: 2 additions & 3 deletions devblog/devblog/client/src/components/post_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,20 @@ pub fn edit_post(props: &Props) -> Html {
let description = description.deref().clone();
let token = store.token.clone();
let is_editing = is_editing.clone();
let on_post_edit = props.on_post_edit.clone();
let id = props.id.clone();
Callback::from(move |e: SubmitEvent| {
e.prevent_default();
let description = description.clone();
let body = Some(helpers::to_jsvalue(description.deref()));
let hdrs = helpers::create_auth_header(&token);
hdrs.append("content-type", "application/json");
let on_post_edit = on_post_edit.clone();
let is_editing = is_editing.clone();

wasm_bindgen_futures::spawn_local(async move {
let response = Api::EditPost(id).fetch(Some(hdrs), body, Method::PUT).await;

if let Some(res) = response {
if res.status() == 200 {
on_post_edit.emit(description.clone());
is_editing.set(false);
}
}
Expand All @@ -54,11 +51,13 @@ pub fn edit_post(props: &Props) -> Html {
};

let on_description_change = {
let on_post_edit = props.on_post_edit.clone();
let description = description.clone();
Callback::from(move |e: InputEvent| {
let input = e.target_dyn_into::<HtmlTextAreaElement>();
if let Some(value) = input {
description.set(value.value());
on_post_edit.emit(value.value());
}
})
};
Expand Down
3 changes: 0 additions & 3 deletions devblog/devblog/client/src/pages/test.md

This file was deleted.

0 comments on commit f96f303

Please sign in to comment.