mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +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
@@ -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>
|
||||
</>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user