-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2224cc
commit f38e842
Showing
15 changed files
with
199 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use crate::{helpers, store::Store, Api, CommentModel}; | ||
use gloo::console::log; | ||
use gloo_net::http::{Headers, Method}; | ||
use std::ops::Deref; | ||
use stylist::Style; | ||
use web_sys::{Event, HtmlInputElement, HtmlTextAreaElement, SubmitEvent}; | ||
use yew::prelude::*; | ||
use yewdux::prelude::*; | ||
|
||
const STYLE: &str = include_str!("styles/addComment.css"); | ||
|
||
#[derive(Properties, PartialEq)] | ||
pub struct Props { | ||
pub post_id: u32, | ||
} | ||
|
||
#[function_component(AddComment)] | ||
pub fn add_comment(props: &Props) -> Html { | ||
let style = Style::new(STYLE).unwrap(); | ||
let comment = use_state(CommentModel::default); | ||
let store = use_store_value::<Store>(); | ||
|
||
let onchange = { | ||
let comment = comment.clone(); | ||
Callback::from(move |e: Event| { | ||
let mut comment_clone = comment.deref().clone(); | ||
let input = e.target_dyn_into::<HtmlTextAreaElement>(); | ||
if let Some(value) = input { | ||
comment_clone.content = value.value(); | ||
comment.set(comment_clone); | ||
} | ||
}) | ||
}; | ||
|
||
let onsubmit = { | ||
let comment = comment.clone(); | ||
let post_id = props.post_id.clone(); | ||
Callback::from(move |e: SubmitEvent| { | ||
e.prevent_default(); | ||
let auth = format!("Bearer {}", store.token); | ||
let hdrs = Headers::new(); | ||
hdrs.append("Authorization", &auth); | ||
hdrs.append("content-type", "application/json"); | ||
|
||
let new_comment = CommentModel::new( | ||
0, | ||
post_id, | ||
comment.deref().content.clone(), | ||
store.username.clone(), | ||
); | ||
comment.set(new_comment.clone()); | ||
|
||
let body = Some(helpers::to_jsvalue(new_comment.clone())); | ||
log!("Response: ", body.clone().unwrap()); | ||
|
||
wasm_bindgen_futures::spawn_local(async move { | ||
let res = Api::AddComment.fetch(Some(hdrs), body, Method::POST).await; | ||
}); | ||
}) | ||
}; | ||
|
||
html! { | ||
<div class={style}> | ||
<div class="create-comment"> | ||
<form {onsubmit}> | ||
<textarea placeholder="your comments here..." | ||
type="text" | ||
required={true} | ||
value={comment.content.clone()} | ||
onchange={onchange}> | ||
</textarea> | ||
<button>{"Add Comment"}</button> | ||
</form> | ||
</div> | ||
</div> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod add_comment; | ||
pub mod comment; | ||
pub mod footer; | ||
pub mod items; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
devblog/devblog/client/src/components/styles/addComment.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.create-comment { | ||
margin-bottom: 20px; | ||
} | ||
|
||
.create-comment form { | ||
display: inline-flex; | ||
flex-direction: column; | ||
width: 100%; | ||
} | ||
|
||
.create-comment form input { | ||
width: 10em; | ||
margin: .5em 0 .5em 0; | ||
border: 0 0 1px 0; | ||
} | ||
|
||
.create-comment button { | ||
margin-top: .5em; | ||
width: fit-content; | ||
padding: 8px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
use crate::{helpers, Api, Store, User}; | ||
use std::rc::Rc; | ||
use stylist::Style; | ||
use yew::prelude::*; | ||
use yew_router::hooks::use_navigator; | ||
use yewdux::prelude::*; | ||
|
||
const STYLE: &str = include_str!("styles/signOut.css"); | ||
|
||
#[function_component(SignOut)] | ||
pub fn sign_out() -> Html { | ||
let style = Style::new(STYLE).unwrap(); | ||
let user = use_state(User::default); | ||
let nav = use_navigator().unwrap(); | ||
let (_, dispatch) = use_store::<Store>(); | ||
|
||
html! { | ||
<section> | ||
<h1>{"SignOut Page"}</h1> | ||
</section> | ||
<span class={style}> | ||
<form onsubmit={helpers::on_submit(&user, nav, Rc::new(Api::SignOut), dispatch)} class="logout-form"> | ||
<button class="logout">{"Logout"}</button> | ||
</form> | ||
</span> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.