Revize a27b3427
Přidáno uživatelem Fantič před více než 1 rok
src/components/notes/NoteView.tsx | ||
---|---|---|
1 |
import { HStack, Box, Text, Image, VStack, Flex, Pressable, DeleteIcon, Button, Center, Avatar, TextArea, AlertDialog } from "native-base"; |
|
1 |
import { HStack, Box, Text, Image, VStack, Flex, Pressable, DeleteIcon, Button, Center, Avatar, TextArea, AlertDialog, ScrollView } from "native-base";
|
|
2 | 2 |
import { Note } from "../../types/note"; |
3 | 3 |
import { EditIcon } from "../general/Icons"; |
4 | 4 |
import { AVATAR_URL } from "../../api/constants"; |
5 | 5 |
import { useState } from "react"; |
6 | 6 |
import React from "react"; |
7 |
import { StyleProp, ViewStyle } from "react-native";
|
|
7 |
import NotesListView from "./NotesListView";
|
|
8 | 8 |
|
9 |
const NoteView = React.memo((props: { note: Note, handleReply: any, handleDelete: any, handleEdit: any, setConfirmDialog: any, navigation: any }) => { |
|
9 |
const NoteView = React.memo((props: { note: Note, handleReply: any, handleDelete: any, handleEdit: any, setConfirmDialog: any, navigation: any, parentId?: string }) => {
|
|
10 | 10 |
const note = props.note; |
11 | 11 |
|
12 | 12 |
const [isEdited, setIsEdited] = useState(false); |
13 | 13 |
|
14 |
const [showReplies, setShowReplies] = useState(false); |
|
15 |
|
|
14 | 16 |
const [text, setText] = useState(note.note); |
15 | 17 |
|
16 |
console.log("rerender"); |
|
17 | 18 |
|
18 | 19 |
const getDateString = (timestamp: Date): string => { |
19 | 20 |
return new Date(timestamp).toLocaleString("en-US", |
... | ... | |
30 | 31 |
return "UK"; // Unknown |
31 | 32 |
} |
32 | 33 |
|
34 |
|
|
35 |
const toggleShowReplies = () => { |
|
36 |
console.log("Toggle showReplies"); |
|
37 |
setShowReplies(!showReplies) |
|
38 |
} |
|
39 |
|
|
33 | 40 |
const toggleEdited = () => { |
34 | 41 |
console.log("Toggle edit"); |
35 | 42 |
if (isEdited) { |
... | ... | |
127 | 134 |
<Pressable onPress={() => props.handleReply(note.uuid, note.username)}> |
128 | 135 |
<Text color="light.500">Reply</Text> |
129 | 136 |
</Pressable>} |
137 |
{!props.parentId && note.replies && note.replies.length > 0 && |
|
138 |
<Pressable marginLeft={3} onPress={() => toggleShowReplies()}> |
|
139 |
{!showReplies ? |
|
140 |
<Text color="light.500">{note.replies.length} replies</Text> |
|
141 |
: |
|
142 |
<Text color="light.500">Hide</Text> |
|
143 |
} |
|
144 |
|
|
145 |
</Pressable>} |
|
130 | 146 |
</Flex> |
131 | 147 |
|
132 | 148 |
<Flex direction="row" alignItems="center" justify="flex-end"> |
... | ... | |
150 | 166 |
</Pressable>} |
151 | 167 |
</Flex> |
152 | 168 |
</HStack> |
169 |
{showReplies && |
|
170 |
<VStack style={{borderLeftColor: '#FFC107', borderLeftWidth: 1, paddingLeft: 5, marginTop: 5}}> |
|
171 |
{note.replies?.map((note, index) => { |
|
172 |
return ( |
|
173 |
<NoteView key={index} note={note} handleReply={null} handleDelete={props.handleDelete} handleEdit={props.handleEdit} setConfirmDialog={props.setConfirmDialog} navigation={props.navigation} /> |
|
174 |
) |
|
175 |
})} |
|
176 |
</VStack> |
|
177 |
} |
|
153 | 178 |
</VStack> |
154 | 179 |
</HStack> |
155 | 180 |
); |
Také k dispozici: Unified diff
#re 10797 NoteView: Note replies base