mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 06:28:51 +00:00
Feat / Reusable SearchField + Fixed Messages align bottom flex with scroll (first message starts at bottom) (#151)
* feat(phone/ui): Make SearchField a reusable component * Fixed conversation scrolling and align bottom * feat(phone/ui): Autoscroll fix * feat(phone/ui): Autoscroll fix remove unused deps * feat(phone/ui): Autoscroll add needed dep for new messages
This commit is contained in:
1 parent
1659fa1654
commit
e56ae415dc
13 files changed
+162
-196
No files matched your search
@@ -1,83 +1,22 @@
|
||||
import React from 'react';
|
||||
import { InputBase } from '@material-ui/core';
|
||||
import SearchIcon from '@material-ui/icons/Search';
|
||||
import { createStyles, Theme, makeStyles } from '@material-ui/core/styles';
|
||||
import { Box } from '@material-ui/core';
|
||||
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useFilteredContacts } from '../../hooks/useFilteredContacts';
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) =>
|
||||
createStyles({
|
||||
bg: {
|
||||
backgroundColor: theme.palette.background.paper,
|
||||
display: 'flex',
|
||||
height: 60,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
},
|
||||
textFieldInput: {
|
||||
fontSize: 20,
|
||||
},
|
||||
inputRoot: {
|
||||
fontSize: 18,
|
||||
border: '1px solid',
|
||||
borderColor: theme.palette.divider,
|
||||
},
|
||||
inputInput: {
|
||||
padding: theme.spacing(1, 4, 1, 4),
|
||||
transition: theme.transitions.create('width'),
|
||||
[theme.breakpoints.up('sm')]: {
|
||||
width: '13ch',
|
||||
'&:focus': {
|
||||
width: '20ch',
|
||||
},
|
||||
},
|
||||
},
|
||||
search: {
|
||||
position: 'relative',
|
||||
borderRadius: theme.shape.borderRadius,
|
||||
marginLeft: 0,
|
||||
width: '100%',
|
||||
[theme.breakpoints.up('sm')]: {
|
||||
marginLeft: theme.spacing(1),
|
||||
width: 'auto',
|
||||
},
|
||||
},
|
||||
searchIcon: {
|
||||
padding: theme.spacing(0, 0.5),
|
||||
height: '100%',
|
||||
position: 'absolute',
|
||||
pointerEvents: 'none',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
}),
|
||||
);
|
||||
import { SearchField } from '../../../../ui/components/SearchField';
|
||||
|
||||
export const SearchContacts = () => {
|
||||
const { setFilteredContacts } = useFilteredContacts();
|
||||
const classes = useStyles();
|
||||
const { setFilteredContacts, filteredContacts } = useFilteredContacts();
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className={classes.bg}>
|
||||
<div className={classes.search}>
|
||||
<div className={classes.searchIcon}>
|
||||
<SearchIcon />
|
||||
</div>
|
||||
<InputBase
|
||||
fullWidth
|
||||
onChange={(e) => setFilteredContacts(e.target.value)}
|
||||
placeholder={t('APPS_CONTACT_PLACEHOLDER_SEARCH_CONTACTS')}
|
||||
classes={{
|
||||
root: classes.inputRoot,
|
||||
input: classes.inputInput,
|
||||
}}
|
||||
inputProps={{ 'aria-label': 'search', autoFocus: true }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Box>
|
||||
<SearchField
|
||||
onChange={(e) => setFilteredContacts(e.target.value)}
|
||||
placeholder={t('APPS_CONTACT_PLACEHOLDER_SEARCH_CONTACTS')}
|
||||
value={filteredContacts}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -32,10 +32,7 @@ export const MessagesApp = () => {
|
||||
</div>
|
||||
</Route>
|
||||
<Route exact path="/messages">
|
||||
<>
|
||||
<MessagesList />
|
||||
<NewMessageGroupButton onClick={() => history.push('/messages/new')} />
|
||||
</>
|
||||
<MessagesList />
|
||||
</Route>
|
||||
</Switch>
|
||||
<Switch>
|
||||
@@ -44,6 +41,9 @@ export const MessagesApp = () => {
|
||||
</Route>
|
||||
</Switch>
|
||||
</AppContent>
|
||||
<Route exact path="/messages">
|
||||
<NewMessageGroupButton onClick={() => history.push('/messages/new')} />
|
||||
</Route>
|
||||
</AppWrapper>
|
||||
</MessagesThemeProvider>
|
||||
);
|
||||
|
||||
@@ -12,7 +12,7 @@ interface IProps {
|
||||
}
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: { position: 'absolute', bottom: 0, width: '100%' },
|
||||
root: { width: '100%' },
|
||||
});
|
||||
|
||||
const MessageInput = ({ messageGroupId, onAddImageClick }: IProps) => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Fab } from '@material-ui/core';
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
position: 'absolute',
|
||||
bottom: theme.spacing(2),
|
||||
bottom: theme.spacing(5),
|
||||
right: theme.spacing(3),
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { InputBase, Paper } from '@material-ui/core';
|
||||
import SearchIcon from '@material-ui/icons/Search';
|
||||
|
||||
import useStyles from './list.styles';
|
||||
|
||||
interface IProps {
|
||||
value: string;
|
||||
handleChange: (event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => void;
|
||||
}
|
||||
|
||||
const MessageSearch = ({ value, handleChange }: IProps) => {
|
||||
const { t } = useTranslation();
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<Paper elevation={24} variant="outlined" className={classes.bg}>
|
||||
<div className={classes.search}>
|
||||
<div className={classes.searchIcon}>
|
||||
<SearchIcon />
|
||||
</div>
|
||||
<InputBase
|
||||
value={value}
|
||||
onChange={handleChange}
|
||||
placeholder={t('APPS_MESSAGES_SEARCH_PLACEHOLDER')}
|
||||
classes={{
|
||||
root: classes.inputRoot,
|
||||
input: classes.inputInput,
|
||||
}}
|
||||
inputProps={{ 'aria-label': 'search' }}
|
||||
/>
|
||||
</div>
|
||||
</Paper>
|
||||
);
|
||||
};
|
||||
|
||||
export default MessageSearch;
|
||||
@@ -1,17 +1,19 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { List } from '@material-ui/core';
|
||||
import { Box, List } from '@material-ui/core';
|
||||
import { MessageGroup } from '../../../../common/typings/messages';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import useMessages from '../../hooks/useMessages';
|
||||
import MessageSearch from './MessageSearch';
|
||||
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 } = useMessages();
|
||||
|
||||
@@ -46,18 +48,28 @@ const MessagesList = (): any => {
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<MessageSearch value={searchValue} handleChange={(e) => setSearchValue(e.target.value)} />
|
||||
<List className={classes.root}>
|
||||
{filteredGroups.map((messageGroup) => (
|
||||
<MessageGroupItem
|
||||
key={messageGroup.groupId}
|
||||
messageGroup={messageGroup}
|
||||
handleClick={handleClick}
|
||||
/>
|
||||
))}
|
||||
</List>
|
||||
</>
|
||||
<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>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,61 +1,10 @@
|
||||
import { makeStyles, fade } from '@material-ui/core';
|
||||
import { makeStyles } from '@material-ui/core';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
height: '100%',
|
||||
height: '580px',
|
||||
overflowY: 'auto',
|
||||
},
|
||||
bg: {
|
||||
display: 'flex',
|
||||
height: 60,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
},
|
||||
textFieldInput: {
|
||||
fontSize: 20,
|
||||
},
|
||||
inputRoot: {
|
||||
fontWeight: 400,
|
||||
fontSize: 18,
|
||||
border: '1px solid',
|
||||
borderColor: theme.palette.divider,
|
||||
},
|
||||
inputInput: {
|
||||
padding: theme.spacing(1, 4, 1, 4),
|
||||
// vertical padding + font size from searchIcon
|
||||
transition: theme.transitions.create('width'),
|
||||
width: '100%',
|
||||
|
||||
[theme.breakpoints.up('sm')]: {
|
||||
width: '13ch',
|
||||
'&:focus': {
|
||||
width: '24ch',
|
||||
},
|
||||
},
|
||||
},
|
||||
search: {
|
||||
position: 'relative',
|
||||
borderRadius: theme.shape.borderRadius,
|
||||
backgroundColor: fade(theme.palette.common.white, 0.25),
|
||||
'&:hover': {
|
||||
backgroundColor: fade(theme.palette.common.white, 0.25),
|
||||
},
|
||||
marginLeft: 0,
|
||||
width: '100%',
|
||||
[theme.breakpoints.up('sm')]: {
|
||||
marginLeft: theme.spacing(1),
|
||||
width: 'auto',
|
||||
},
|
||||
},
|
||||
searchIcon: {
|
||||
padding: theme.spacing(0, 0.5),
|
||||
height: '100%',
|
||||
position: 'absolute',
|
||||
pointerEvents: 'none',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
}));
|
||||
|
||||
export default useStyles;
|
||||
@@ -30,15 +30,29 @@ const Conversation = ({ activeMessageGroup, messages, onClickDisplay }: IProps)
|
||||
isOpen={imageModalOpen}
|
||||
messageGroupId={activeMessageGroup.groupId}
|
||||
/>
|
||||
<Box id={CONVERSATION_ELEMENT_ID} height="85%" py={6} className={classes.overflowAutoY}>
|
||||
{messages.map((message) => (
|
||||
<MessageBubble
|
||||
onClickDisplay={onClickDisplay}
|
||||
key={message.id}
|
||||
message={message}
|
||||
isGroupChat={activeMessageGroup?.isGroupChat}
|
||||
/>
|
||||
))}
|
||||
<Box
|
||||
id={CONVERSATION_ELEMENT_ID}
|
||||
height="85%"
|
||||
pt={6}
|
||||
style={{ flex: 1, display: 'flex', overflowY: 'auto' }}
|
||||
>
|
||||
<Box
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
minHeight: 'min-content',
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
{messages.map((message) => (
|
||||
<MessageBubble
|
||||
onClickDisplay={onClickDisplay}
|
||||
key={message.id}
|
||||
message={message}
|
||||
isGroupChat={activeMessageGroup?.isGroupChat}
|
||||
/>
|
||||
))}
|
||||
</Box>
|
||||
</Box>
|
||||
<MessageInput
|
||||
/* I should do some groupDiplay here */
|
||||
|
||||
@@ -3,6 +3,11 @@ import React from 'react';
|
||||
import { Message } from '../../../../common/typings/messages';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
'&:first-child': {
|
||||
marginTop: 'auto',
|
||||
},
|
||||
},
|
||||
imageMessage: {
|
||||
width: '80%',
|
||||
maxWidth: '80%',
|
||||
@@ -55,7 +60,7 @@ export const MessageBubble = ({
|
||||
}) => {
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<div>
|
||||
<div className={classes.root}>
|
||||
<Paper className={message.isMine ? classes.mySms : classes.sms} variant="outlined">
|
||||
<Box className={classes.message}>
|
||||
{isImage(message.message) ? (
|
||||
|
||||
@@ -82,13 +82,13 @@ export const MessageModal = () => {
|
||||
}, [groupId, setActiveMessageGroup]);
|
||||
|
||||
useEffect(() => {
|
||||
if (messages) {
|
||||
if (isLoaded && messages) {
|
||||
const element = document.getElementById(CONVERSATION_ELEMENT_ID);
|
||||
if (element) {
|
||||
element.scrollTop = element.scrollHeight;
|
||||
}
|
||||
}
|
||||
}, [messages]);
|
||||
}, [isLoaded, messages]);
|
||||
|
||||
// sends all unread messages
|
||||
useEffect(() => {
|
||||
|
||||
@@ -26,10 +26,9 @@ const useStyles = makeStyles({
|
||||
bottom: '0',
|
||||
},
|
||||
overflowAutoY: {
|
||||
flex: 6,
|
||||
height: '550px',
|
||||
overflowY: 'auto',
|
||||
overflowX: 'hidden',
|
||||
justifyContent: 'end',
|
||||
},
|
||||
groupdisplay: {
|
||||
width: '300px',
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
"APPS_CONTACT_UPDATE_FAILED": "Failed to update contact!",
|
||||
"APPS_CONTACT_DELETE_SUCCESS": "Successfully deleted contact!",
|
||||
"APPS_CONTACT_DELETE_FAILED": "Failed to delete contact!",
|
||||
"APPS_CONTACT_PLACEHOLDER_SEARCH_CONTACTS": "Search contacts",
|
||||
"APPS_CONTACT_PLACEHOLDER_SEARCH_CONTACTS": "Search contacts...",
|
||||
"APPS_CONTACT_MODAL_PLACEHOLDER_NAME": "Name",
|
||||
"APPS_CONTACT_MODAL_PLACEHOLDER_NUMBER": "Number",
|
||||
"APPS_CONTACT_MODAL_PLACEHOLDER_AVATAR": "Avatar",
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import React from 'react';
|
||||
import { emphasize, InputBase, makeStyles, Paper } from '@material-ui/core';
|
||||
import SearchIcon from '@material-ui/icons/Search';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
bg: {
|
||||
display: 'flex',
|
||||
height: '60px',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
},
|
||||
textFieldInput: {
|
||||
fontSize: 20,
|
||||
},
|
||||
inputRoot: {
|
||||
fontWeight: 400,
|
||||
fontSize: 18,
|
||||
border: '1px solid',
|
||||
borderColor: theme.palette.divider,
|
||||
},
|
||||
inputInput: {
|
||||
padding: theme.spacing(1, 4, 1, 4),
|
||||
// vertical padding + font size from searchIcon
|
||||
transition: theme.transitions.create(['width', 'border']),
|
||||
width: '16ch',
|
||||
'&:focus': {
|
||||
width: '24ch',
|
||||
borderLeft: `2px solid ${theme.palette.primary.main} `,
|
||||
},
|
||||
},
|
||||
search: {
|
||||
position: 'relative',
|
||||
borderRadius: theme.shape.borderRadius,
|
||||
backgroundColor: emphasize(theme.palette.background.paper, 0.21),
|
||||
'&:hover': {
|
||||
backgroundColor: emphasize(theme.palette.background.paper, 0.28),
|
||||
},
|
||||
marginLeft: theme.spacing(1),
|
||||
width: 'auto',
|
||||
},
|
||||
searchIcon: {
|
||||
padding: theme.spacing(0, 0.7),
|
||||
height: '100%',
|
||||
position: 'absolute',
|
||||
pointerEvents: 'none',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
}));
|
||||
|
||||
interface IProps {
|
||||
onChange: (event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => void;
|
||||
value: string;
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
const DEFAULT_PROPS = {
|
||||
onChange: () => {},
|
||||
value: '',
|
||||
placeholder: 'Search...',
|
||||
};
|
||||
|
||||
export const SearchField = ({ value, onChange, placeholder }: IProps = DEFAULT_PROPS) => {
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<Paper elevation={24} variant="outlined" className={classes.bg}>
|
||||
<div className={classes.search}>
|
||||
<div className={classes.searchIcon}>
|
||||
<SearchIcon />
|
||||
</div>
|
||||
<InputBase
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
placeholder={placeholder}
|
||||
classes={{
|
||||
root: classes.inputRoot,
|
||||
input: classes.inputInput,
|
||||
}}
|
||||
inputProps={{ 'aria-label': 'search' }}
|
||||
/>
|
||||
</div>
|
||||
</Paper>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user