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,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>
|
||||
|
||||
Reference in new issue
Block a user