Files
new-phone-who-dis/phone/src/apps/messages/components/list/MessagesList.tsx
T
Taso 0f61088999 refactor(events): Events are now tied to a common enum typings (#167)
* chore(scripts/twitter): Refactored twitter to use event enums

* chore(scripts/marketplace): Refactored marketplace to use event enums

* chore(scripts/messages): Refactored messages to use event enums

* chore(scripts/contacts): Refactored contacts to use event enums

* chore(scripts/calls): Refactored calls to use event enums

* chore(scripts/notes): Refactored notes to use event enums

* chore(scripts/photos): Refactored photos to use event enums

* chore(scripts/bank): Refactored bank to use event enums

* chore(scripts/phone): Refactored phone to use event enums

* chore(events): Removed old events object

* refactor(phone/nui-events): Attached NUI events to respective enum

* tweak(event-enums): Added npwd prefix to all events

* tweak(phone/serve): Added craco to override CRA without eject

Also bumped react-scripts to 4.0.1, with seemingly no issues

* fix(typings/twitter): Fixed method enums for twitter
2021-03-22 13:37:07 -04:00

89 lines
2.6 KiB
TypeScript

import React, { useEffect, useState } from 'react';
import { Box, List } from '@material-ui/core';
import { MessageEvents, MessageGroup } from '../../../../../../typings/messages';
import Nui from '../../../../os/nui-events/utils/Nui';
import useMessages from '../../hooks/useMessages';
import MessageGroupItem from './MessageGroupItem';
import useStyles from './list.styles';
import { useHistory } from 'react-router-dom';
import { goToConversation } from '../../utils/goToConversation';
import { SearchField } from '../../../../ui/components/SearchField';
import { useTranslation } from 'react-i18next';
const MessagesList = (): any => {
const classes = useStyles();
const history = useHistory();
const { t } = useTranslation();
const {
messageGroups,
createMessageGroupResult,
clearMessageGroupResult,
getMessageGroupById,
setActiveMessageGroup,
} = useMessages();
const [searchValue, setSearchValue] = useState('');
const formattedSearch = searchValue.toLowerCase().trim();
const filteredGroups = formattedSearch
? messageGroups.filter((group) => {
const groupDisplay = group.groupDisplay.toLowerCase();
const displayIncludes = groupDisplay.includes(formattedSearch);
const label = group.label?.toLowerCase();
return label ? displayIncludes || label.includes(formattedSearch) : displayIncludes;
})
: messageGroups;
useEffect(() => {
if (createMessageGroupResult?.groupId) {
const findGroup = getMessageGroupById(createMessageGroupResult.groupId);
clearMessageGroupResult();
if (findGroup) {
goToConversation(findGroup, history);
}
}
}, [
messageGroups,
createMessageGroupResult,
clearMessageGroupResult,
history,
setActiveMessageGroup,
getMessageGroupById,
]);
if (!messageGroups) return null;
const handleClick = (messageGroup: MessageGroup) => () => {
goToConversation(messageGroup, history);
};
return (
<Box display="flex" flexDirection="column">
<Box>
<SearchField
value={searchValue}
onChange={(e) => setSearchValue(e.target.value)}
placeholder={t('APPS_MESSAGES_SEARCH_PLACEHOLDER')}
/>
</Box>
<Box display="flex" flexDirection="column">
<Box className={classes.root}>
<List>
{filteredGroups.map((messageGroup) => (
<MessageGroupItem
key={messageGroup.groupId}
messageGroup={messageGroup}
handleClick={handleClick}
/>
))}
</List>
</Box>
</Box>
</Box>
);
};
export default MessagesList;