mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Make Camera app use router (#69)
* Make Camera app use router * Remove unused hooks * Fucking communicate messages with camera with router * Improved sharing in messages flow * Fix clipboard * Removeunused imports * improve routing helpers * Fix bug :D * Fix stupid thing * Add docs to useQueryParams hook
This commit is contained in:
1 parent
447c51a07e
commit
40f9555b39
34 files changed
+481
-294
No files matched your search
@@ -7,7 +7,6 @@ import {
|
||||
TextField,
|
||||
makeStyles,
|
||||
} from '@material-ui/core';
|
||||
import CloseIcon from '@material-ui/icons/Close';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
|
||||
@@ -33,11 +32,6 @@ const useStyles = makeStyles((theme) => ({
|
||||
fontSize: 16,
|
||||
marginBottom: 30,
|
||||
},
|
||||
closeButton: {
|
||||
position: 'absolute',
|
||||
right: 0,
|
||||
width: '10%',
|
||||
},
|
||||
}));
|
||||
|
||||
export const TransferModal = () => {
|
||||
@@ -65,9 +59,6 @@ export const TransferModal = () => {
|
||||
|
||||
return (
|
||||
<Modal visible={showBankModal} handleClose={_handleClose}>
|
||||
<Button className={classes.closeButton} onClick={_handleClose}>
|
||||
<CloseIcon />
|
||||
</Button>
|
||||
<List style={{ marginTop: 20 }}>
|
||||
<ListItem>
|
||||
<TextField
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import React from 'react';
|
||||
import { AppWrapper } from '../../../ui/components';
|
||||
import { AppContent } from '../../../ui/components/AppContent';
|
||||
import { usePhotoModal } from '../hooks/usePhotoModal';
|
||||
import { GalleryGrid } from './grid/GalleryGrid';
|
||||
import { GalleryModal } from './modal/GalleryModal';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import { Route, Switch } from 'react-router-dom';
|
||||
|
||||
InjectDebugData([
|
||||
{
|
||||
@@ -24,19 +24,13 @@ InjectDebugData([
|
||||
]);
|
||||
|
||||
const CameraApp = () => {
|
||||
const { modal } = usePhotoModal();
|
||||
|
||||
return (
|
||||
<AppWrapper id='camera-app'>
|
||||
<AppContent>
|
||||
<GalleryModal />
|
||||
{/*<Router>
|
||||
<Switch>
|
||||
<Route path="/camera/image" component={GalleryModal} />
|
||||
<Route path="/" exact component={GalleryGrid} />
|
||||
</Switch>
|
||||
</Router>*/}
|
||||
{!modal ? <GalleryGrid /> : null}
|
||||
<Switch>
|
||||
<Route path='/camera' exact component={GalleryGrid} />
|
||||
<Route path='/camera/image' exact component={GalleryModal} />
|
||||
</Switch>
|
||||
</AppContent>
|
||||
</AppWrapper>
|
||||
);
|
||||
|
||||
@@ -4,28 +4,30 @@ import useStyles from './grid.styles';
|
||||
import { usePhotos } from '../../hooks/usePhotos';
|
||||
import AddIcon from '@material-ui/icons/Add';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { usePhotoModal } from '../../hooks/usePhotoModal';
|
||||
import { usePhotoMeta } from '../../hooks/usePhotoMeta';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { addQueryToLocation } from '../../../../common/utils/addQueryToLocation';
|
||||
import { getLocationFromUrl } from '../../../../common/utils/getLocationFromUrl';
|
||||
|
||||
// isMessage will work as a style handler kinda. If the gallery is rendered in the messages,
|
||||
// it will have the value true, which basically means a tweak on the design to fit in a modal
|
||||
export const GalleryGrid = (isMessags) => {
|
||||
export const GalleryGrid = () => {
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const query = useQueryParams();
|
||||
|
||||
const { setMeta } = usePhotoMeta();
|
||||
const { setModal } = usePhotoModal();
|
||||
const referal = query.referal
|
||||
? decodeURIComponent(query.referal)
|
||||
: '/camera/image';
|
||||
|
||||
const photos = usePhotos();
|
||||
|
||||
console.log(photos);
|
||||
|
||||
const handleCamera = () => {
|
||||
Nui.send('phone:TakePhoto', {});
|
||||
};
|
||||
|
||||
const handlePhotoOpen = (photo) => {
|
||||
setModal(true);
|
||||
setMeta(photo);
|
||||
history.push(
|
||||
addQueryToLocation(getLocationFromUrl(referal), 'image', photo.image)
|
||||
);
|
||||
};
|
||||
|
||||
if (!photos)
|
||||
@@ -66,7 +68,7 @@ export const GalleryGrid = (isMessags) => {
|
||||
</Button>
|
||||
</Box>
|
||||
{photos.map((photo) => (
|
||||
<Box onClick={() => handlePhotoOpen(photo)}>
|
||||
<Box key={photo.id} onClick={() => handlePhotoOpen(photo)}>
|
||||
<div
|
||||
style={{ backgroundImage: `url(${photo.image})` }}
|
||||
className={classes.photo}
|
||||
|
||||
@@ -1,63 +1,66 @@
|
||||
import React from 'react';
|
||||
import { usePhotoMeta } from '../../hooks/usePhotoMeta';
|
||||
import { usePhotoModal } from '../../hooks/usePhotoModal';
|
||||
import React, { useMemo, useState, useCallback } from 'react';
|
||||
import useStyles from './modal.styles';
|
||||
import { Button, Paper } from '@material-ui/core';
|
||||
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||
import DeleteIcon from '@material-ui/icons/Delete';
|
||||
import ShareIcon from '@material-ui/icons/Share';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useShareModal } from '../../hooks/useShareModal';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { ICameraPhoto } from '../../hooks/usePhotos';
|
||||
import { ShareModal } from './ShareModal';
|
||||
import { useShareLink } from '../../hooks/useShareLink';
|
||||
|
||||
export const GalleryModal = () => {
|
||||
const { meta, setMeta } = usePhotoMeta();
|
||||
const { modal, setModal } = usePhotoModal();
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const query = useQueryParams();
|
||||
const referal = query.referal || '/camera';
|
||||
|
||||
const { shareModal, setShareModal } = useShareModal();
|
||||
const { setShareLink } = useShareLink();
|
||||
const [shareOpen, setShareOpen] = useState(null);
|
||||
|
||||
const meta: ICameraPhoto = useMemo(
|
||||
() => ({ id: query.id as string, image: query.image as string }),
|
||||
[query]
|
||||
);
|
||||
|
||||
const _handleClose = () => {
|
||||
setModal(false);
|
||||
setMeta(null);
|
||||
history.push(referal);
|
||||
};
|
||||
|
||||
const handleDeletePhoto = () => {
|
||||
console.log(meta.id);
|
||||
const handleDeletePhoto = useCallback(() => {
|
||||
Nui.send('photo:deletePhoto', {
|
||||
id: meta.id,
|
||||
});
|
||||
setModal(false);
|
||||
};
|
||||
history.push(referal);
|
||||
}, [history, meta.id, referal]);
|
||||
|
||||
const handleSharePhoto = () => {
|
||||
setShareModal(true);
|
||||
setShareLink(meta.image);
|
||||
};
|
||||
const handleSharePhoto = useCallback(() => {
|
||||
setShareOpen(meta);
|
||||
}, [meta]);
|
||||
|
||||
if (!meta) return null;
|
||||
|
||||
return (
|
||||
<Paper className={modal ? classes.modal : classes.modalHide}>
|
||||
<ShareModal key={meta.id} {...meta} />
|
||||
<div className={shareModal ? classes.backgroundModal : undefined} />
|
||||
<Button onClick={_handleClose}>
|
||||
<ArrowBackIcon />
|
||||
</Button>
|
||||
<div
|
||||
className={classes.image}
|
||||
style={{ backgroundImage: `url(${meta.image})` }}
|
||||
/>
|
||||
<div className={classes.actionDiv}>
|
||||
<Button onClick={handleDeletePhoto}>
|
||||
<DeleteIcon fontSize='large' />
|
||||
<>
|
||||
<ShareModal referal={referal} meta={shareOpen} onClose={() => setShareOpen(null)} />
|
||||
<Paper className={classes.modal}>
|
||||
<div className={shareOpen ? classes.backgroundModal : null} />
|
||||
<Button onClick={_handleClose}>
|
||||
<ArrowBackIcon />
|
||||
</Button>
|
||||
<Button onClick={handleSharePhoto}>
|
||||
<ShareIcon fontSize='large' />
|
||||
</Button>
|
||||
</div>
|
||||
</Paper>
|
||||
<div
|
||||
className={classes.image}
|
||||
style={{ backgroundImage: `url(${meta.image})` }}
|
||||
/>
|
||||
<div className={classes.actionDiv}>
|
||||
<Button onClick={handleDeletePhoto}>
|
||||
<DeleteIcon fontSize='large' />
|
||||
</Button>
|
||||
<Button onClick={handleSharePhoto}>
|
||||
<ShareIcon fontSize='large' />
|
||||
</Button>
|
||||
</div>
|
||||
</Paper>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -1,46 +1,42 @@
|
||||
import React from 'react';
|
||||
import Modal from '../../../../ui/components/Modal';
|
||||
import { useShareLink } from '../../hooks/useShareLink';
|
||||
import { useShareModal } from '../../hooks/useShareModal';
|
||||
import { Button } from '@material-ui/core';
|
||||
import MessageIcon from '@material-ui/icons/Message';
|
||||
import { setClipboard } from '../../../../os/phone/hooks/useClipboard';
|
||||
import CloseIcon from '@material-ui/icons/Close';
|
||||
|
||||
import useStyles from './modal.styles';
|
||||
import { ICameraPhoto } from '../../hooks/usePhotos';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
export const ShareModal = (meta) => {
|
||||
interface IShareModalProps {
|
||||
meta: ICameraPhoto;
|
||||
referal: string;
|
||||
onClose(): void;
|
||||
}
|
||||
|
||||
export const ShareModal = ({ meta, onClose, referal }: IShareModalProps) => {
|
||||
const classes = useStyles();
|
||||
const { shareModal, setShareModal } = useShareModal();
|
||||
const { setShareLink } = useShareLink();
|
||||
|
||||
const _handleClose = () => {
|
||||
setShareModal(false);
|
||||
setShareLink(null);
|
||||
};
|
||||
const history = useHistory();
|
||||
|
||||
const handleCopyImage = () => {
|
||||
setClipboard(meta.image);
|
||||
history.push(referal);
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal visible={shareModal} handleClose={_handleClose}>
|
||||
<Modal visible={!!meta} handleClose={onClose}>
|
||||
<div className={classes.shareModal}>
|
||||
<Button
|
||||
style={{ position: 'absolute', right: 0, width: '10%' }}
|
||||
onClick={_handleClose}
|
||||
>
|
||||
<CloseIcon />
|
||||
</Button>
|
||||
<div className={classes.innerShareModal}>
|
||||
<h4 style={{ textAlign: 'center', marginTop: 20 }}>
|
||||
Where do you want to share the photo?
|
||||
</h4>
|
||||
<Button>{<MessageIcon />} Message</Button>
|
||||
<h4>Or just copy the image here:</h4>
|
||||
<Button onClick={handleCopyImage} variant='contained'>
|
||||
Copy image
|
||||
</Button>
|
||||
<>
|
||||
<h4 style={{ textAlign: 'center', marginTop: 20 }}>
|
||||
Where do you want to share the photo?
|
||||
</h4>
|
||||
<Button>{<MessageIcon />} Message</Button>
|
||||
<h4>Or just copy the image here:</h4>
|
||||
<Button onClick={handleCopyImage} variant='contained'>
|
||||
Copy image
|
||||
</Button>
|
||||
</>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
@@ -5,20 +5,4 @@ export const photoState = {
|
||||
key: 'galleryPhotos',
|
||||
default: null,
|
||||
}),
|
||||
modal: atom({
|
||||
key: 'photoModal',
|
||||
default: false,
|
||||
}),
|
||||
photoMeta: atom({
|
||||
key: 'photoMeta',
|
||||
default: null,
|
||||
}),
|
||||
shareModal: atom({
|
||||
key: 'phoneShareModal',
|
||||
default: false,
|
||||
}),
|
||||
shareLink: atom({
|
||||
key: 'photoShareLink',
|
||||
default: null,
|
||||
}),
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { photoState } from './state';
|
||||
|
||||
export const usePhotoMeta = () => {
|
||||
const [meta, setMeta] = useRecoilState(photoState.photoMeta);
|
||||
return { meta, setMeta };
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { photoState } from './state';
|
||||
|
||||
export const usePhotoModal = () => {
|
||||
const [modal, setModal] = useRecoilState(photoState.modal);
|
||||
return { modal, setModal };
|
||||
};
|
||||
@@ -1,13 +1,11 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { photoState } from './state';
|
||||
|
||||
interface IPhotos {
|
||||
image: string[];
|
||||
|
||||
map?: any;
|
||||
export interface ICameraPhoto {
|
||||
id: string;
|
||||
image: string;
|
||||
}
|
||||
|
||||
export const usePhotos = (): IPhotos | null => {
|
||||
const photos = useRecoilValue<IPhotos | null>(photoState.photos);
|
||||
return photos;
|
||||
export const usePhotos = (): ICameraPhoto[] | null => {
|
||||
return useRecoilValue<ICameraPhoto[] | null>(photoState.photos);
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { photoState } from './state';
|
||||
|
||||
export const useShareLink = () => {
|
||||
const [shareLink, setShareLink] = useRecoilState(photoState.shareLink);
|
||||
return { shareLink, setShareLink };
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { photoState } from './state';
|
||||
|
||||
interface ShareModalProps {
|
||||
shareModal: boolean;
|
||||
setShareModal: (show: boolean) => void;
|
||||
}
|
||||
|
||||
export const useShareModal = (): ShareModalProps => {
|
||||
const [ shareModal, setShareModal ] = useRecoilState(photoState.shareModal);
|
||||
return { shareModal, setShareModal }
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import List from '@material-ui/core/List';
|
||||
import ListItem from '@material-ui/core/ListItem';
|
||||
import Modal from '../../../ui/components/Modal';
|
||||
import { useModal } from '../hooks/useModal';
|
||||
import ClearIcon from '@material-ui/icons/Clear';
|
||||
import PersonIcon from '@material-ui/icons/Person';
|
||||
import PhoneIcon from '@material-ui/icons/Phone';
|
||||
import AccountCircleIcon from '@material-ui/icons/AccountCircle';
|
||||
@@ -41,9 +40,6 @@ export const AddContactModal = () => {
|
||||
|
||||
return (
|
||||
<Modal visible={showModal} handleClose={_handleClose}>
|
||||
<Button onClick={_handleClose} className={classes.clearButton}>
|
||||
<ClearIcon />
|
||||
</Button>
|
||||
<List style={{ marginTop: 30 }}>
|
||||
<ListItem>
|
||||
<PersonIcon className={classes.icons} />
|
||||
|
||||
@@ -1,25 +1,67 @@
|
||||
import './messages.css';
|
||||
import React from 'react';
|
||||
import { AppWrapper } from '../../../ui/components';
|
||||
import { AppTitle } from '../../../ui/components/AppTitle';
|
||||
import { AppContent } from '../../../ui/components/AppContent';
|
||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||
import AlertBar from './AlertBar';
|
||||
import { MessageModal } from './modal/MessageModal';
|
||||
import MessageGroupModal from './modal/MessageGroupModal';
|
||||
import NewMessageGroupButton from './buttons/NewMessageGroupButton';
|
||||
import MessagesList from './list/MessagesList';
|
||||
import './messages.css';
|
||||
import { Route, Switch } from 'react-router-dom';
|
||||
import { MessageModal } from './modal/MessageModal';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
|
||||
InjectDebugData([
|
||||
{
|
||||
app: 'MESSAGES',
|
||||
method: 'phone:fetchMessagesSuccess',
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
message: 'sup!',
|
||||
user_identifier: '1234',
|
||||
phone_number: '444-4444',
|
||||
display: 'kidz',
|
||||
avatar: null,
|
||||
isRead: true,
|
||||
isMine: false,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
app: 'MESSAGES',
|
||||
method: 'phone:fetchMessageGroupsSuccess',
|
||||
data: [
|
||||
{
|
||||
groupId: '2',
|
||||
groupDisplay: 'dev-chat',
|
||||
isGroupChat: true,
|
||||
avatar: null,
|
||||
label: null,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
export const MessagesApp = () => {
|
||||
const messages = useApp('MESSAGES');
|
||||
return (
|
||||
<AppWrapper id='messages-app'>
|
||||
<AppTitle app={messages} />
|
||||
<MessageModal />
|
||||
<MessageGroupModal />
|
||||
<AppContent>
|
||||
<MessagesList />
|
||||
<NewMessageGroupButton />
|
||||
<Switch>
|
||||
<Route
|
||||
exact
|
||||
path='/messages/conversations/:groupId'
|
||||
component={MessageModal}
|
||||
/>
|
||||
</Switch>
|
||||
<Switch>
|
||||
<Route path='/messages' component={MessagesList} />
|
||||
<Route exact path='/messages/new' component={MessageGroupModal} />
|
||||
</Switch>
|
||||
</AppContent>
|
||||
<AlertBar />
|
||||
</AppWrapper>
|
||||
|
||||
@@ -2,7 +2,6 @@ import React from 'react';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { Fab } from '@material-ui/core';
|
||||
import AddIcon from '@material-ui/icons/Add';
|
||||
import useModals from '../../hooks/useModals';
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
root: {
|
||||
@@ -12,15 +11,18 @@ const useStyles = makeStyles(() => ({
|
||||
},
|
||||
}));
|
||||
|
||||
export function NewMessageGroupButton() {
|
||||
const classes = useStyles();
|
||||
const { setShowNewMessageGroup } = useModals();
|
||||
interface INewMessageGroupButtonProps {
|
||||
onClick(): void;
|
||||
}
|
||||
|
||||
const handleClick = () => setShowNewMessageGroup(true);
|
||||
export function NewMessageGroupButton({
|
||||
onClick,
|
||||
}: INewMessageGroupButtonProps) {
|
||||
const classes = useStyles();
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<Fab color='primary' onClick={handleClick}>
|
||||
<Fab color='primary' onClick={onClick}>
|
||||
<AddIcon />
|
||||
</Fab>
|
||||
</div>
|
||||
|
||||
@@ -5,14 +5,13 @@ import useStyles from './form.styles';
|
||||
import SendIcon from '@material-ui/icons/Send';
|
||||
import ImageIcon from '@material-ui/icons/Image';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useImageModal } from '../../hooks/useImageModal';
|
||||
|
||||
interface IProps {
|
||||
onAddImageClick(): void;
|
||||
messageGroupId: string | undefined;
|
||||
}
|
||||
|
||||
const MessageInput = ({ messageGroupId }: IProps) => {
|
||||
const { setImageModal } = useImageModal();
|
||||
const MessageInput = ({ messageGroupId, onAddImageClick }: IProps) => {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const [message, setMessage] = useState('');
|
||||
@@ -29,10 +28,6 @@ const MessageInput = ({ messageGroupId }: IProps) => {
|
||||
}
|
||||
};
|
||||
|
||||
const openImageModal = () => {
|
||||
setImageModal(true);
|
||||
};
|
||||
|
||||
if (!messageGroupId) return null;
|
||||
|
||||
return (
|
||||
@@ -48,7 +43,7 @@ const MessageInput = ({ messageGroupId }: IProps) => {
|
||||
className: classes.messagesInput,
|
||||
}}
|
||||
/>
|
||||
<Button className={classes.sendButton} onClick={openImageModal}>
|
||||
<Button className={classes.sendButton} onClick={onAddImageClick}>
|
||||
<ImageIcon />
|
||||
</Button>
|
||||
<Button className={classes.sendButton} type='submit'>
|
||||
|
||||
@@ -3,13 +3,13 @@ import { useTranslation } from 'react-i18next';
|
||||
import { TextField, Button } from '@material-ui/core';
|
||||
|
||||
import useStyles from './form.styles';
|
||||
import useModals from '../../hooks/useModals';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
const NewMessageGroupForm = () => {
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const { t } = useTranslation();
|
||||
const { setShowNewMessageGroup } = useModals();
|
||||
const [participants, setParticipants] = useState('');
|
||||
const [label, setLabel] = useState('');
|
||||
|
||||
@@ -31,7 +31,7 @@ const NewMessageGroupForm = () => {
|
||||
label: isGroupChat && labelValue ? labelValue : null,
|
||||
});
|
||||
setParticipants('');
|
||||
setShowNewMessageGroup(false); // close modal after submission
|
||||
history.push('/messages');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { List } from '@material-ui/core';
|
||||
|
||||
import qs from 'qs';
|
||||
import { MessageGroup } from '../../../../common/typings/messages';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import useMessages from '../../hooks/useMessages';
|
||||
import useModals from '../../hooks/useModals';
|
||||
import MessageSearch from './MessageSearch';
|
||||
import MessageGroupItem from './MessageGroupItem';
|
||||
import useStyles from './list.styles';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import NewMessageGroupButton from '../buttons/NewMessageGroupButton';
|
||||
|
||||
const MessagesList = (): any => {
|
||||
const classes = useStyles();
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
const history = useHistory();
|
||||
|
||||
const { messageGroups } = useMessages();
|
||||
const { setActiveMessageGroup } = useModals();
|
||||
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
Nui.send('phone:fetchMessageGroups');
|
||||
@@ -22,8 +25,12 @@ const MessagesList = (): any => {
|
||||
if (!messageGroups) return null;
|
||||
|
||||
const handleClick = (messageGroup: MessageGroup) => () => {
|
||||
setActiveMessageGroup(messageGroup);
|
||||
Nui.send('phone:fetchMessages', { groupId: messageGroup.groupId });
|
||||
history.push(
|
||||
`/messages/conversations/${messageGroup.groupId}/?${qs.stringify(
|
||||
messageGroup
|
||||
)}`
|
||||
);
|
||||
};
|
||||
|
||||
const formattedSearch = searchValue.toLowerCase().trim();
|
||||
@@ -54,6 +61,7 @@ const MessagesList = (): any => {
|
||||
/>
|
||||
))}
|
||||
</List>
|
||||
<NewMessageGroupButton onClick={() => history.push('/messages/new')} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { Paper, Typography } from '@material-ui/core';
|
||||
|
||||
import { Message, MessageGroup } from '../../../../common/typings/messages';
|
||||
import MessageInput from '../form/MessageInput';
|
||||
import useStyles from './modal.styles';
|
||||
import { MessageImageModal } from './MessageImageModal';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
|
||||
interface IProps {
|
||||
activeMessageGroup: MessageGroup;
|
||||
@@ -15,6 +16,9 @@ export const CONVERSATION_ELEMENT_ID = 'message-modal-conversation';
|
||||
|
||||
const Conversation = ({ activeMessageGroup, messages }: IProps) => {
|
||||
const classes = useStyles();
|
||||
const [imageModalOpen, setImageModalOpen] = useState(false);
|
||||
const query = useQueryParams();
|
||||
const referalImage = query?.image || null;
|
||||
|
||||
const isImage = (url) => {
|
||||
return /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|png|jpeg|gif)/g.test(url);
|
||||
@@ -22,7 +26,12 @@ const Conversation = ({ activeMessageGroup, messages }: IProps) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<MessageImageModal messageGroupId={activeMessageGroup.groupId} />
|
||||
<MessageImageModal
|
||||
image={referalImage}
|
||||
onClose={() => setImageModalOpen(false)}
|
||||
isOpen={imageModalOpen}
|
||||
messageGroupId={activeMessageGroup.groupId}
|
||||
/>
|
||||
<div id={CONVERSATION_ELEMENT_ID} className={classes.messageList}>
|
||||
{messages.map((message) => (
|
||||
<div key={message.id} className={classes.messageContainer}>
|
||||
@@ -48,7 +57,10 @@ const Conversation = ({ activeMessageGroup, messages }: IProps) => {
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<MessageInput messageGroupId={activeMessageGroup.groupId} />
|
||||
<MessageInput
|
||||
messageGroupId={activeMessageGroup.groupId}
|
||||
onAddImageClick={() => setImageModalOpen(true)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -2,21 +2,18 @@ import React from 'react';
|
||||
import { Slide, Paper, Button } from '@material-ui/core';
|
||||
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||
import useStyles from './modal.styles';
|
||||
|
||||
import useModals from '../../hooks/useModals';
|
||||
import NewMessageGroupForm from '../form/NewMessageGroupForm';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
const MessageGroupModal = () => {
|
||||
const classes = useStyles();
|
||||
const { showNewMessageGroup, setShowNewMessageGroup } = useModals();
|
||||
const history = useHistory();
|
||||
|
||||
const handleClose = () => setShowNewMessageGroup(false);
|
||||
const handleClose = () => history.push('/messages');
|
||||
|
||||
return (
|
||||
<Slide direction='left' in={showNewMessageGroup}>
|
||||
<Paper
|
||||
className={showNewMessageGroup ? classes.modalRoot : classes.modalHide}
|
||||
>
|
||||
<Slide direction='left' in>
|
||||
<Paper className={classes.modalRoot}>
|
||||
<Button onClick={handleClose}>
|
||||
<ArrowBackIcon fontSize='large' />
|
||||
</Button>
|
||||
|
||||
@@ -1,55 +1,128 @@
|
||||
import { TextField, Button } from '@material-ui/core';
|
||||
import React, { useState } from 'react';
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import qs from 'qs';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import Modal from '../../../../ui/components/Modal';
|
||||
import { useImageModal } from '../../hooks/useImageModal';
|
||||
import CloseIcon from '@material-ui/icons/Close';
|
||||
import PhotoLibraryIcon from '@material-ui/icons/PhotoLibrary';
|
||||
import { Box, Button, TextField, Typography } from '@material-ui/core';
|
||||
import FileCopyIcon from '@material-ui/icons/FileCopy';
|
||||
import useStyles from './modal.styles';
|
||||
import { useHistory, useLocation } from 'react-router-dom';
|
||||
import { ContextMenu } from '../../../../ui/components/ContextMenu';
|
||||
import { deleteQueryFromLocation } from '../../../../common/utils/deleteQueryFromLocation';
|
||||
import { PictureResponsive } from '../../../../ui/components/PictureResponsive';
|
||||
|
||||
interface IProps {
|
||||
isOpen: boolean;
|
||||
messageGroupId: string | undefined;
|
||||
onClose(): void;
|
||||
image?: string;
|
||||
}
|
||||
|
||||
export const MessageImageModal = ({ messageGroupId }: IProps) => {
|
||||
export const MessageImageModal = ({
|
||||
isOpen,
|
||||
messageGroupId,
|
||||
onClose,
|
||||
image,
|
||||
}: IProps) => {
|
||||
const classes = useStyles();
|
||||
const { imageModal, setImageModal } = useImageModal();
|
||||
const history = useHistory();
|
||||
const { pathname, search } = useLocation();
|
||||
|
||||
const [message, setMessage] = useState('');
|
||||
const [pasteVisible, setPasteVisible] = useState(false);
|
||||
const [queryParamImagePreview, setQueryParamImagePreview] = useState(null);
|
||||
|
||||
const _handleClose = () => {
|
||||
setImageModal(false);
|
||||
};
|
||||
|
||||
const sendImageMessage = (event) => {
|
||||
if (event.key === 'Enter') {
|
||||
const sendImageMessage = useCallback(
|
||||
(m) => {
|
||||
Nui.send('phone:sendMessage', {
|
||||
groupId: messageGroupId,
|
||||
message,
|
||||
message: m,
|
||||
});
|
||||
setImageModal(false);
|
||||
onClose();
|
||||
},
|
||||
[messageGroupId, onClose]
|
||||
);
|
||||
|
||||
const sendFromQueryParam = useCallback(
|
||||
(image) => {
|
||||
setQueryParamImagePreview(null);
|
||||
sendImageMessage(image);
|
||||
|
||||
console.log('++++', { pathname, search });
|
||||
history.replace(deleteQueryFromLocation({ pathname, search }, 'image'));
|
||||
},
|
||||
[history, pathname, search, sendImageMessage]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!image) return;
|
||||
setQueryParamImagePreview(image);
|
||||
}, [image, sendFromQueryParam]);
|
||||
|
||||
const sendFromClipboard = (event) => {
|
||||
if (event.key === 'Enter') {
|
||||
sendImageMessage(message);
|
||||
}
|
||||
};
|
||||
|
||||
const menuOptions = useMemo(
|
||||
() => [
|
||||
{
|
||||
label: 'Paste from clipboard',
|
||||
icon: <FileCopyIcon />,
|
||||
onClick: () => setPasteVisible(true),
|
||||
},
|
||||
{
|
||||
label: 'Camera / Gallery',
|
||||
icon: <PhotoLibraryIcon />,
|
||||
onClick: () =>
|
||||
history.push(
|
||||
`/camera?${qs.stringify({
|
||||
referal: encodeURIComponent(pathname + search),
|
||||
})}`
|
||||
),
|
||||
},
|
||||
],
|
||||
[history, pathname, search]
|
||||
);
|
||||
|
||||
return (
|
||||
<Modal visible={imageModal} handleClose={_handleClose}>
|
||||
<div>
|
||||
<Button
|
||||
onClick={_handleClose}
|
||||
className={classes.imageModalCloseButton}
|
||||
>
|
||||
<CloseIcon />
|
||||
</Button>
|
||||
<TextField
|
||||
placeholder='A link to your image or gif'
|
||||
onChange={(e) => setMessage(e.target.value)}
|
||||
value={message}
|
||||
className={classes.input}
|
||||
inputProps={{
|
||||
className: classes.messagesInput,
|
||||
}}
|
||||
inputRef={(input) => input && input.focus()}
|
||||
onKeyPress={sendImageMessage}
|
||||
/>
|
||||
</div>
|
||||
</Modal>
|
||||
<>
|
||||
<ContextMenu open={isOpen} options={menuOptions} onClose={onClose} />
|
||||
<Modal
|
||||
visible={queryParamImagePreview}
|
||||
handleClose={() => setQueryParamImagePreview(null)}
|
||||
>
|
||||
<Box py={1}>
|
||||
<Typography paragraph>Do you want to share this image?</Typography>
|
||||
<PictureResponsive
|
||||
src={queryParamImagePreview}
|
||||
alt={'Share gallery image preview'}
|
||||
/>
|
||||
<Button
|
||||
fullWidth
|
||||
variant='contained'
|
||||
onClick={() => sendFromQueryParam(queryParamImagePreview)}
|
||||
>
|
||||
Share
|
||||
</Button>
|
||||
</Box>
|
||||
</Modal>
|
||||
<Modal visible={pasteVisible} handleClose={() => setPasteVisible(false)}>
|
||||
<div>
|
||||
<TextField
|
||||
placeholder='A link to your image or gif'
|
||||
onChange={(e) => setMessage(e.target.value)}
|
||||
value={message}
|
||||
className={classes.input}
|
||||
inputProps={{
|
||||
className: classes.messagesInput,
|
||||
}}
|
||||
inputRef={(input) => input && input.focus()}
|
||||
onKeyPress={sendFromClipboard}
|
||||
/>
|
||||
</div>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -4,10 +4,12 @@ import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||
|
||||
import useStyles from './modal.styles';
|
||||
import useMessages from '../../hooks/useMessages';
|
||||
import useModals from '../../hooks/useModals';
|
||||
import Conversation, { CONVERSATION_ELEMENT_ID } from './Conversation';
|
||||
import MessageSkeletonList from './MessageSkeletonList';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { MessageGroup } from '../../../../common/typings/messages';
|
||||
import { useHistory, useParams } from 'react-router-dom';
|
||||
|
||||
const LARGE_HEADER_CHARS = 30;
|
||||
const MAX_HEADER_CHARS = 80;
|
||||
@@ -16,27 +18,29 @@ const MESSAGES_REFRESH_RATE = 5000;
|
||||
|
||||
export const MessageModal = () => {
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const activeMessageGroup = useQueryParams<MessageGroup>();
|
||||
const { groupId } = useParams<{ groupId: string }>();
|
||||
const { messages, setMessages } = useMessages();
|
||||
const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
|
||||
const { activeMessageGroup, setActiveMessageGroup } = useModals();
|
||||
|
||||
const closeModal = () => {
|
||||
setActiveMessageGroup(null);
|
||||
history.push('/messages');
|
||||
setMessages(null);
|
||||
setMimimumLoadPassed(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeMessageGroup?.groupId) return;
|
||||
if (!groupId) return;
|
||||
|
||||
const timeout = window.setTimeout(() => {
|
||||
setMimimumLoadPassed(true);
|
||||
}, MINIMUM_LOAD_TIME);
|
||||
|
||||
const interval = window.setInterval(() => {
|
||||
if (!activeMessageGroup) return;
|
||||
if (!groupId) return;
|
||||
Nui.send('phone:fetchMessages', {
|
||||
groupId: activeMessageGroup.groupId,
|
||||
groupId,
|
||||
});
|
||||
}, MESSAGES_REFRESH_RATE);
|
||||
|
||||
@@ -44,7 +48,7 @@ export const MessageModal = () => {
|
||||
window.clearInterval(interval);
|
||||
window.clearTimeout(timeout);
|
||||
};
|
||||
}, [activeMessageGroup]);
|
||||
}, [groupId]);
|
||||
|
||||
useEffect(() => {
|
||||
// when we get a new message group we should scroll to the
|
||||
@@ -61,7 +65,6 @@ export const MessageModal = () => {
|
||||
// there isn't a quick flash of loading and immediately
|
||||
// another flash to the tweets screen.
|
||||
const hasLoaded = messages && minimumLoadPassed;
|
||||
const isOpen = activeMessageGroup !== null;
|
||||
|
||||
// don't allow too many characters, it takes too much room
|
||||
let header = activeMessageGroup ? activeMessageGroup.groupDisplay : '';
|
||||
@@ -77,8 +80,8 @@ export const MessageModal = () => {
|
||||
: classes.groupdisplay;
|
||||
|
||||
return (
|
||||
<Slide direction='left' in={isOpen}>
|
||||
<Paper className={isOpen ? classes.modalRoot : classes.modalHide}>
|
||||
<Slide direction='left' in={!!activeMessageGroup}>
|
||||
<Paper className={classes.modalRoot}>
|
||||
<Paper className={classes.topContainer}>
|
||||
<Button onClick={closeModal}>
|
||||
<ArrowBackIcon fontSize='large' />
|
||||
@@ -87,7 +90,7 @@ export const MessageModal = () => {
|
||||
{header}
|
||||
</Typography>
|
||||
</Paper>
|
||||
{messages && hasLoaded ? (
|
||||
{hasLoaded ? (
|
||||
<Conversation
|
||||
messages={messages}
|
||||
activeMessageGroup={activeMessageGroup}
|
||||
|
||||
@@ -71,11 +71,6 @@ const useStyles = makeStyles((theme) => ({
|
||||
height: '80%',
|
||||
maxHeight: '80%',
|
||||
},
|
||||
imageModalCloseButton: {
|
||||
position: 'absolute',
|
||||
right: 0,
|
||||
width: '10%',
|
||||
},
|
||||
}));
|
||||
|
||||
export default useStyles;
|
||||
@@ -1,7 +0,0 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { messageState } from './state';
|
||||
|
||||
export const useImageModal = () => {
|
||||
const [imageModal, setImageModal] = useRecoilState(messageState.imageModal);
|
||||
return { imageModal, setImageModal };
|
||||
};
|
||||
@@ -1,26 +0,0 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { MessageGroup } from '../../../common/typings/messages';
|
||||
import { messageState } from './state';
|
||||
|
||||
interface IUseModal {
|
||||
activeMessageGroup: MessageGroup | null;
|
||||
setActiveMessageGroup: (group: MessageGroup | null) => void;
|
||||
showNewMessageGroup: boolean;
|
||||
setShowNewMessageGroup: (value: boolean) => void;
|
||||
}
|
||||
|
||||
export default (): IUseModal => {
|
||||
const [
|
||||
activeMessageGroup,
|
||||
setActiveMessageGroup,
|
||||
] = useRecoilState<MessageGroup | null>(messageState.activeMessageGroup);
|
||||
const [showNewMessageGroup, setShowNewMessageGroup] = useRecoilState<boolean>(
|
||||
messageState.showNewMessageGroup
|
||||
);
|
||||
return {
|
||||
activeMessageGroup,
|
||||
setActiveMessageGroup,
|
||||
showNewMessageGroup,
|
||||
setShowNewMessageGroup,
|
||||
};
|
||||
};
|
||||
@@ -1,7 +1,5 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { Button } from '@material-ui/core';
|
||||
import CloseIcon from '@material-ui/icons/Close';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
@@ -32,12 +30,6 @@ const useStyles = makeStyles((theme) => ({
|
||||
margin: 5,
|
||||
marginTop: 20,
|
||||
},
|
||||
close: {
|
||||
position: 'absolute',
|
||||
top: '12px',
|
||||
right: '4px',
|
||||
zIndex: 2,
|
||||
},
|
||||
buttonsContainer: {
|
||||
paddingBottom: '8px',
|
||||
display: 'flex',
|
||||
@@ -160,9 +152,6 @@ export const AddTweetModal = () => {
|
||||
|
||||
return (
|
||||
<Modal visible={modalVisible} handleClose={_handleClose}>
|
||||
<Button className={classes.close} onClick={_handleClose}>
|
||||
<CloseIcon color='action' />
|
||||
</Button>
|
||||
<TweetMessage message={message} handleChange={handleMessageChange} />
|
||||
<ImagePrompt
|
||||
visible={showImagePrompt}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import qs, { ParsedQs } from 'qs';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
|
||||
/**
|
||||
* Parses all available query params in current location and returns as an object
|
||||
*
|
||||
* @return {T} Querystring object
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* const { id, title } = useQueryParams<{ id: string, title: string }>();
|
||||
*/
|
||||
export function useQueryParams<T = Record<string, string>>() {
|
||||
return qs.parse(useLocation().search, { ignoreQueryPrefix: true }) as T &
|
||||
Partial<ParsedQs>;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import qs from 'qs';
|
||||
import url from 'parse-url';
|
||||
|
||||
interface IRouterLocation {
|
||||
pathname: string;
|
||||
search: string;
|
||||
}
|
||||
|
||||
export const addQueryToLocation = (
|
||||
{ pathname = '', search = '' }: Record<string, unknown> & IRouterLocation,
|
||||
key = '',
|
||||
value = ''
|
||||
) => {
|
||||
const { query } = url(pathname + search);
|
||||
return `${pathname}?${qs.stringify({
|
||||
...query,
|
||||
[key]: value,
|
||||
})}`;
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
import qs from 'qs';
|
||||
import url from 'parse-url';
|
||||
|
||||
interface IRouterLocation {
|
||||
pathname: string;
|
||||
search: any;
|
||||
}
|
||||
|
||||
export const deleteQueryFromLocation = (
|
||||
location: Record<string, unknown> & IRouterLocation,
|
||||
key = ''
|
||||
) => {
|
||||
const { query } = url(location.pathname + location.search);
|
||||
return `${location.pathname}/?${qs.stringify({
|
||||
...query,
|
||||
[key]: undefined,
|
||||
})}`;
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import parseUrl from 'parse-url';
|
||||
|
||||
export const getLocationFromUrl = (url: String) => {
|
||||
const { pathname, search } = parseUrl(url);
|
||||
const searchStr = '?' + (search || '');
|
||||
return { pathname, search: searchStr };
|
||||
};
|
||||
@@ -59,6 +59,7 @@ const appsState = atom({
|
||||
backgroundColor: amber[700],
|
||||
color: common.white,
|
||||
path: '/messages',
|
||||
sharePath: '/messages/new',
|
||||
Route: () => <Route path='/messages' component={MessagesApp} />,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -18,7 +18,19 @@ const useStyles = makeStyles((theme) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
export const ContextMenu = ({ open, onClose, options }) => {
|
||||
interface IContextMenuProps {
|
||||
open: boolean;
|
||||
onClose(): void;
|
||||
options: Array<{
|
||||
onClick(e, option): void;
|
||||
label: string;
|
||||
selected?: boolean;
|
||||
icon?: React.ReactNode;
|
||||
key?: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
export const ContextMenu = ({ open, onClose, options }: IContextMenuProps) => {
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<Slide direction='up' in={open} mountOnEnter unmountOnExit>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import CloseIcon from '@material-ui/icons/Close';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { Paper } from '@material-ui/core';
|
||||
import { Button, Paper } from '@material-ui/core';
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
root: {
|
||||
padding: '24px',
|
||||
zIndex: 10,
|
||||
background: '#424242',
|
||||
marginTop: '15px',
|
||||
@@ -24,6 +26,12 @@ const useStyles = makeStyles(() => ({
|
||||
displayNone: {
|
||||
display: 'none',
|
||||
},
|
||||
imageModalCloseButton: {
|
||||
position: 'absolute',
|
||||
right: 0,
|
||||
top: 0,
|
||||
width: '10%',
|
||||
},
|
||||
}));
|
||||
|
||||
export const Modal = ({ children, visible, handleClose }) => {
|
||||
@@ -48,7 +56,12 @@ export const Modal = ({ children, visible, handleClose }) => {
|
||||
|
||||
return (
|
||||
<div className={showHideClassName}>
|
||||
<Paper className={classes.root}>{children}</Paper>
|
||||
<Paper className={classes.root}>
|
||||
<Button onClick={handleClose} className={classes.imageModalCloseButton}>
|
||||
<CloseIcon />
|
||||
</Button>
|
||||
{children}
|
||||
</Paper>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user