initial commit for camera app

This commit is contained in:
Christopher committed 2020-12-04 23:09:20 +01:00
1 parent 580fb12e92
commit 5b85efedf1
13 files changed
+334

No files matched your search

@@ -0,0 +1,30 @@
import { Fab } from '@material-ui/core';
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';
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}
</AppContent>
</AppWrapper>
)
}
export default CameraApp;
@@ -0,0 +1,62 @@
import React from 'react'
import { Box, Button } from '@material-ui/core';
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 { useModal } from '../../../contacts/hooks/useModal';
//import { useHistory } from 'react-router-dom';
// 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) => {
const classes = useStyles()
const { setMeta } = usePhotoMeta();
const { setModal } = usePhotoModal();
//let history = useHistory();
const photos = usePhotos();
console.log(photos)
const handleCamera = () => {
Nui.send('phone:TakePhoto', {})
}
const handlePhotoOpen = (photo) => {
setModal(true)
setMeta(photo)
//history.push('/camera/image')
}
if(!photos) return (
<Box display="flex" flexWrap="wrap" alignContent="flex-start" className={classes.root}>
<Box>
<Button onClick={handleCamera} style={{ borderRadius: 0 }} className={classes.photo}>
<AddIcon fontSize="large"/>
</Button>
</Box>
</Box>
)
return (
<div>
<Box display="flex" flexWrap="wrap" alignContent="flex-start" className={classes.root}>
<Box>
<Button onClick={handleCamera} style={{ borderRadius: 0 }} className={classes.photo}>
<AddIcon fontSize="large"/>
</Button>
</Box>
{photos.map(photo => (
<Box onClick={() => handlePhotoOpen(photo)}>
<div style={{ backgroundImage: `url(${photo.image})` }} className={classes.photo} />
</Box>
))}
</Box>
</div>
)
}
@@ -0,0 +1,19 @@
import { makeStyles, Theme } from '@material-ui/core/styles';
const useStyles = makeStyles((theme: Theme) => ({
root: {
flexGrow: 1
},
photo: {
border: '1px inset #fff',
height: 129,
width: 129,
maxWidth: 150,
maxHeight: 150,
backgroundPosition: 'center',
backgroundRepeat: 'no-repeat',
backgroundSize: 'cover',
}
}))
export default useStyles;
@@ -0,0 +1,65 @@
import React from 'react'
import Modal from '../../../../ui/components/Modal';
import { usePhotoMeta } from '../../hooks/usePhotoMeta';
import { usePhotoModal } from '../../hooks/usePhotoModal';
import useStyles from './modal.styles';
import { useHistory } from 'react-router-dom';
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 { useImagePrompt } from '../../../twitter/hooks/useImagePrompt';
import { useShareModal } from '../../hooks/useShareModal';
import { ShareModal } from './ShareModal';
import { useShareLink } from '../../hooks/useShareLink';
export const GalleryModal = () => {
const { meta, setMeta } = usePhotoMeta();
const { modal, setModal } = usePhotoModal();
const classes = useStyles();
const { shareModal ,setShareModal } = useShareModal();
const { setShareLink } = useShareLink();
let history = useHistory();
const _handleClose = () => {
setModal(false)
setMeta(null);
//history.goBack();
}
const handleDeletePhoto = () => {
console.log(meta.id)
Nui.send('photo:deletePhoto', {
id: meta.id
})
setModal(false)
}
const handleSharePhoto = () => {
setShareModal(true)
setShareLink(meta.image)
}
if(!meta) return null;
return (
<Paper className={modal ? classes.modal : classes.modalHide}>
<ShareModal />
<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" />
</Button>
<Button onClick={handleSharePhoto}>
<ShareIcon fontSize="large" />
</Button>
</div>
</Paper>
)
}
@@ -0,0 +1,43 @@
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 TwitterIcon from '@material-ui/icons/Twitter';
import { useHistory } from 'react-router-dom';
import { useModal } from '../../../twitter/hooks/useModal';
import CloseIcon from '@material-ui/icons/Close';
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAd } from "@fortawesome/free-solid-svg-icons";
export const ShareModal = () => {
const { shareModal, setShareModal } = useShareModal();
const { shareLink, setShareLink } = useShareLink();
const { setModalVisible } = useModal();
let history = useHistory();
const _handleClose = () => {
setShareModal(false)
setShareLink(null)
}
return (
<Modal visible={shareModal} handleClose={_handleClose}>
<div style={{ marginBottom: 50 }}>
<Button style={{ position: 'absolute', right: 0, width: '10%' }} onClick={_handleClose}><CloseIcon /></Button>
<div style={{ marginTop: 40 }}>
<h4 style={{ textAlign: 'center', marginTop: 20 }}>Where do you want to share the photo?</h4>
<Button>
{<TwitterIcon />} Twitter
</Button>
<Button>
{<FontAwesomeIcon icon={faAd} fixedWidth size="2x"/>} Advert
</Button>
</div>
</div>
</Modal>
)
}
@@ -0,0 +1,39 @@
import { makeStyles, Theme } from '@material-ui/core/styles';
const useStyles = makeStyles((theme: Theme) => ({
backgroundModal: {
background: "black",
opacity: "0.6",
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
zIndex: 5,
},
modal: {
position: 'absolute',
height: '100%',
width: '100%',
},
modalHide: {
display: 'none'
},
image: {
width: 'auto',
height: 380,
maxWidth: 'auto',
maxHeight: 380,
backgroundPosition: 'center',
backgroundSize: 'cover',
backgroundRepeat: 'no-repeat',
marginTop: '4em'
},
actionDiv: {
marginTop: 15,
display: 'flex',
justifyContent: 'space-evenly'
}
}))
export default useStyles;
+24
View File
@@ -0,0 +1,24 @@
import { atom } from 'recoil';
export const photoState = {
photos: atom({
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
})
}
@@ -0,0 +1,7 @@
import { useRecoilState } from 'recoil';
import { photoState } from './state';
export const usePhotoMeta = () => {
const [meta, setMeta] = useRecoilState(photoState.photoMeta);
return { meta, setMeta};
}
@@ -0,0 +1,7 @@
import { useRecoilState } from 'recoil';
import { photoState } from './state';
export const usePhotoModal = () => {
const [modal, setModal] = useRecoilState(photoState.modal);
return { modal, setModal}
}
@@ -0,0 +1,10 @@
import { useSetRecoilState } from 'recoil';
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import { photoState } from './state';
import { usePhotos } from './usePhotos';
export const usePhotoService = () => {
const setPhotos = useSetRecoilState(photoState.photos);
useNuiEvent('CAMERA', 'setPhotos', setPhotos);
return usePhotos();
}
+14
View File
@@ -0,0 +1,14 @@
import { useRecoilValue } from 'recoil';
import { photoState } from './state';
interface IPhotos {
image: string[];
map?: any;
}
export const usePhotos = (): IPhotos | null => {
const photos = useRecoilValue<IPhotos | null>(photoState.photos);
return photos;
}
@@ -0,0 +1,7 @@
import { useRecoilState } from 'recoil';
import { photoState } from './state';
export const useShareLink = () => {
const [ shareLink, setShareLink ] = useRecoilState(photoState.shareLink);
return { shareLink, setShareLink }
}
@@ -0,0 +1,7 @@
import { useRecoilState } from 'recoil';
import { photoState } from './state';
export const useShareModal = () => {
const [ shareModal, setShareModal ] = useRecoilState(photoState.shareModal);
return { shareModal, setShareModal }
}