Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. import React, { Fragment, useEffect, useState } from 'react';
  2. import { TextField, Button } from '@material-ui/core';
  3. import {makeStyles} from '@material-ui/core/styles';
  4. import {useDispatch, useSelector} from 'react-redux';
  5.  
  6. const cssStyles = makeStyles((theme) => ({
  7. root:{
  8. marginTop:"20px",
  9. textAlign:"right",
  10. '& button' :{
  11. marginTop:"20px"
  12. }
  13. }
  14. }))
  15.  
  16. function ReplyComponent(props) { //Accept thread ID or whole comment object?
  17. const commentsData = useSelector(currentState => currentState.commentsReducer);
  18.  
  19. const [message,setMessage] = useState({userMessage:""});
  20. const dispatch = useDispatch();
  21. const useCss = cssStyles();
  22.  
  23. const handleMessageEvent = (event)=>{
  24. const {name, value} = event.target;
  25. setMessage((currentState)=>({
  26. ...currentState,
  27. [name]: value
  28. }));
  29. }
  30.  
  31. function addCommentDB(){
  32. let temp = commentsData.data.find((value)=> value._id == props.root);
  33. console.log(JSON.stringify(temp));
  34. debugger;
  35. }
  36. const submitReplyEvent = ()=>{
  37. const reduxPayload = {
  38. comment: message.userMessage,
  39. author: "replying User",
  40. parent: props.id
  41. }
  42. dispatch({
  43. type: "ADD_COMMENT",
  44. payload: reduxPayload
  45. });
  46. debugger;
  47.  
  48. addCommentDB();
  49. }
  50.  
  51. return (
  52. <Fragment>
  53. <div className={useCss.root}>
  54.  
  55. <TextField onChange={handleMessageEvent} id="message-input" rows="8" multiline={true} aria-describedby="message-helper-text" fullWidth variant="outlined" label="Message" name="userMessage" />
  56. <Button onClick={submitReplyEvent}>Send reply</Button>
  57. <pre>{JSON.stringify(commentsData, null, 2) }</pre>
  58.  
  59. </div>
  60. </Fragment>
  61. )
  62. }
  63.  
  64. export default ReplyComponent;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement