Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 7386 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 7386 Rev 7428
Línea 1... Línea 1...
1
import React, { useState } from 'react'
1
import React, { useState } from 'react'
2
import CommentTemplate from './CommentTemplate'
2
import CommentTemplate from './CommentTemplate'
Línea 3... Línea 3...
3
 
3
 
Línea 4... Línea 4...
4
const CommentSection = ({ owner_url, owner_image, comments, comments_link_add }) => {
4
const CommentSection = ({ owner_url, owner_image, comments, comments_link_add }) => {
-
 
5
 
-
 
6
    const [commentState, setCommentState] = useState(comments)
-
 
7
 
-
 
8
    const handleSubmit = (e) => {
-
 
9
        e.preventDefault()
-
 
10
 
-
 
11
        axios.post(comments_link_add)
-
 
12
            .then(({ data }) => {
-
 
13
                if (!data.success) {
-
 
14
                    return console.log("Error de envio")
-
 
15
                }
-
 
16
 
-
 
17
                setCommentState([...commentState, data.data])
-
 
18
            })
Línea 5... Línea 19...
5
 
19
            .catch((err) => console.log(err))
6
    const [commentState, setCommentState] = useState()
20
    }
7
 
21
 
8
    return (
22
    return (
Línea 15... Línea 29...
15
                            src={owner_image}
29
                            src={owner_image}
16
                            alt="user avatar image"
30
                            alt="user avatar image"
17
                        />
31
                        />
18
                    </a>
32
                    </a>
19
                </div>
33
                </div>
20
                <form className="w-100">
34
                <form className="w-100" onSubmit={(e) => handleSubmit(e)}>
21
                    <textarea
35
                    <input
22
                        className="form-control pe-4 bg-light"
36
                        className="form-control pe-4 bg-light"
23
                        rows="1"
37
                        type='text'
24
                        placeholder="Escribe un comentario"
38
                        placeholder="Escribe un comentario"
25
                        value={commentState}
39
                        value={commentState}
26
                        onChange={(e) => setCommentState(e.target.value)}
40
                        onChange={(e) => setCommentState(e.target.value)}
27
                    />
41
                    />
28
                </form>
42
                </form>
29
            </div>
43
            </div>
30
            <ul className="comment-wrap list-unstyled">
44
            <ul className="comment-wrap list-unstyled">
31
                {
45
                {
32
                    comments.map((comment) =>
46
                    commentState.map((comment) =>
33
                        <li className="comment-item">
47
                        <li className="comment-item">
34
                            <CommentTemplate
48
                            <CommentTemplate
35
                                key={comment.unique}
49
                                key={comment.unique}
36
                                feed_comment={comment}
50
                                feed_comment={comment}
37
                            />
51
                            />