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'; |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 22 | import { useContext, useEffect } 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'; |
Misha Krieger-Raynauld | cfa4430 | 2022-11-30 18:36:36 -0500 | [diff] [blame] | 25 | import { Conversation } from '../models/conversation'; |
simon | d8ca2f2 | 2022-10-11 23:30:55 -0400 | [diff] [blame] | 26 | import { useAppSelector } from '../redux/hooks'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 27 | import ConversationListItem from './ConversationListItem'; |
Adrien Béraud | 995e802 | 2021-04-08 13:46:51 -0400 | [diff] [blame] | 28 | |
simon | 6b9ddfb | 2022-10-03 00:04:50 -0400 | [diff] [blame] | 29 | type ConversationListProps = { |
simon | 6b9ddfb | 2022-10-03 00:04:50 -0400 | [diff] [blame] | 30 | conversations: Conversation[]; |
simon | 6b9ddfb | 2022-10-03 00:04:50 -0400 | [diff] [blame] | 31 | }; |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 32 | export default function ConversationList({ conversations }: ConversationListProps) { |
| 33 | const { searchResult } = useContext(MessengerContext); |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 34 | const { refresh } = useAppSelector((state) => state.userInfo); |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 35 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 36 | useEffect(() => { |
| 37 | console.log('refresh list'); |
| 38 | }, [refresh]); |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 39 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 40 | return ( |
| 41 | <div className="rooms-list"> |
| 42 | <List> |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 43 | {searchResult && ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 44 | <div> |
| 45 | <ListSubheader>Public directory</ListSubheader> |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 46 | <ConversationListItem conversation={searchResult} /> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 47 | <ListSubheader>Conversations</ListSubheader> |
| 48 | </div> |
| 49 | )} |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 50 | {conversations.map((conversation) => ( |
Misha Krieger-Raynauld | cfa4430 | 2022-11-30 18:36:36 -0500 | [diff] [blame] | 51 | <ConversationListItem key={conversation.id} conversation={conversation} /> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 52 | ))} |
simon | 21f7d9f | 2022-11-28 14:21:54 -0500 | [diff] [blame] | 53 | {conversations.length === 0 && ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 54 | <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éraud | 995e802 | 2021-04-08 13:46:51 -0400 | [diff] [blame] | 64 | } |