Browse Source

Change comments component view

LenDoc 1 year ago
parent
commit
ad914752dc
4 changed files with 129 additions and 109 deletions
  1. 27 0
      package-lock.json
  2. 1 0
      package.json
  3. 1 1
      src/actions/index.js
  4. 100 108
      src/components/Comment.js

+ 27 - 0
package-lock.json

@@ -25,6 +25,7 @@
         "react-dom": "^17.0.2",
         "react-dropzone": "^12.0.2",
         "react-input-emoji": "^4.1.0",
+        "react-native-emoji-selector": "^0.2.0",
         "react-redux": "^7.2.6",
         "react-responsive-carousel": "^3.2.22",
         "react-router-dom": "^5.3.0",
@@ -6514,6 +6515,11 @@
         "url": "https://github.com/sindresorhus/emittery?sponsor=1"
       }
     },
+    "node_modules/emoji-datasource": {
+      "version": "6.1.1",
+      "resolved": "https://registry.npmjs.org/emoji-datasource/-/emoji-datasource-6.1.1.tgz",
+      "integrity": "sha512-fbS3QJpzGHhujvBULSKXcvsYmVg+1ldfI3VVXG3jnFuniZtkp7rz/OcTcQjbp3m43BYxmiJgKmaoOUPxXQupRQ=="
+    },
     "node_modules/emoji-mart": {
       "version": "3.0.1",
       "resolved": "https://registry.npmjs.org/emoji-mart/-/emoji-mart-3.0.1.tgz",
@@ -14151,6 +14157,14 @@
       "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
       "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w=="
     },
+    "node_modules/react-native-emoji-selector": {
+      "version": "0.2.0",
+      "resolved": "https://registry.npmjs.org/react-native-emoji-selector/-/react-native-emoji-selector-0.2.0.tgz",
+      "integrity": "sha512-+rPPWG5vl5AexdH8udEwtzdq9QUGD6kp+dQ8C/459d3ScM0S3UnT/qAvhmpsTgCbgjpdwiJIcrKNxKmGEDb15g==",
+      "dependencies": {
+        "emoji-datasource": "^6.0.0"
+      }
+    },
     "node_modules/react-redux": {
       "version": "7.2.6",
       "resolved": "https://registry.npmjs.org/react-redux/-/react-redux-7.2.6.tgz",
@@ -21946,6 +21960,11 @@
       "resolved": "https://registry.npmjs.org/emittery/-/emittery-0.8.1.tgz",
       "integrity": "sha512-uDfvUjVrfGJJhymx/kz6prltenw1u7WrCg1oa94zYY8xxVpLLUu045LAT0dhDZdXG58/EpPL/5kA180fQ/qudg=="
     },
+    "emoji-datasource": {
+      "version": "6.1.1",
+      "resolved": "https://registry.npmjs.org/emoji-datasource/-/emoji-datasource-6.1.1.tgz",
+      "integrity": "sha512-fbS3QJpzGHhujvBULSKXcvsYmVg+1ldfI3VVXG3jnFuniZtkp7rz/OcTcQjbp3m43BYxmiJgKmaoOUPxXQupRQ=="
+    },
     "emoji-mart": {
       "version": "3.0.1",
       "resolved": "https://registry.npmjs.org/emoji-mart/-/emoji-mart-3.0.1.tgz",
@@ -27327,6 +27346,14 @@
       "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
       "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w=="
     },
