Revize 2135f53d
Přidáno uživatelem Fantič před téměř 2 roky(ů)
src/components/notes/NotesListView.tsx | ||
---|---|---|
1 |
import { Center, VStack, Box, Text, HStack, ScrollView } from "native-base";
|
|
1 |
import { VStack, Box, Text, HStack, ScrollView, Flex, Button, CloseIcon, IconButton, TextArea } from "native-base";
|
|
2 | 2 |
import { Note } from "../../types/note"; |
3 | 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"; |
|
4 | 10 |
|
5 |
const NotesListView = (props: { notes: Note[], handleReply : any, handleDelete : any, handleEdit : any, setConfirmDialog: any, navigation: any}) => {
|
|
11 |
const NotesListView = (props: { notes: Note[], navigation: any, handleCreateComment: any, requestPending: boolean }) => {
|
|
6 | 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 |
|
|
7 | 45 |
return ( |
8 |
<ScrollView> |
|
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 |
|
|
9 | 71 |
{ |
10 |
notes && notes.length > 0 ? ( |
|
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> |
|
11 | 75 |
<VStack> |
12 |
{notes.map((note, index) => ( |
|
13 |
<NoteView key={index} note={note} handleReply={props.handleReply} handleDelete={props.handleDelete} handleEdit={props.handleEdit} setConfirmDialog={props.setConfirmDialog} navigation={props.navigation}/> |
|
14 |
))} |
|
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> |
|
15 | 80 |
</VStack> |
16 |
) : ( |
|
17 |
<Text>There are no notes.</Text> |
|
18 |
) |
|
81 |
</HStack> |
|
19 | 82 |
} |
20 |
</ScrollView> |
|
83 |
<ConfirmDialog {...confirmDialog} isShown={confirmDialog != null} cancelRef={cancelRef} /> |
|
84 |
</VStack> |
|
21 | 85 |
); |
22 | 86 |
} |
23 | 87 |
|
Také k dispozici: Unified diff
re #10678: ItemNotes refactor NoteListView