blob: 294e06947532ddab003cc59810f53a5ec232998a [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 */
simon9f814a32022-11-22 21:40:53 -050018import { Box, Stack } from '@mui/material';
simon21f7d9f2022-11-28 14:21:54 -050019import { ReactNode, useContext } from 'react';
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040020
Adrien Béraud6ecaa402021-04-06 17:37:25 -040021//import Sound from 'react-sound';
Adrien Béraud995e8022021-04-08 13:46:51 -040022import ConversationList from '../components/ConversationList';
simon07b4eb02022-09-29 17:50:26 -040023import Header from '../components/Header';
simon6b9ddfb2022-10-03 00:04:50 -040024import LoadingPage from '../components/Loading';
simon07b4eb02022-09-29 17:50:26 -040025import NewContactForm from '../components/NewContactForm';
simon21f7d9f2022-11-28 14:21:54 -050026import { MessengerContext } from '../contexts/MessengerProvider';
simonfe1de722022-10-02 00:21:43 -040027import AddContactPage from './AddContactPage';
ervinanoh34eb9472022-09-13 04:20:28 -040028
simon21f7d9f2022-11-28 14:21:54 -050029const Messenger = ({ children }: { children?: ReactNode }) => {
30 const { newContactId, conversations } = useContext(MessengerContext);
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040031
Adrien Béraud4e287b92021-04-24 16:15:56 -040032 return (
simon9f814a32022-11-22 21:40:53 -050033 <Box display="flex" height="100%">
simond47ef9e2022-09-28 22:24:28 -040034 <Stack flexGrow={0} flexShrink={0} overflow="auto">
idillonbef18a52022-09-01 01:51:40 -040035 <Header />
simon21f7d9f2022-11-28 14:21:54 -050036 <NewContactForm />
simonff1cb352022-11-24 15:15:26 -050037 {newContactId && <AddContactPage contactId={newContactId} />}
simond47ef9e2022-09-28 22:24:28 -040038 {conversations ? (
simon21f7d9f2022-11-28 14:21:54 -050039 <ConversationList conversations={conversations} />
simond47ef9e2022-09-28 22:24:28 -040040 ) : (
41 <div className="rooms-list">
42 <LoadingPage />
43 </div>
44 )}
idillonbef18a52022-09-01 01:51:40 -040045 </Stack>
simon9f814a32022-11-22 21:40:53 -050046 <Box flexGrow={1} display="flex" position="relative">
simon21f7d9f2022-11-28 14:21:54 -050047 {children}
simon9f814a32022-11-22 21:40:53 -050048 </Box>
49 </Box>
simond47ef9e2022-09-28 22:24:28 -040050 );
51};
Larbi Gharibe9af9732021-03-31 15:08:01 +010052
simond47ef9e2022-09-28 22:24:28 -040053export default Messenger;