+    "react-native-emoji-selector": {
+      "version": "0.2.0",
+      "resolved": "https://registry.npmjs.org/react-native-emoji-selector/-/react-native-emoji-selector-0.2.0.tgz",
+      "integrity": "sha512-+rPPWG5vl5AexdH8udEwtzdq9QUGD6kp+dQ8C/459d3ScM0S3UnT/qAvhmpsTgCbgjpdwiJIcrKNxKmGEDb15g==",
+      "requires": {
+        "emoji-datasource": "^6.0.0"
+      }
+    },
     "react-redux": {
       "version": "7.2.6",
       "resolved": "https://registry.npmjs.org/react-redux/-/react-redux-7.2.6.tgz",

+ 1 - 0
package.json

@@ -21,6 +21,7 @@
     "react-dom": "^17.0.2",
     "react-dropzone": "^12.0.2",
     "react-input-emoji": "^4.1.0",
+    "react-native-emoji-selector": "^0.2.0",
     "react-redux": "^7.2.6",
     "react-responsive-carousel": "^3.2.22",
     "react-router-dom": "^5.3.0",

+ 1 - 1
src/actions/index.js

@@ -9,7 +9,7 @@ import { actionExploreTypeCount } from '../redux/reducers/explore/exploreReducer
 import { actionClearExplorePosts } from '../redux/reducers/explore/exploreReducer'
 import { actionExploreType } from '../redux/reducers/explore/exploreReducer'
 import { actionClearFeedPosts } from '../redux/reducers/feed/feedReducer'
-import {actionProfilePageDataType} from '../redux/reducers/profileData/profileReducer'
+import {actionProfilePageDataType} from '../redux/reducers/myData/myProfileReducer'
 import { history } from '../helpers'
 import{promiseWorker} from '../redux/saga'
 import { all, put, takeEvery, takeLatest, takeLeading, select,call } from 'redux-saga/effects'; //

+ 100 - 108
src/components/Comment.js

@@ -5,38 +5,52 @@ import {
 } from '../actions'
 import { Tooltip } from 'antd'
 import { connect } from 'react-redux'
+import { Link } from 'react-router-dom'
 
 import { Input, Button } from 'antd'
 import { SmileOutlined } from '@ant-design/icons'
 import moment from 'moment'
-import React, { useState } from 'react'
+import React, { useRef, useEffect, useState } from 'react'
 import 'emoji-mart/css/emoji-mart.css'
 import { Picker } from 'emoji-mart'
 import data from 'emoji-mart/data/google.json'
 import { NimblePicker, Emoji } from 'emoji-mart'
 import { LinkToUser } from './LinkToUser'
 import reactStringReplace from 'react-string-replace'
+import {  Comment,Avatar } from 'antd';
+import user from '../materials/user.png'
+// import EmojiSelector from 'react-native-emoji-selector'
+// render(<EmojiPicker onEmojiSelect={console.log} />, document.querySelector('#picker'))
+import { ConstructorModal } from '../helpers'
 
 export const AddComment = ({ addComment, postId }) => {
   const [text, setComment] = useState('')
   const [showEmojiPicker, setShowEmojiPicker] = useState(false)
-  const addEmoji = ({ colons }) => {
-    setComment((text + ' ' + colons).trim())
-  }
+  console.log('show stickers', showEmojiPicker)
+  const handleOK = () => 
+    setShowEmojiPicker(!showEmojiPicker)
+
+  const addEmoji = ({ native }) => 
+  setComment((text + ' ' + native).trim())
+
   return (
     <>
       {showEmojiPicker && (
+       
         <Picker
-          autoFocus={true}
           style={{
-            color: '#74d2e7',
+            color: '#108ee9',
             position: 'absolute',
             bottom: '160px',
             right: '30px',
           }}
-          onSelect={(emojiTag) => addEmoji(emojiTag)}
-          set="apple"
-        />
+          theme="light"
+          native={true}
+          showPreview={false}
+          showSkinTones={false}
+          onSelect={(native) =>
+            addEmoji(native)}
+          />
       )}
       <Input
         style={{
@@ -55,20 +69,32 @@ export const AddComment = ({ addComment, postId }) => {
           setComment(e.target.value)
         }}
       />
-      <SmileOutlined
+      {
+        !showEmojiPicker ?
+        <SmileOutlined
         className="smile-btn"
         style={{ fontSize: 'xx-large', marginRight: '30px' }}
-        onClick={() => {
-          setShowEmojiPicker(!showEmojiPicker)
-        }}
-      />
+      
+        onClick={handleOK}
+          />
+          :
+          <SmileOutlined
+          className="smile-btn"
+          style={{ color:'#108ee9',fontSize: 'xx-large', marginRight: '30px' }}
+        
+          onClick={handleOK}
+        />
+    }
+     
       <Button
         size="large"
         disabled={text.length < 1}
         type="primary"
-        onClick={(e) =>
-          addComment(postId, text) && setComment((e.target.value = ''))
-        }
+        onClick={(e) => { 
+          addComment(postId, text)
+            && setComment(e.target.value = '') &&
+            setShowEmojiPicker(false)
+        }}
       >
         {' '}
         Publish{' '}
@@ -92,21 +118,6 @@ export const SpoilerButton = ({ text, close, children, style }) => {
     </>
   )
 }
-const CommentAuthor = ({ owner:{_id, login, avatar} }) => (
-  <>
-    <div
-      style={{
-        display: 'flex',
-        flexDirection: 'row',
-        padding: '5px',
-        margin: '5px',
-      }}
-    >
-      <LinkToUser _id={_id} login={login} avatar={avatar} size={'10px'} sizePadding={'0px'} />
-    </div>
-  </>
-)
-
 const CommentForReply = ({ addCommentReply, commentId, postId }) => {
   const [comment, setComment] = useState('')
   return (
@@ -140,35 +151,10 @@ const CommentForReply = ({ addCommentReply, commentId, postId }) => {
   )
 }
 
-const CommentText = ({ text, close }) => {
-  // const [edit, setEdited] = useState(close)
-  return (
-    <div
-      style={{
-        width: '90%',
-        margin: '20px',
-        paddingLeft: '5px',
-        display: 'flex',
-        alignItems: 'left',
-        justifyContent: 'left',
-        transition: '.3s',
-        boxShadow: '0 5px 10px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22)',
-      }}
-    >
-      {/* <EditOutlined style={{float:'right',  fontSize: 'x-large' }}/> */}
-      <h3 style={{ display: 'block' }}>
-        {' '}
-        {reactStringReplace(text, /:(.+?):/g, (match, i) => (
-          <Emoji emoji={match} set="apple" size={20} />
-        ))}
-      </h3>
-    </div>
-  )
-}
 const CommentData = ({ createdAt }) => {
   return (
     <Tooltip
-      color={'#87d068'}
+      color={'#108ee9'}
       style={{ paddingLeft: '10px' }}
       title={moment(new Date(+createdAt)).format('lll')}
     >
@@ -179,65 +165,72 @@ const CommentData = ({ createdAt }) => {
   )
 }
 
-export const Comments = ({
+export const Comments =  ({
   comments,
   postId,
+  commentsFind,
   addCommentReply,
-  commentId,
   children,
   close,
   findSubComment,
+  onGetLikes,
+  onGetType
 }) => {
   const [opened, setOpened] = useState(close)
-
   return (
     <>
-      {comments
-        ? comments.map((comment) => (
-            <>
-              <div
-                style={{
-                  display: 'flex',
-                  flexDirection: 'row',
-                  width: '100%',
-                  padding: '15px',
-                }}
-              >
-                <CommentAuthor owner={comment.owner} />
-                <CommentText text={comment.text} />
-              </div>
-              <CommentData createdAt={comment.createdAt} />
-              <div style={{ display: 'flex', flexDirection: 'row' }}>
-                <div style={{ display: 'flex', flexDirection: 'column' }}>
-                  <SpoilerButton text={'Reply to'}>
-                    <CommentForReply
-                      addCommentReply={addCommentReply}
-                      commentId={comment._id}
-                      postId={postId}
-                    />
-                  </SpoilerButton>
-                </div>
-                {comment?.answers && comment?.answers?.length ? (
-                  <div style={{ marginLeft: '10px', display: 'inline-block' }}>
-                    <SpoilerButton
-                      // style={{ position: 'fixed' }}
-                      text={'More comments'}
-                      onClick={() => findSubComment(commentId)}
-                    >
-                      <Comments
-                        comments={comment.answers}
-                        addCommentReply={addCommentReply}
-                        commentId={comment._id}
-                      ></Comments>
-                    </SpoilerButton>
-                  </div>
-                ) : null}
-              </div>
-            </>
-          ))
-        : null}
-    </>
-  )
+      {comments 
+        
+        ? 
+        comments?.map((comment) => (
+          <Comment
+      
+            author={ <Link
+              to={`/profile/${comment?.owner?._id}`}
+            >
+                {comment?.owner?.login || 'Anon'}
+             
+            </Link>}
+        
+            avatar= 
+            {comment.owner?.avatar ? (
+              <Link
+              to={`/profile/${comment?.owner?._id}`}
+            >
+                <Avatar
+                  size={30}
+                  src={'/' + comment.owner?.avatar?.url}
+                style={{ marginLeft: '15px' }}
+                alt={comment.owner?.login || 'Anon'}
+                />
+                </Link>
+            ) : (
+              <Link
+              to={`/profile/${comment?.owner?._id}`}
+            >
+                <Avatar size={30}
+                  src={user}
+                  style={{ marginLeft: '15px' }}
+                  alt={comment.owner?.login || 'Anon'}
+                  />
+              </Link>
+              )}
+  
+            content=
+            {
+              <p>
+                {comment?.text}
+                </p>
+            }
+           
+            datetime={
+              <CommentData createdAt={comment?.createdAt} />
+            }
+          />
+
+            
+     )) : <h3> No comments </h3>}
+    </>)
 }
 
 export const CComments = connect(
@@ -247,7 +240,6 @@ export const CComments = connect(
     addSubComment: state.promise?.addSubComment,
   }),
   {
-    // addComment: actionAddFullComment,
     addCommentReply: actionAddSubFullComment,
     findSubComment: actionFindSubComment,
   },