simon | 26e79f7 | 2022-10-05 22:16:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 18 | import { GroupRounded as GroupIcon } from '@mui/icons-material'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 19 | import List from '@mui/material/List'; |
| 20 | import ListSubheader from '@mui/material/ListSubheader'; |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 21 | import Typography from '@mui/material/Typography'; |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 22 | import { useContext } from 'react'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 23 | |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 24 | import { MessengerContext } from '../contexts/MessengerProvider'; |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 25 | import ContactSearchResultList from './ContactSearchResultList'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 26 | import ConversationListItem from './ConversationListItem'; |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 27 | import LoadingPage from './Loading'; |
Adrien Béraud | 995e802 | 2021-04-08 13:46:51 -0400 | [diff] [blame] | 28 | |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 29 | export default function ConversationList() { |
| 30 | const { searchResult, conversationsSummaries } = useContext(MessengerContext); |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 31 | |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 32 | if (!conversationsSummaries) { |
| 33 | return <LoadingPage />; |
| 34 | } |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 35 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 36 | return ( |
| 37 | <div className="rooms-list"> |
| 38 | <List> |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 39 | {searchResult && ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 40 | <div> |
| 41 | <ListSubheader>Public directory</ListSubheader> |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 42 | <ContactSearchResultList contacts={searchResult} /> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 43 | <ListSubheader>Conversations</ListSubheader> |
| 44 | </div> |
| 45 | )} |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 46 | {conversationsSummaries.map((conversationSummary) => ( |
| 47 | <ConversationListItem key={conversationSummary.id} conversationSummary={conversationSummary} /> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 48 | ))} |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 49 | {conversationsSummaries.length === 0 && ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 50 | <div className="list-placeholder"> |
| 51 | <GroupIcon color="disabled" fontSize="large" /> |
| 52 | <Typography className="subtitle" variant="subtitle2"> |
| 53 | No conversation yet |
| 54 | </Typography> |
| 55 | </div> |
| 56 | )} |
| 57 | </List> |
| 58 | </div> |
| 59 | ); |
Adrien Béraud | 995e802 | 2021-04-08 13:46:51 -0400 | [diff] [blame] | 60 | } |