2024-01-26 20:43:57 +00:00
|
|
|
import React, { useEffect, useRef } from 'react';
|
2024-01-25 14:11:07 +00:00
|
|
|
import { FlatList } from 'react-native';
|
|
|
|
|
|
|
|
import { Quote } from './Quote';
|
|
|
|
import { useRoomContext } from '../../../../views/RoomView/context';
|
|
|
|
|
|
|
|
export const Quotes = (): React.ReactElement | null => {
|
|
|
|
const { selectedMessages, action } = useRoomContext();
|
2024-01-26 20:43:57 +00:00
|
|
|
const nQuotesRef = useRef(0);
|
|
|
|
const listRef = useRef<FlatList>(null);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (nQuotesRef.current && nQuotesRef.current < selectedMessages.length) {
|
|
|
|
setTimeout(() => {
|
|
|
|
listRef.current?.scrollToEnd({ animated: true });
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
nQuotesRef.current = selectedMessages.length;
|
|
|
|
}, [selectedMessages.length]);
|
2024-01-25 14:11:07 +00:00
|
|
|
|
|
|
|
if (action !== 'quote') {
|
|
|
|
return null;
|
|
|
|
}
|
2024-01-26 20:43:57 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<FlatList
|
|
|
|
ref={listRef}
|
|
|
|
data={selectedMessages}
|
|
|
|
renderItem={({ item }) => <Quote messageId={item} />}
|
|
|
|
horizontal
|
|
|
|
keyExtractor={item => item}
|
|
|
|
/>
|
|
|
|
);
|
2024-01-25 14:11:07 +00:00
|
|
|
};
|