blob: 3f7603f1b53c5338c8412736536ca8689850cd26 [file] [log] [blame]
simon26e79f72022-10-05 22:16:08 -04001/*
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éraudab519ff2022-05-03 15:34:48 -040018import { GroupRounded as GroupIcon } from '@mui/icons-material';
simon07b4eb02022-09-29 17:50:26 -040019import List from '@mui/material/List';
20import ListSubheader from '@mui/material/ListSubheader';
Adrien Béraudab519ff2022-05-03 15:34:48 -040021import Typography from '@mui/material/Typography';
idillon07d31cc2022-12-06 22:40:14 -050022import { useContext } from 'react';
simon07b4eb02022-09-29 17:50:26 -040023
simon21f7d9f2022-11-28 14:21:54 -050024import { MessengerContext } from '../contexts/MessengerProvider';
idillon07d31cc2022-12-06 22:40:14 -050025import ContactSearchResultList from './ContactSearchResultList';
simon07b4eb02022-09-29 17:50:26 -040026import ConversationListItem from './ConversationListItem';
idillon07d31cc2022-12-06 22:40:14 -050027import LoadingPage from './Loading';
Adrien Béraud995e8022021-04-08 13:46:51 -040028
idillon07d31cc2022-12-06 22:40:14 -050029export default function ConversationList() {
30 const { searchResult, conversationsSummaries } = useContext(MessengerContext);
ervinanoh34eb9472022-09-13 04:20:28 -040031
idillon07d31cc2022-12-06 22:40:14 -050032 if (!conversationsSummaries) {
33 return <LoadingPage />;
34 }
ervinanoh34eb9472022-09-13 04:20:28 -040035
simond47ef9e2022-09-28 22:24:28 -040036 return (
37 <div className="rooms-list">
38 <List>
simon21f7d9f2022-11-28 14:21:54 -050039 {searchResult && (
simond47ef9e2022-09-28 22:24:28 -040040 <div>
41 <ListSubheader>Public directory</ListSubheader>
idillon07d31cc2022-12-06 22:40:14 -050042 <ContactSearchResultList contacts={searchResult} />
simond47ef9e2022-09-28 22:24:28 -040043 <ListSubheader>Conversations</ListSubheader>
44 </div>
45 )}
idillon07d31cc2022-12-06 22:40:14 -050046 {conversationsSummaries.map((conversationSummary) => (
47 <ConversationListItem key={conversationSummary.id} conversationSummary={conversationSummary} />
simond47ef9e2022-09-28 22:24:28 -040048 ))}
idillon07d31cc2022-12-06 22:40:14 -050049 {conversationsSummaries.length === 0 && (
simond47ef9e2022-09-28 22:24:28 -040050 <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éraud995e8022021-04-08 13:46:51 -040060}