cleanup(photos): A general cleanup of photos

Removes legacy code no longer in use or cleans up code to use new type safe native wrappers
This commit is contained in:
Taso committed 2021-07-27 22:39:18 -04:00
1 parent 83ec915926
commit 16626db5bd
9 files changed
+34 -141

No files matched your search

-1
View File
@@ -15,7 +15,6 @@ import { useMatchService } from './apps/match/hooks/useMatchService';
import { useMarketplaceService } from './apps/marketplace/hooks/useMarketplaceService';
import { useBankService } from './apps/bank/hooks/useBankService';
import { useMessagesService } from './apps/messages/hooks/useMessageService';
import { usePhotoService } from './apps/camera/hooks/usePhotoService';
import { isSettingsSchemaValid, useSettings } from './apps/settings/hooks/useSettings';
import { useCallService } from './os/call/hooks/useCallService';
import { useDialService } from './apps/dialer/hooks/useDialService';
+12 -33
View File
@@ -3,41 +3,20 @@ import { AppWrapper } from '../../../ui/components';
import { AppContent } from '../../../ui/components/AppContent';
import { GalleryGrid } from './grid/GalleryGrid';
import { GalleryModal } from './modal/GalleryModal';
import InjectDebugData from '../../../os/debug/InjectDebugData';
import { Route, Switch } from 'react-router-dom';
import { PhotoEvents } from '../../../../../typings/photo';
import { LoadingSpinner } from '../../../ui/components/LoadingSpinner';
InjectDebugData([
{
app: 'CAMERA',
method: PhotoEvents.SEND_PHOTOS,
data: [
{
id: 1,
image: 'https://i.file.glass/noDcb.jpeg',
},
{
id: 2,
image: 'https://i.file.glass/teUcY.jpeg',
},
],
},
]);
const CameraApp = () => {
return (
<AppWrapper id="camera-app">
<AppContent>
<Switch>
<React.Suspense fallback={<LoadingSpinner />}>
<Route path="/camera" exact component={GalleryGrid} />
<Route path="/camera/image" exact component={GalleryModal} />
</React.Suspense>
</Switch>
</AppContent>
</AppWrapper>
);
};
const CameraApp: React.FC = () => (
<AppWrapper id="camera-app">
<AppContent>
<Switch>
<React.Suspense fallback={<LoadingSpinner />}>
<Route path="/camera" exact component={GalleryGrid} />
<Route path="/camera/image" exact component={GalleryModal} />
</React.Suspense>
</Switch>
</AppContent>
</AppWrapper>
);
export default CameraApp;
@@ -1,7 +1,6 @@
import React from 'react';
import { Box, Button, CircularProgress } from '@material-ui/core';
import { Box, Button } from '@material-ui/core';
import useStyles from './grid.styles';
import { useCamera } from '../../hooks/useCamera';
import AddIcon from '@material-ui/icons/Add';
import { useHistory } from 'react-router-dom';
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
+3 -47
View File
@@ -1,8 +1,8 @@
import { usePhotos } from './state';
import { useSetPhotos } from './state';
import { useCallback } from 'react';
export const usePhotoActions = () => {
const [photos, setPhotos] = usePhotos();
const setPhotos = useSetPhotos();
const takePhoto = useCallback(
(photo) => {
@@ -18,49 +18,5 @@ export const usePhotoActions = () => {
[setPhotos],
);
return {
takePhoto,
deletePhoto,
};
/*const { t } = useTranslation();
const { addAlert } = useSnackbar();
const [photos, setPhotos] = usePhotoService();
const [isUploading, setUploading] = useState(false);*/
/*
const onPhotoSuccess = useCallback(
(photo) => {
setUploading(false);
if (!photo?.image) return;
setPhotos((curr) => [photo, ...curr]);
},
[setPhotos],
);
const onPhotoError = useCallback(
(i18nKey) => {
setUploading(false);
addAlert({ type: 'error', message: t(i18nKey) });
},
[addAlert, t],
);
const [_takePhoto] = useNuiCallback<void, GalleryPhoto>(
'CAMERA',
PhotoEvents.TAKE_PHOTO,
onPhotoSuccess,
onPhotoError,
);
const takePhoto = () => {
_takePhoto(undefined, { timeout: 60000 });
};
return {
photos,
setPhotos,
takePhoto,
isLoading: isUploading,
};*/
return { takePhoto, deletePhoto };
};
@@ -1,9 +0,0 @@
import { useSetRecoilState } from 'recoil';
import { useNuiEvent } from 'fivem-nui-react-lib';
import { photoState } from './state';
import { PhotoEvents } from '../../../../../typings/photo';
export const usePhotoService = () => {
const setPhotos = useSetRecoilState(photoState.photos);
useNuiEvent('CAMERA', PhotoEvents.SEND_PHOTOS, setPhotos);
};
+17 -22
View File
@@ -1,10 +1,10 @@
import { GalleryPhoto, PhotoEvents } from '../../typings/photo';
import { PhotoEvents } from '../../typings/photo';
import { Delay } from '../utils/fivem';
import { sendCameraEvent, sendMessage } from '../utils/messages';
import { PhoneEvents } from '../../typings/phone';
import { ClUtils } from './client';
import { animationService } from './animations/animation.controller';
import { RegisterNuiProxy } from './cl_utils';
import { RegisterNuiCB, RegisterNuiProxy } from './cl_utils';
const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none');
@@ -33,9 +33,7 @@ const displayHelperText = () => {
EndTextCommandDisplayHelp(0, true, false, -1);
};
RegisterNuiCallbackType(PhotoEvents.TAKE_PHOTO);
on(`__cfx_nui:${PhotoEvents.TAKE_PHOTO}`, async (data: any, cb: Function) => {
/*cb();*/
RegisterNuiCB<void>(PhotoEvents.TAKE_PHOTO, async (_, cb) => {
await animationService.openCamera();
emit('npwd:disableControlActions', false);
// Create Phone Prop
@@ -56,9 +54,14 @@ on(`__cfx_nui:${PhotoEvents.TAKE_PHOTO}`, async (data: any, cb: Function) => {
frontCam = !frontCam;
CellFrontCamActivate(frontCam);
} else if (IsControlJustPressed(1, 176)) {
const resp = await handleTakePicture();
cb(resp);
if (SCREENSHOT_BASIC_TOKEN !== 'none') {
const resp = await handleTakePicture();
cb(resp);
break;
}
console.error(
'You may be trying to take a photo, but your token is not setup for upload! See NPWD Docs for more info!',
);
} else if (IsControlJustPressed(1, 177)) {
handleCameraExit();
break;
@@ -79,11 +82,15 @@ const handleTakePicture = async () => {
CellCamActivate(false, false);
openPhoneTemp();
inCameraMode = false;
ClearHelp(true);
return resp;
};
const handleCameraExit = () => {
const handleCameraExit = async () => {
ClearHelp(true);
animationService.closeCamera();
emit('npwd:disableControlActions', true);
DestroyMobilePhone();
CellCamActivate(false, false);
openPhoneTemp();
@@ -91,10 +98,6 @@ const handleCameraExit = () => {
inCameraMode = false;
};
onNet(PhotoEvents.SEND_PHOTOS, (photos: string[]) => {
sendCameraEvent(PhotoEvents.SEND_PHOTOS, photos);
});
const takePhoto = () =>
new Promise((res, rej) => {
// Return and log error if screenshot basic token not found
@@ -113,7 +116,6 @@ const takePhoto = () =>
async (data: any) => {
try {
const imageLink = JSON.parse(data).data.link;
const resp = await ClUtils.emitNetPromise(PhotoEvents.UPLOAD_PHOTO, imageLink);
console.log('export shit', resp);
res(resp);
@@ -125,11 +127,4 @@ const takePhoto = () =>
});
RegisterNuiProxy(PhotoEvents.FETCH_PHOTOS);
RegisterNuiCallbackType(PhotoEvents.DELETE_PHOTO);
on(`__cfx_nui:${PhotoEvents.DELETE_PHOTO}`, async (data: GalleryPhoto, cb: Function) => {
console.log('my data', data);
/*emitNet(PhotoEvents.DELETE_PHOTO, data);*/
const resp = await ClUtils.emitNetPromise(PhotoEvents.DELETE_PHOTO, data);
cb(resp);
});
RegisterNuiProxy(PhotoEvents.DELETE_PHOTO);
@@ -1,16 +1,8 @@
import { getSource } from '../utils/miscUtils';
import { GalleryPhoto, PhotoEvents } from '../../../typings/photo';
import PhotoService from './photo.service';
import { photoLogger } from './photo.utils';
import { onNetPromise } from '../utils/PromiseNetEvents/onNetPromise';
/*onNet(PhotoEvents.UPLOAD_PHOTO, async (image: string) => {
const src = getSource();
PhotoService.handleUploadPhoto(src, image).catch((e) =>
photoLogger.error(`Error occurred in upload photo event (${src}), Error: ${e.message}`),
);
});*/
onNetPromise<string, GalleryPhoto>(PhotoEvents.UPLOAD_PHOTO, (reqObj, resp) => {
PhotoService.handleUploadPhoto(reqObj, resp).catch((e) => {
photoLogger.error(
@@ -29,13 +21,6 @@ onNetPromise<void, GalleryPhoto[]>(PhotoEvents.FETCH_PHOTOS, (reqObj, resp) => {
});
});
/*onNet(PhotoEvents.FETCH_PHOTOS, async () => {
const src = getSource();
PhotoService.handleFetchPhotos(src).catch((e) =>
photoLogger.error(`Error occurred in upload photo event (${src}), Error: ${e.message}`),
);
});*/
onNetPromise<GalleryPhoto, void>(PhotoEvents.DELETE_PHOTO, (reqObj, resp) => {
PhotoService.handleDeletePhoto(reqObj, resp).catch((e) => {
photoLogger.error(
@@ -44,10 +29,3 @@ onNetPromise<GalleryPhoto, void>(PhotoEvents.DELETE_PHOTO, (reqObj, resp) => {
resp({ status: 'error', errorMsg: 'INTERNAL_ERROR' });
});
});
/*onNet(PhotoEvents.DELETE_PHOTO, async (photo: GalleryPhoto) => {
const src = getSource();
PhotoService.handleDeletePhoto(src, photo).catch((e) =>
photoLogger.error(`Error occurred in delete photo event (${src}), Error: ${e.message}`),
);
});*/
+1 -1
View File
@@ -1,5 +1,5 @@
import PlayerService from '../players/player.service';
import { GalleryPhoto, PhotoEvents } from '../../../typings/photo';
import { GalleryPhoto } from '../../../typings/photo';
import PhotoDB, { _PhotoDB } from './photo.db';
import { photoLogger } from './photo.utils';
import { PromiseEventResp, PromiseRequest } from '../utils/PromiseNetEvents/promise.types';
-4
View File
@@ -6,11 +6,7 @@ export interface GalleryPhoto {
export enum PhotoEvents {
TAKE_PHOTO = 'npwd:TakePhoto',
TAKE_PHOTO_SUCCESS = 'npwd:TakePhotoSuccess',
TAKE_PHOTO_ERROR = 'npwd:TakePhotoError',
UPLOAD_PHOTO = 'npwd:UploadPhoto',
UPLOAD_PHOTO_SUCCESS = 'npwd:UploadPhotoSuccess',
FETCH_PHOTOS = 'npwd:FetchPhotos',
SEND_PHOTOS = 'npwd:SendPhotos',
DELETE_PHOTO = 'npwd:deletePhoto',
DELETE_PHOTO_SUCCESS = 'npwd:deletePhotoSuccess',
}