mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Feature / Add loading state to camera app (#200)
* (feat/camera-loading): Add loading state to camera app * Fix imports + Add timeout * Use actual function :D
This commit is contained in:
1 parent
e1e6e8440d
commit
b97cc4102d
10 files changed
+43
-36
No files matched your search
@@ -1,28 +1,21 @@
|
||||
import React from 'react';
|
||||
import { Box, Button } from '@material-ui/core';
|
||||
import { Box, Button, CircularProgress } from '@material-ui/core';
|
||||
import useStyles from './grid.styles';
|
||||
import { usePhotos } from '../../hooks/usePhotos';
|
||||
import { useCamera } from '../../hooks/useCamera';
|
||||
import AddIcon from '@material-ui/icons/Add';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { addQueryToLocation } from '../../../../common/utils/addQueryToLocation';
|
||||
import { getLocationFromUrl } from '../../../../common/utils/getLocationFromUrl';
|
||||
import { PhotoEvents } from '../../../../../../typings/photo';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
|
||||
export const GalleryGrid = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const query = useQueryParams();
|
||||
|
||||
const referal = query.referal ? decodeURIComponent(query.referal) : '/camera/image';
|
||||
|
||||
const photos = usePhotos();
|
||||
|
||||
const handleCamera = () => {
|
||||
Nui.send(PhotoEvents.TAKE_PHOTO, {});
|
||||
};
|
||||
const { photos, isLoading, takePhoto } = useCamera();
|
||||
|
||||
const handlePhotoOpen = (photo) => {
|
||||
history.push(addQueryToLocation(getLocationFromUrl(referal), 'image', photo.image));
|
||||
@@ -43,8 +36,13 @@ export const GalleryGrid = () => {
|
||||
<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
|
||||
disabled={isLoading}
|
||||
onClick={takePhoto}
|
||||
style={{ borderRadius: 0 }}
|
||||
className={classes.photo}
|
||||
>
|
||||
{isLoading ? <CircularProgress /> : <AddIcon fontSize="large" />}
|
||||
</Button>
|
||||
</Box>
|
||||
{photos.map((photo) => (
|
||||
|
||||
@@ -6,7 +6,7 @@ import DeleteIcon from '@material-ui/icons/Delete';
|
||||
import ShareIcon from '@material-ui/icons/Share';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { ICameraPhoto } from '../../hooks/usePhotos';
|
||||
import { ICameraPhoto } from '../../hooks/useCamera';
|
||||
import { ShareModal } from './ShareModal';
|
||||
import { PhotoEvents } from '../../../../../../typings/photo';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
|
||||
@@ -5,7 +5,7 @@ import MessageIcon from '@material-ui/icons/Message';
|
||||
import { setClipboard } from '../../../../os/phone/hooks/useClipboard';
|
||||
|
||||
import useStyles from './modal.styles';
|
||||
import { ICameraPhoto } from '../../hooks/usePhotos';
|
||||
import { ICameraPhoto } from '../../hooks/useCamera';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
interface IShareModalProps {
|
||||
|
||||
@@ -3,6 +3,6 @@ import { atom } from 'recoil';
|
||||
export const photoState = {
|
||||
photos: atom({
|
||||
key: 'galleryPhotos',
|
||||
default: null,
|
||||
default: [],
|
||||
}),
|
||||
};
|
||||
@@ -43,7 +43,7 @@ export const useCamera = (): IUseCamera => {
|
||||
[addAlert, t],
|
||||
);
|
||||
|
||||
const [takePhoto] = useNuiCallback<void, ICameraPhoto>(
|
||||
const [_takePhoto] = useNuiCallback<void, ICameraPhoto>(
|
||||
'CAMERA',
|
||||
PhotoEvents.TAKE_PHOTO,
|
||||
onPhotoSuccess,
|
||||
@@ -52,6 +52,11 @@ export const useCamera = (): IUseCamera => {
|
||||
|
||||
useNuiEvent('CAMERA', PhotoEvents.UPLOAD_PHOTO, () => setUploading(true));
|
||||
|
||||
const takePhoto = () => {
|
||||
// Timeout at 1 minute
|
||||
_takePhoto(undefined, { timeout: 60000 });
|
||||
};
|
||||
|
||||
return {
|
||||
photos,
|
||||
setPhotos,
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { photoState } from './state';
|
||||
|
||||
export interface ICameraPhoto {
|
||||
id: string;
|
||||
image: string;
|
||||
}
|
||||
|
||||
export const usePhotos = (): ICameraPhoto[] | null => {
|
||||
return useRecoilValue<ICameraPhoto[] | null>(photoState.photos);
|
||||
};
|
||||
@@ -62,6 +62,8 @@
|
||||
"APPS_SELLOUT": "Market",
|
||||
"APPS_CAMERA": "Camera",
|
||||
|
||||
"APPS_CAMERA_FAILED_TO_TAKE_PHOTO": "Photo could not be saved :(",
|
||||
|
||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
||||
"APPS_DIALER_CURRENT_CALL_TITLE": "Current Phone Call",
|
||||
"APPS_DIALER_CURRENT_CALL_WITH": "In call with {{ transmitter }}",
|
||||
@@ -221,6 +223,7 @@
|
||||
"APPS_MARKETPLACE_FORM_DESCRIPTION": "Description",
|
||||
|
||||
"GENERIC_CLICK_TO_REVEAL": "Click to reveal",
|
||||
"GENERIC_LOADING": "Loading...",
|
||||
"GENERIC_WAIT": "Please wait...",
|
||||
"GENERIC_SAVE": "Save",
|
||||
"GENERIC_UPDATE": "Update",
|
||||
|
||||
Reference in new issue
Block a user