Revize bc25708c
Přidáno uživatelem Fantič před více než 1 rok
src/components/notes/NotesListView.tsx | ||
---|---|---|
15 | 15 |
const [newComment, setNewComment] = useState<string>(""); |
16 | 16 |
const [replyingTo, setReplyingTo] = useState<{ messageId: string; userName: string } | null>(null); |
17 | 17 |
|
18 |
const [renderedNotes, setRenderedNotes] = useState(6); |
|
19 |
|
|
18 | 20 |
const cancelRef = React.useRef(null); |
19 | 21 |
|
20 | 22 |
const dispatch = useDispatch<AppDispatch>(); |
... | ... | |
47 | 49 |
} |
48 | 50 |
}, [dispatch, props.requestPending]); |
49 | 51 |
|
52 |
const handleScrollEnd = (event : any) => { |
|
53 |
const offsetY = event.nativeEvent.contentOffset.y; |
|
54 |
const contentHeight = event.nativeEvent.contentSize.height; |
|
55 |
const screenHeight = event.nativeEvent.layoutMeasurement.height; |
|
56 |
|
|
57 |
if (offsetY + screenHeight >= contentHeight - 20) { |
|
58 |
// Load more notes when the user is near the end of the list |
|
59 |
const nextBatchSize = 5; // Number of notes to render in the next batch |
|
60 |
|
|
61 |
if((renderedNotes + nextBatchSize) > notes.length && (renderedNotes + nextBatchSize) != notes.length){ |
|
62 |
setRenderedNotes(notes.length); |
|
63 |
// TODO toast display info all rendered |
|
64 |
} |
|
65 |
else{ |
|
66 |
setRenderedNotes(renderedNotes + nextBatchSize); |
|
67 |
// TODO toast display loading more notes |
|
68 |
} |
|
69 |
} |
|
70 |
}; |
|
71 |
|
|
72 |
console.log(renderedNotes) |
|
73 |
console.log(notes.length) |
|
74 |
|
|
50 | 75 |
return ( |
51 | 76 |
<VStack> |
52 | 77 |
<Box height={windowHeight - 70 - 160 - (replyingTo ? 40 : 0)} marginBottom={2}> |
53 | 78 |
{/* Notes */} |
54 |
<ScrollView contentContainerStyle={{ flexGrow: 1 }}> |
|
79 |
<ScrollView contentContainerStyle={{ flexGrow: 1 }} onScrollEndDrag={handleScrollEnd}>
|
|
55 | 80 |
{ |
56 | 81 |
notes && notes.length > 0 ? ( |
57 | 82 |
<VStack> |
58 |
{notes.map((note, index) => { |
|
59 |
// if(index >= 5){ |
|
60 |
// return null; |
|
61 |
// } |
|
62 |
return ( |
|
83 |
{ |
|
84 |
notes.slice(0, renderedNotes).map((note, index) => ( |
|
63 | 85 |
<NoteView key={index} note={note} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} navigation={props.navigation} /> |
64 |
) |
|
65 |
})}
|
|
86 |
))
|
|
87 |
} |
|
66 | 88 |
</VStack> |
67 | 89 |
) : ( |
68 | 90 |
<Text>There are no notes.</Text> |
... | ... | |
84 | 106 |
</IconButton> |
85 | 107 |
</Flex> |
86 | 108 |
} |
87 |
|
|
109 |
|
|
88 | 110 |
|
89 | 111 |
{/* Add comment */} |
90 | 112 |
<HStack height={90} > |
Také k dispozici: Unified diff
#re 10797 NoteListView lazy loading -> scroll load more notes