Skip to content

Commit

Permalink
Merge pull request #54 from Soongsil-Developers/Writecomment
Browse files Browse the repository at this point in the history
[#53] comment 부분 글 작성후,post 메소드를 이용하여 서버에 저장
  • Loading branch information
hoyyChoi authored Sep 13, 2022
2 parents ff36177 + 361f8d9 commit 7afffdf
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 55 deletions.
2 changes: 2 additions & 0 deletions src/atoms/auth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const slugState = atom({
default:''
})



// export const newArticleState = atom({
// key: 'src/atoms/auth.jsx-newArticleState',
// default:{
Expand Down
48 changes: 0 additions & 48 deletions src/component/Article/ArticleComment.jsx

This file was deleted.

1 change: 0 additions & 1 deletion src/component/Article/ArticleContainer.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import ArticleComment from './ArticleComment'
import ArticleContents from './ArticleContents'
import ShowComment from './ShowComment'
import WriteCommet from './WriteCommet'
Expand Down
25 changes: 21 additions & 4 deletions src/component/Article/WriteCommet.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
import React from 'react'
import { useState } from 'react'
import { useRecoilValue } from 'recoil'
import { slugState, userState } from '../../atoms/auth'
import { postComment } from '../../remote/index'

const WriteCommet = () => {


const [body,setTextComment] = useState('')
const slug = useRecoilValue(slugState)
const user = useRecoilValue(userState)

const submitComment = (e) =>{
e.preventDefault()

postComment(slug,{body},{user})
.then(res=>{
console.log(res)
}).catch(err=>{
console.log(err)
})
}

return (
<div className="row">
<div className="col-xs-12 col-md-8 offset-md-2">
<form className="card comment-form">
<form className="card comment-form" onSubmit={(e)=>submitComment(e)}>
<div className="card-block">
<textarea
className="form-control"
placeholder="Write a comment..."
rows="3"
rows="3" value={body} onChange={(e)=>setTextComment(e.currentTarget.value)}
></textarea>
</div>
<div className="card-footer">
<img
src="http://i.imgur.com/Qr71crq.jpg"
className="comment-author-img"
/>
<button className="btn btn-sm btn-primary">Post Comment</button>
<button className="btn btn-sm btn-primary" type='submit'>Post Comment</button>
</div>
</form>
</div>
Expand Down
31 changes: 29 additions & 2 deletions src/remote/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,33 @@ const getSlugArticle = (slug) => conduitAxios.get(`/articles/${slug}`)
]
}}
*/

const getComment = (slug) => conduitAxios.get(`/articles/${slug}/comments`)
export {postRegisterUser,postLoginUser,getLoginUser,putLoginUser,getProfile,getArticles,createArticle,getSlugArticle,getComment};

/**
@param {string} slug
@param {{
comment: {
body: string;
}
}} comment
@returns {{
comments: [
{
id: 0;
createdAt: 2022-09-13T09:11:17.036Z;
updatedAt: 2022-09-13T09:11:17.036Z;
body: string;
author: {
username: string;
bio: string;
image: string;
following: true
}
}
]
}}
*/

const postComment =(slug,comment,{user}) => conduitAxios.post(`/articles/${slug}/comments`,{comment},{headers:{authorization:`Bearer ${user.token}`}})

export {postRegisterUser,postLoginUser,getLoginUser,putLoginUser,getProfile,getArticles,createArticle,getSlugArticle,getComment,postComment};

0 comments on commit 7afffdf

Please sign in to comment.