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 | */ |
idillon | 2ef2be9 | 2022-12-30 10:59:06 -0500 | [diff] [blame] | 18 | import { SearchRounded } from '@mui/icons-material'; |
| 19 | import { InputBase, List, Stack } from '@mui/material'; |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 20 | import { ChangeEvent, useCallback, useState } from 'react'; |
| 21 | import { useTranslation } from 'react-i18next'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 22 | |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 23 | import { useConversationsSummariesQuery } from '../services/conversationQueries'; |
| 24 | import { SquareButton } from './Button'; |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 25 | import ContactSearchResultList from './ContactSearchResultList'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 26 | import ConversationListItem from './ConversationListItem'; |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 27 | import { PeopleGroupIcon } from './SvgIcon'; |
idillon | 2ef2be9 | 2022-12-30 10:59:06 -0500 | [diff] [blame] | 28 | import { Tab, TabPanel, Tabs, TabsList } from './Tabs'; |
Adrien Béraud | 995e802 | 2021-04-08 13:46:51 -0400 | [diff] [blame] | 29 | |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 30 | export default function ConversationList() { |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 31 | const { t } = useTranslation(); |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 32 | const [searchFilter, setSearchFilter] = useState(''); |
| 33 | |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 34 | const handleInputChange = useCallback((event: ChangeEvent<HTMLInputElement>) => { |
| 35 | setSearchFilter(event.target.value); |
| 36 | }, []); |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 37 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 38 | return ( |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 39 | <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> |
idillon | 2ef2be9 | 2022-12-30 10:59:06 -0500 | [diff] [blame] | 52 | {searchFilter ? <ContactSearchResultList searchFilter={searchFilter} /> : <ConversationTabs />} |
idillon | 847b464 | 2022-12-29 14:28:38 -0500 | [diff] [blame] | 53 | </Stack> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 54 | ); |
Adrien Béraud | 995e802 | 2021-04-08 13:46:51 -0400 | [diff] [blame] | 55 | } |
idillon | 2ef2be9 | 2022-12-30 10:59:06 -0500 | [diff] [blame] | 56 | |
| 57 | const 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 | |
| 75 | const 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 | |
| 90 | const InvitationsTabPanel = () => { |
| 91 | const { t } = useTranslation(); |
| 92 | |
| 93 | return <TabPanel value={1}>{t('invitations')}</TabPanel>; |
| 94 | }; |