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
+21 -128

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 { useMarketplaceService } from './apps/marketplace/hooks/useMarketplaceService';
import { useBankService } from './apps/bank/hooks/useBankService'; import { useBankService } from './apps/bank/hooks/useBankService';
import { useMessagesService } from './apps/messages/hooks/useMessageService'; import { useMessagesService } from './apps/messages/hooks/useMessageService';
import { usePhotoService } from './apps/camera/hooks/usePhotoService';
import { isSettingsSchemaValid, useSettings } from './apps/settings/hooks/useSettings'; import { isSettingsSchemaValid, useSettings } from './apps/settings/hooks/useSettings';
import { useCallService } from './os/call/hooks/useCallService'; import { useCallService } from './os/call/hooks/useCallService';
import { useDialService } from './apps/dialer/hooks/useDialService'; import { useDialService } from './apps/dialer/hooks/useDialService';
+1 -22
View File
@@ -3,30 +3,10 @@ import { AppWrapper } from '../../../ui/components';
import { AppContent } from '../../../ui/components/AppContent'; import { AppContent } from '../../../ui/components/AppContent';
import { GalleryGrid } from './grid/GalleryGrid'; import { GalleryGrid } from './grid/GalleryGrid';
import { GalleryModal } from './modal/GalleryModal'; import { GalleryModal } from './modal/GalleryModal';
import InjectDebugData from '../../../os/debug/InjectDebugData';
import { Route, Switch } from 'react-router-dom'; import { Route, Switch } from 'react-router-dom';
import { PhotoEvents } from '../../../../../typings/photo';
import { LoadingSpinner } from '../../../ui/components/LoadingSpinner'; import { LoadingSpinner } from '../../../ui/components/LoadingSpinner';
InjectDebugData([ const CameraApp: React.FC = () => (
{
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"> <AppWrapper id="camera-app">
<AppContent> <AppContent>
<Switch> <Switch>
@@ -38,6 +18,5 @@ const CameraApp = () => {
</AppContent> </AppContent>
</AppWrapper> </AppWrapper>
); );
};
export default CameraApp; export default CameraApp;
@@ -1,7 +1,6 @@
import React from 'react'; 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 useStyles from './grid.styles';
import { useCamera } from '../../hooks/useCamera';
import AddIcon from '@material-ui/icons/Add'; import AddIcon from '@material-ui/icons/Add';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { useQueryParams } from '../../../../common/hooks/useQueryParams'; 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'; import { useCallback } from 'react';
export const usePhotoActions = () => { export const usePhotoActions = () => {
const [photos, setPhotos] = usePhotos(); const setPhotos = useSetPhotos();
const takePhoto = useCallback( const takePhoto = useCallback(
(photo) => { (photo) => {
@@ -18,49 +18,5 @@ export const usePhotoActions = () => {
[setPhotos], [setPhotos],
); );
return { return { takePhoto, deletePhoto };
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,
};*/
}; };
@@ -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);
};
+15 -20
View File
@@ -1,10 +1,10 @@
import { GalleryPhoto, PhotoEvents } from '../../typings/photo'; import { PhotoEvents } from '../../typings/photo';
import { Delay } from '../utils/fivem'; import { Delay } from '../utils/fivem';
import { sendCameraEvent, sendMessage } from '../utils/messages'; import { sendCameraEvent, sendMessage } from '../utils/messages';
import { PhoneEvents } from '../../typings/phone'; import { PhoneEvents } from '../../typings/phone';
import { ClUtils } from './client'; import { ClUtils } from './client';
import { animationService } from './animations/animation.controller'; 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'); const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none');
@@ -33,9 +33,7 @@ const displayHelperText = () => {
EndTextCommandDisplayHelp(0, true, false, -1); EndTextCommandDisplayHelp(0, true, false, -1);
}; };
RegisterNuiCallbackType(PhotoEvents.TAKE_PHOTO); RegisterNuiCB<void>(PhotoEvents.TAKE_PHOTO, async (_, cb) => {
on(`__cfx_nui:${PhotoEvents.TAKE_PHOTO}`, async (data: any, cb: Function) => {
/*cb();*/
await animationService.openCamera(); await animationService.openCamera();
emit('npwd:disableControlActions', false); emit('npwd:disableControlActions', false);
// Create Phone Prop // Create Phone Prop
@@ -56,9 +54,14 @@ on(`__cfx_nui:${PhotoEvents.TAKE_PHOTO}`, async (data: any, cb: Function) => {
frontCam = !frontCam; frontCam = !frontCam;
CellFrontCamActivate(frontCam); CellFrontCamActivate(frontCam);
} else if (IsControlJustPressed(1, 176)) { } else if (IsControlJustPressed(1, 176)) {
if (SCREENSHOT_BASIC_TOKEN !== 'none') {
const resp = await handleTakePicture(); const resp = await handleTakePicture();
cb(resp); 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)) { } else if (IsControlJustPressed(1, 177)) {
handleCameraExit(); handleCameraExit();
break; break;
@@ -79,11 +82,15 @@ const handleTakePicture = async () => {
CellCamActivate(false, false); CellCamActivate(false, false);
openPhoneTemp(); openPhoneTemp();
inCameraMode = false; inCameraMode = false;
ClearHelp(true);
return resp; return resp;
}; };
const handleCameraExit = () => { const handleCameraExit = async () => {
ClearHelp(true);
animationService.closeCamera();
emit('npwd:disableControlActions', true);
DestroyMobilePhone(); DestroyMobilePhone();
CellCamActivate(false, false); CellCamActivate(false, false);
openPhoneTemp(); openPhoneTemp();
@@ -91,10 +98,6 @@ const handleCameraExit = () => {
inCameraMode = false; inCameraMode = false;
}; };
onNet(PhotoEvents.SEND_PHOTOS, (photos: string[]) => {
sendCameraEvent(PhotoEvents.SEND_PHOTOS, photos);
});
const takePhoto = () => const takePhoto = () =>
new Promise((res, rej) => { new Promise((res, rej) => {
// Return and log error if screenshot basic token not found // Return and log error if screenshot basic token not found
@@ -113,7 +116,6 @@ const takePhoto = () =>
async (data: any) => { async (data: any) => {
try { try {
const imageLink = JSON.parse(data).data.link; const imageLink = JSON.parse(data).data.link;
const resp = await ClUtils.emitNetPromise(PhotoEvents.UPLOAD_PHOTO, imageLink); const resp = await ClUtils.emitNetPromise(PhotoEvents.UPLOAD_PHOTO, imageLink);
console.log('export shit', resp); console.log('export shit', resp);
res(resp); res(resp);
@@ -125,11 +127,4 @@ const takePhoto = () =>
}); });
RegisterNuiProxy(PhotoEvents.FETCH_PHOTOS); RegisterNuiProxy(PhotoEvents.FETCH_PHOTOS);
RegisterNuiProxy(PhotoEvents.DELETE_PHOTO);
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);
});
@@ -1,16 +1,8 @@
import { getSource } from '../utils/miscUtils';
import { GalleryPhoto, PhotoEvents } from '../../../typings/photo'; import { GalleryPhoto, PhotoEvents } from '../../../typings/photo';
import PhotoService from './photo.service'; import PhotoService from './photo.service';
import { photoLogger } from './photo.utils'; import { photoLogger } from './photo.utils';
import { onNetPromise } from '../utils/PromiseNetEvents/onNetPromise'; 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) => { onNetPromise<string, GalleryPhoto>(PhotoEvents.UPLOAD_PHOTO, (reqObj, resp) => {
PhotoService.handleUploadPhoto(reqObj, resp).catch((e) => { PhotoService.handleUploadPhoto(reqObj, resp).catch((e) => {
photoLogger.error( 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) => { onNetPromise<GalleryPhoto, void>(PhotoEvents.DELETE_PHOTO, (reqObj, resp) => {
PhotoService.handleDeletePhoto(reqObj, resp).catch((e) => { PhotoService.handleDeletePhoto(reqObj, resp).catch((e) => {
photoLogger.error( photoLogger.error(
@@ -44,10 +29,3 @@ onNetPromise<GalleryPhoto, void>(PhotoEvents.DELETE_PHOTO, (reqObj, resp) => {
resp({ status: 'error', errorMsg: 'INTERNAL_ERROR' }); 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 PlayerService from '../players/player.service';
import { GalleryPhoto, PhotoEvents } from '../../../typings/photo'; import { GalleryPhoto } from '../../../typings/photo';
import PhotoDB, { _PhotoDB } from './photo.db'; import PhotoDB, { _PhotoDB } from './photo.db';
import { photoLogger } from './photo.utils'; import { photoLogger } from './photo.utils';
import { PromiseEventResp, PromiseRequest } from '../utils/PromiseNetEvents/promise.types'; import { PromiseEventResp, PromiseRequest } from '../utils/PromiseNetEvents/promise.types';
-4
View File
@@ -6,11 +6,7 @@ export interface GalleryPhoto {
export enum PhotoEvents { export enum PhotoEvents {
TAKE_PHOTO = 'npwd:TakePhoto', TAKE_PHOTO = 'npwd:TakePhoto',
TAKE_PHOTO_SUCCESS = 'npwd:TakePhotoSuccess', TAKE_PHOTO_SUCCESS = 'npwd:TakePhotoSuccess',
TAKE_PHOTO_ERROR = 'npwd:TakePhotoError',
UPLOAD_PHOTO = 'npwd:UploadPhoto', UPLOAD_PHOTO = 'npwd:UploadPhoto',
UPLOAD_PHOTO_SUCCESS = 'npwd:UploadPhotoSuccess',
FETCH_PHOTOS = 'npwd:FetchPhotos', FETCH_PHOTOS = 'npwd:FetchPhotos',
SEND_PHOTOS = 'npwd:SendPhotos',
DELETE_PHOTO = 'npwd:deletePhoto', DELETE_PHOTO = 'npwd:deletePhoto',
DELETE_PHOTO_SUCCESS = 'npwd:deletePhotoSuccess',
} }