Skip to content

Commit

Permalink
write api for message
Browse files Browse the repository at this point in the history
  • Loading branch information
ducga1998 committed Nov 26, 2018
1 parent 1dcf748 commit 84e60da
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
27 changes: 27 additions & 0 deletions src/API/messageAPI.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import gql from "graphql-tag";
import { client } from "./client";
export function getMessageByIdRoom(idroom) {
return new Promise(resolve => {
const data = client.query({
query: gql`
query {
getAllMessageByIdRoom( id : "${idroom}"){
idRoom
idUser
content
userMessage {
name
avatarLink
idUser
}
roomMessage {
idUser
idRoom
}
}
}
`
})
resolve(data)
})
}
21 changes: 3 additions & 18 deletions src/Component/Article/ReadArticle/writeComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ export default class WriteComment extends React.Component<IWriteComment> {
title.subscribe('editableInput', (event, editable) => {
const content = event.srcElement.innerHTML
this.setState({ content })

});
}

handleAddComment = async () => {

// console.log(this.state.content)
const { imgSrc, idArticle } = this.props
const { idArticle } = this.props
const { content } = this.state
if (content === ' <p><br></p>' || content === '') {
toast.error('Comment not empty !!!. Please write something ')
Expand All @@ -50,26 +47,14 @@ export default class WriteComment extends React.Component<IWriteComment> {
idArticle,

}
avatarLink = (avatarLink ? avatarLink : IMAGE_SOURCE_DEFAULT)
// request to backend and add comment data to commentContainer
// let { data: {
// addCommentIntoArticle
// } }: any = await addComment(input)
// let newComment = addCommentIntoArticle
await commentAllContainer.addCommentInArticle(input)
// newComment.userComment = {
// avatarLink,
// name
// }

// console.log('newComment', newComment)
// await this.props.onChange(newComment)
await commentAllContainer.addCommentInArticle(input) // function handle request to backend and add data to commentAllContainer
await this.setState({ content: '' })
this.refComment.current.innerHTML = '<p><br /></p>'
}
render() {
const { name, avatarLink } = userContainer.state
console.log('avatarLink', avatarLink)
// here view user write comment
return <>< $Comment>
<$Img src={avatarLink ? avatarLink : IMAGE_SOURCE_DEFAULT} /> <b>{name}</b>
<$Content ref={this.refComment} />
Expand Down
6 changes: 5 additions & 1 deletion src/Component/RoomChat/DetailRoomChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ListRoom from './listRoom';
import UIButton from '../../UI/UIButton';
import io from 'socket.io-client';
import { toast } from 'react-toastify';
import { getMessageByIdRoom } from '../../API/messageAPI';

interface IRoomChat {
match: any
Expand All @@ -21,12 +22,15 @@ export default class RoomChat extends React.Component<IRoomChat> {
value: ''
}
refWrappInput: any = React.createRef()
componentDidMount() {
async componentDidMount() {

const { match: { params: { id } } } = this.props
const input = {
idUser: userContainer.state.dataUser.idUser,
idRoom: id
}
const dataMessage = await getMessageByIdRoom(id)
console.log('dataMessage', dataMessage)
chatsockets.on('connect', function () {

})
Expand Down

0 comments on commit 84e60da

Please sign in to comment.