Projekt

Obecné

Profil

Stáhnout (3.72 KB) Statistiky
| Větev: | Tag: | Revize:
1
import { VStack, Box, Text, HStack, ScrollView, Flex, Button, CloseIcon, IconButton, TextArea } from "native-base";
2
import { Note } from "../../types/note";
3
import NoteView from "./NoteView";
4
import { MessageIcon } from "../general/Icons";
5
import React, { useState } from "react";
6
import { updateNote, deleteNote } from "../../stores/actions/notesThunks";
7
import { ConfirmDialog } from "../general/Dialogs";
8
import { AppDispatch } from "../../stores/store";
9
import { useDispatch } from "react-redux";
10

    
11
const NotesListView = (props: { notes: Note[], navigation: any, handleCreateComment: any, requestPending: boolean }) => {
12
    const notes = props.notes;
13

    
14
    const [newComment, setNewComment] = useState<string>("");
15
    const [replyingTo, setReplyingTo] = useState<{ messageId: string; userName: string } | null>(null);
16

    
17
    const cancelRef = React.useRef(null);
18

    
19
    const dispatch = useDispatch<AppDispatch>();
20

    
21
    const [confirmDialog, setConfirmDialog] = React.useState<{
22
        headerText?: string;
23
        bodyText?: string;
24
        confirmText?: string;
25
        confirmColor?: string;
26
        cancelRef?: any;
27
        onClose?: () => void;
28
        onSubmit?: () => void;
29
    } | null>(null);
30

    
31
    const handleReply = (messageId: string, userName: string) => {
32
        setReplyingTo({ messageId, userName })
33
    }
34

    
35
    const handleEdit = (note: Note) => {
36
        if (!props.requestPending)
37
            dispatch(updateNote(note));
38
    }
39

    
40
    const handleDelete = (messageId: string) => {
41
        if (!props.requestPending)
42
            dispatch(deleteNote({ noteId: messageId }))
43
    }
44

    
45
    return (
46
        <VStack>
47
            <Box h={props.handleCreateComment == null ? "88%" : (replyingTo != null ? "65%" : "70%")}>
48
                <ScrollView contentContainerStyle={{ flexGrow: 1 }}>
49
                    {
50
                        notes && notes.length > 0 ? (
51
                            <VStack>
52
                                {notes.map((note, index) => (
53
                                    <NoteView key={index} note={note} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} navigation={props.navigation} />
54
                                ))}
55
                            </VStack>
56
                        ) : (
57
                            <Text>There are no notes.</Text>
58
                        )
59
                    }
60
                </ScrollView>
61
            </Box>
62
            {
63
                props.handleCreateComment != null && replyingTo != null &&
64
                <Flex direction="row" alignItems="center" justify="flex-end" h="5%" marginRight="10%">
65
                    <Text>Replying to {replyingTo.userName}</Text>
66
                    <IconButton onPress={() => setReplyingTo(null)} size="sm" icon={<CloseIcon />} marginLeft="-1%">
67
                    </IconButton>
68
                </Flex>
69
            }
70

    
71
            {
72
                props.handleCreateComment != null &&
73
                <HStack h={replyingTo != null ? "20%" : "15%"} marginTop={replyingTo != null ? "0%" : "6%"}>
74
                    <TextArea placeholder="Add comment" width="90%" fontSize={14} value={newComment} onChangeText={setNewComment} autoCompleteType={undefined} ></TextArea>
75
                    <VStack>
76
                        <Box h={replyingTo != null ? "30%" : "45%"}></Box>
77
                        <Box marginLeft="2">
78
                            <Button onPress={() => props.handleCreateComment(newComment , replyingTo)} startIcon={<MessageIcon color="#FFF" />}></Button>
79
                        </Box>
80
                    </VStack>
81
                </HStack>
82
            }
83
            <ConfirmDialog {...confirmDialog} isShown={confirmDialog != null} cancelRef={cancelRef} />
84
        </VStack>
85
    );
86
}
87

    
88
export default NotesListView
(2-2/2)