This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
website/components/Application/Messages/Messages.tsx

51 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-03-16 14:04:19 +01:00
import useTranslation from 'next-translate/useTranslation'
import InfiniteScroll from 'react-infinite-scroll-component'
2022-08-31 21:44:33 +02:00
import { AnimatePresence } from 'framer-motion'
import { Loader } from '../../design/Loader'
import { Message } from './Message'
import { useMessages } from '../../../contexts/Messages'
import { Emoji } from '../../Emoji'
export const Messages: React.FC = () => {
2022-03-16 14:04:19 +01:00
const { t } = useTranslation()
const { messages, hasMore, nextPage } = useMessages()
if (messages.length === 0) {
return (
<div
id='messages'
className='scrollbar-firefox-support mt-8 flex w-full flex-1 flex-col overflow-y-auto text-center text-lg transition-all'
>
<p>
2022-03-16 14:04:19 +01:00
{t('application:nothing-here')} <Emoji value=':ghost:' size={20} />
</p>
2022-03-16 14:04:19 +01:00
<p>{t('application:start-chatting-kill-ghost')}</p>
</div>
)
}
return (
<div
id='messages'
className='scrollbar-firefox-support flex w-full flex-1 flex-col-reverse overflow-y-auto transition-all'
>
2022-08-31 21:44:33 +02:00
<AnimatePresence>
<InfiniteScroll
scrollableTarget='messages'
className='messages-list !overflow-x-hidden'
dataLength={messages.length}
next={nextPage}
inverse
hasMore={hasMore}
loader={<Loader />}
>
{messages.map((message) => {
return <Message key={message.id} message={message} />
})}
</InfiniteScroll>
</AnimatePresence>
</div>
)
}