Files
new-phone-who-dis/phone/src/apps/messages/components/form/MessageInput.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

67 lines
1.8 KiB
TypeScript

import React, { FormEvent, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Paper, Box, makeStyles, TextField, Button } from '@material-ui/core';
import SendIcon from '@material-ui/icons/Send';
import ImageIcon from '@material-ui/icons/Image';
import Nui from '../../../../os/nui-events/utils/Nui';
import { MessageEvents } from '../../../../../../typings/messages';
interface IProps {
onAddImageClick(): void;
messageGroupId: string | undefined;
messageGroupName: string | undefined;
}
const useStyles = makeStyles({
root: { width: '100%' },
});
const MessageInput = ({ messageGroupId, onAddImageClick }: IProps) => {
const { t } = useTranslation();
const classes = useStyles();
const [message, setMessage] = useState('');
const handleSubmit = (event: FormEvent) => {
event.preventDefault();
if (message.trim()) {
// don't allow the user to submit white space
Nui.send(MessageEvents.SEND_MESSAGE, {
groupId: messageGroupId,
message,
});
setMessage('');
}
};
if (!messageGroupId) return null;
return (
<Paper variant="outlined" className={classes.root}>
<form onSubmit={handleSubmit}>
<Box display="flex">
<Box pl={1} flexGrow={1}>
<TextField
fullWidth
inputProps={{ style: { fontSize: '1.3em' } }}
value={message}
onChange={(e) => setMessage(e.target.value)}
placeholder={t('APPS_MESSAGES_NEW_MESSAGE')}
/>
</Box>
<Box>
<Button onClick={onAddImageClick}>
<ImageIcon />
</Button>
<Button type="submit">
<SendIcon />
</Button>
</Box>
</Box>
</form>
</Paper>
);
};
export default MessageInput;