Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1657 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1650 stevensc 1
import React, { useState } from 'react'
2
import { Link } from 'react-router-dom'
3
import { useSelector } from 'react-redux'
4
 
5
import { StyledCommentList, StyledCommentTemplate } from './comments-ui'
6
import Options from '@app/components/UI/Option'
7
import ConfirmModal from '@app/components/modals/ConfirmModal'
8
 
9
export default function CommentsList({ comments, onDelete }) {
10
  return (
11
    <>
12
      <StyledCommentList>
13
        {comments.map((comment) => {
14
          return (
15
            <li key={comment.unique}>
16
              <CommentsList.Item comment={comment} onDelete={onDelete} />
17
            </li>
18
          )
19
        })}
20
      </StyledCommentList>
21
    </>
22
  )
23
}
24
 
25
function Comment({ onDelete, comment }) {
26
  const [showConfirmModal, setShowConfirmModal] = useState(false)
27
  const labels = useSelector(({ intl }) => intl.labels)
28
 
29
  const {
30
    unique,
31
    user_url,
32
    user_name,
33
    time_elapsed,
34
    comment: content,
35
    link_delete
36
  } = comment
37
 
38
  const toggleModal = () => {
39
    setShowConfirmModal(!showConfirmModal)
40
  }
41
 
42
  return (
43
    <>
44
      <StyledCommentTemplate>
45
        <div className='content'>
46
          <div className='info'>
47
            <Link to={user_url}>
48
              <h3>{user_name}</h3>
49
            </Link>
50
            <span>{time_elapsed}</span>
51
          </div>
52
          {link_delete && (
53
            <Options
54
              options={[
55
                {
56
                  label: labels.delete,
57
                  action: toggleModal
58
                }
59
              ]}
60
              right='0.5rem'
61
              top='1.5rem'
62
            />
63
          )}
64
          <p>{content}</p>
65
        </div>
66
      </StyledCommentTemplate>
67
      <ConfirmModal
68
        show={showConfirmModal}
69
        onClose={toggleModal}
70
        onAccept={() => onDelete(unique, link_delete)}
71
        acceptLabel={labels.accept}
72
      />
73
    </>
74
  )
75
}
76
 
77
CommentsList.Item = Comment