1 |
|
import { VStack, Box, Text, HStack, ScrollView, Flex, Button, CloseIcon, IconButton, TextArea } from "native-base";
|
|
1 |
import { VStack, Box, Text, HStack, ScrollView, Flex, Button, CloseIcon, IconButton, TextArea, useToast } from "native-base";
|
2 |
2 |
import { Note } from "../../types/note";
|
3 |
3 |
import NoteView from "./NoteView";
|
4 |
4 |
import { MessageIcon } from "../general/Icons";
|
... | ... | |
9 |
9 |
import { useDispatch } from "react-redux";
|
10 |
10 |
import { Dimensions } from "react-native";
|
11 |
11 |
|
|
12 |
|
|
13 |
|
12 |
14 |
const NotesListView = (props: { notes: Note[], navigation: any, handleCreateComment: any, requestPending: boolean }) => {
|
13 |
15 |
const notes = props.notes;
|
14 |
16 |
|
|
17 |
const toast = useToast();
|
|
18 |
|
15 |
19 |
const [newComment, setNewComment] = useState<string>("");
|
16 |
20 |
const [replyingTo, setReplyingTo] = useState<{ messageId: string; userName: string } | null>(null);
|
17 |
21 |
|
... | ... | |
49 |
53 |
}
|
50 |
54 |
}, [dispatch, props.requestPending]);
|
51 |
55 |
|
52 |
|
const handleScrollEnd = (event : any) => {
|
|
56 |
const handleScrollEnd = (event: any) => {
|
53 |
57 |
const offsetY = event.nativeEvent.contentOffset.y;
|
54 |
58 |
const contentHeight = event.nativeEvent.contentSize.height;
|
55 |
59 |
const screenHeight = event.nativeEvent.layoutMeasurement.height;
|
... | ... | |
58 |
62 |
// Load more notes when the user is near the end of the list
|
59 |
63 |
const nextBatchSize = 5; // Number of notes to render in the next batch
|
60 |
64 |
|
61 |
|
if((renderedNotes + nextBatchSize) > notes.length && (renderedNotes + nextBatchSize) != notes.length){
|
|
65 |
if ((renderedNotes + nextBatchSize) > notes.length && (renderedNotes + nextBatchSize) != notes.length) {
|
62 |
66 |
setRenderedNotes(notes.length);
|
63 |
67 |
// TODO toast display info all rendered
|
64 |
68 |
}
|
65 |
|
else{
|
|
69 |
else if ((renderedNotes + nextBatchSize) != notes.length) {
|
66 |
70 |
setRenderedNotes(renderedNotes + nextBatchSize);
|
67 |
71 |
// TODO toast display loading more notes
|
68 |
72 |
}
|
69 |
73 |
}
|
70 |
74 |
};
|
71 |
75 |
|
72 |
|
console.log(renderedNotes)
|
73 |
|
console.log(notes.length)
|
74 |
|
|
75 |
76 |
return (
|
76 |
77 |
<VStack>
|
77 |
78 |
<Box height={windowHeight - 70 - 160 - (replyingTo ? 40 : 0)} marginBottom={2}>
|
... | ... | |
81 |
82 |
notes && notes.length > 0 ? (
|
82 |
83 |
<VStack>
|
83 |
84 |
{
|
84 |
|
notes.slice(0, renderedNotes).map((note, index) => (
|
85 |
|
<NoteView key={index} note={note} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} navigation={props.navigation} />
|
86 |
|
))
|
|
85 |
notes.slice(0, renderedNotes).map((note, index) => {
|
|
86 |
|
|
87 |
if(replyingTo?.messageId == note.uuid){
|
|
88 |
return <NoteView higlighted key={index} note={note} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} navigation={props.navigation} />
|
|
89 |
}
|
|
90 |
|
|
91 |
return <NoteView key={index} note={note} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} navigation={props.navigation} />;
|
|
92 |
|
|
93 |
})
|
87 |
94 |
}
|
88 |
95 |
</VStack>
|
89 |
96 |
) : (
|
... | ... | |
100 |
107 |
|
101 |
108 |
{/* Replying to */}
|
102 |
109 |
{replyingTo != null &&
|
103 |
|
<Flex direction="row" alignItems="center" justify="flex-end" marginRight={20} height={10}>
|
|
110 |
<Flex direction="row" alignItems="center" justify="flex-end" height={10} style={{backgroundColor: "#FFF8E1"}}>
|
104 |
111 |
<Text>Replying to {replyingTo.userName}</Text>
|
105 |
|
<IconButton onPress={() => setReplyingTo(null)} size="sm" icon={<CloseIcon />} marginLeft="-1%">
|
106 |
|
</IconButton>
|
|
112 |
<IconButton onPress={() => setReplyingTo(null)} size="sm" icon={<CloseIcon />} marginLeft="-1%" marginRight={20 }/>
|
107 |
113 |
</Flex>
|
108 |
114 |
}
|
109 |
115 |
|
#re 10797 NoteView: higlight replying to