blob: 08553b7fd403c103b4dc2bc879c065c7bc035cb2 [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';
simon21f7d9f2022-11-28 14:21:54 -050022import { useContext, useEffect } from 'react';
simon07b4eb02022-09-29 17:50:26 -040023
simon21f7d9f2022-11-28 14:21:54 -050024import { MessengerContext } from '../contexts/MessengerProvider';
Misha Krieger-Raynauldcfa44302022-11-30 18:36:36 -050025import { Conversation } from '../models/conversation';
simond8ca2f22022-10-11 23:30:55 -040026import { useAppSelector } from '../redux/hooks';
simon07b4eb02022-09-29 17:50:26 -040027import ConversationListItem from './ConversationListItem';
Adrien Béraud995e8022021-04-08 13:46:51 -040028
simon6b9ddfb2022-10-03 00:04:50 -040029type ConversationListProps = {
simon6b9ddfb2022-10-03 00:04:50 -040030 conversations: Conversation[];
simon6b9ddfb2022-10-03 00:04:50 -040031};
simon21f7d9f2022-11-28 14:21:54 -050032export default function ConversationList({ conversations }: ConversationListProps) {
33 const { searchResult } = useContext(MessengerContext);
Michelle Sepkap Simee580f422022-10-31 23:27:04 -040034 const { refresh } = useAppSelector((state) => state.userInfo);
ervinanoh34eb9472022-09-13 04:20:28 -040035
simond47ef9e2022-09-28 22:24:28 -040036 useEffect(() => {
37 console.log('refresh list');
38 }, [refresh]);
ervinanoh34eb9472022-09-13 04:20:28 -040039
simond47ef9e2022-09-28 22:24:28 -040040 return (
41 <div className="rooms-list">
42 <List>
simon21f7d9f2022-11-28 14:21:54 -050043 {searchResult && (
simond47ef9e2022-09-28 22:24:28 -040044 <div>
45 <ListSubheader>Public directory</ListSubheader>
simon21f7d9f2022-11-28 14:21:54 -050046 <ConversationListItem conversation={searchResult} />
simond47ef9e2022-09-28 22:24:28 -040047 <ListSubheader>Conversations</ListSubheader>
48 </div>
49 )}
simon21f7d9f2022-11-28 14:21:54 -050050 {conversations.map((conversation) => (
Misha Krieger-Raynauldcfa44302022-11-30 18:36:36 -050051 <ConversationListItem key={conversation.id} conversation={conversation} />
simond47ef9e2022-09-28 22:24:28 -040052 ))}
simon21f7d9f2022-11-28 14:21:54 -050053 {conversations.length === 0 && (
simond47ef9e2022-09-28 22:24:28 -040054 <div className="list-placeholder">
55 <GroupIcon color="disabled" fontSize="large" />
56 <Typography className="subtitle" variant="subtitle2">
57 No conversation yet
58 </Typography>
59 </div>
60 )}
61 </List>
62 </div>
63 );
Adrien Béraud995e8022021-04-08 13:46:51 -040064}