blob: 2792fd486f7f31ce30339ea14524696828591858 [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 */
idillon2ef2be92022-12-30 10:59:06 -050018import { SearchRounded } from '@mui/icons-material';
19import { InputBase, List, Stack } from '@mui/material';
idillon847b4642022-12-29 14:28:38 -050020import { ChangeEvent, useCallback, useState } from 'react';
21import { useTranslation } from 'react-i18next';
simon07b4eb02022-09-29 17:50:26 -040022
idillon847b4642022-12-29 14:28:38 -050023import { useConversationsSummariesQuery } from '../services/conversationQueries';
24import { SquareButton } from './Button';
idillon07d31cc2022-12-06 22:40:14 -050025import ContactSearchResultList from './ContactSearchResultList';
simon07b4eb02022-09-29 17:50:26 -040026import ConversationListItem from './ConversationListItem';
idillon847b4642022-12-29 14:28:38 -050027import { PeopleGroupIcon } from './SvgIcon';
idillon2ef2be92022-12-30 10:59:06 -050028import { Tab, TabPanel, Tabs, TabsList } from './Tabs';
Adrien Béraud995e8022021-04-08 13:46:51 -040029
idillon07d31cc2022-12-06 22:40:14 -050030export default function ConversationList() {
idillon847b4642022-12-29 14:28:38 -050031 const { t } = useTranslation();
idillon847b4642022-12-29 14:28:38 -050032 const [searchFilter, setSearchFilter] = useState('');
33
idillon847b4642022-12-29 14:28:38 -050034 const handleInputChange = useCallback((event: ChangeEvent<HTMLInputElement>) => {
35 setSearchFilter(event.target.value);
36 }, []);
ervinanoh34eb9472022-09-13 04:20:28 -040037
simond47ef9e2022-09-28 22:24:28 -040038 return (
idillon847b4642022-12-29 14:28:38 -050039 <Stack>
40 <Stack direction="row">
41 <InputBase
42 type="search"
43 placeholder={t('find_users_and_conversations')}
44 onChange={handleInputChange}
45 startAdornment={<SearchRounded />}
46 sx={{
47 flexGrow: 1,
48 }}
49 />
50 <SquareButton aria-label="start swarm" Icon={PeopleGroupIcon} />
51 </Stack>
idillon2ef2be92022-12-30 10:59:06 -050052 {searchFilter ? <ContactSearchResultList searchFilter={searchFilter} /> : <ConversationTabs />}
idillon847b4642022-12-29 14:28:38 -050053 </Stack>
simond47ef9e2022-09-28 22:24:28 -040054 );
Adrien Béraud995e8022021-04-08 13:46:51 -040055}
idillon2ef2be92022-12-30 10:59:06 -050056
57const ConversationTabs = () => {
58 const { t } = useTranslation();
59 const invitations = [];
60
61 return (
62 <Tabs defaultValue={0}>
63 {invitations.length !== 0 && (
64 <TabsList>
65 <Tab>{t('conversations')}</Tab>
66 <Tab>{t('invitations')}</Tab>
67 </TabsList>
68 )}
69 <ConversationsTabPanel />
70 <InvitationsTabPanel />
71 </Tabs>
72 );
73};
74
75const ConversationsTabPanel = () => {
76 const conversationsSummariesQuery = useConversationsSummariesQuery();
77 const conversationsSummaries = conversationsSummariesQuery.data;
78
79 return (
80 <TabPanel value={0}>
81 <List>
82 {conversationsSummaries?.map((conversationSummary) => (
83 <ConversationListItem key={conversationSummary.id} conversationSummary={conversationSummary} />
84 ))}
85 </List>
86 </TabPanel>
87 );
88};
89
90const InvitationsTabPanel = () => {
91 const { t } = useTranslation();
92
93 return <TabPanel value={1}>{t('invitations')}</TabPanel>;
94};