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:
J Francisco Rader authored and GitHub committed 2021-04-10 16:19:25 -03:00
1 parent e1e6e8440d
commit b97cc4102d
10 files changed
+43 -36

No files matched your search

+14 -5
View File
@@ -1,4 +1,4 @@
import { PhotoEvents } from '../../typings/photo';
import { IPhoto, PhotoEvents } from '../../typings/photo';
import { Delay } from '../utils/fivem';
import { sendMessage, sendCameraEvent } from '../utils/messages';
const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none');
@@ -65,6 +65,7 @@ const handleTakePicture = async () => {
DestroyMobilePhone();
CellCamActivate(false, false);
openPhoneTemp();
sendCameraEvent(PhotoEvents.UPLOAD_PHOTO, true);
inCameraMode = false;
};
@@ -72,6 +73,7 @@ const handleCameraExit = () => {
DestroyMobilePhone();
CellCamActivate(false, false);
openPhoneTemp();
sendCameraEvent(PhotoEvents.TAKE_PHOTO_SUCCESS, false);
inCameraMode = false;
};
@@ -94,14 +96,21 @@ function takePhoto() {
},
},
(data: string) => {
const imageLink = JSON.parse(data).data.link;
emitNet(PhotoEvents.UPLOAD_PHOTO, imageLink);
try {
const imageLink = JSON.parse(data).data.link;
emitNet(PhotoEvents.UPLOAD_PHOTO, imageLink);
} catch (e) {
sendCameraEvent(PhotoEvents.TAKE_PHOTO_ERROR, 'APPS_CAMERA_FAILED_TO_TAKE_PHOTO');
}
},
);
}
onNet(PhotoEvents.UPLOAD_PHOTO_SUCCESS, () => {
emitNet(PhotoEvents.FETCH_PHOTOS);
onNet(PhotoEvents.UPLOAD_PHOTO_SUCCESS, (photo: IPhoto) => {
if (photo && photo.image) {
return sendCameraEvent(PhotoEvents.TAKE_PHOTO_SUCCESS, photo);
}
sendCameraEvent(PhotoEvents.TAKE_PHOTO_ERROR, 'APPS_CAMERA_FAILED_TO_TAKE_PHOTO');
});
// delete photo
+5 -4
View File
@@ -5,9 +5,10 @@ import { mainLogger } from './sv_logger';
const photoLogger = mainLogger.child({ module: 'photo' });
async function uploadPhoto(identifier: string, image: string) {
async function uploadPhoto(identifier: string, image: string): Promise<IPhoto> {
const query = 'INSERT INTO npwd_phone_gallery (identifier, image) VALUES (?, ?)';
await pool.query(query, [identifier, image]);
const [results] = (await pool.query(query, [identifier, image])) as any;
return { id: results.insertId, image };
}
async function getPhotosByIdentifier(identifier: string): Promise<IPhoto[]> {
@@ -25,8 +26,8 @@ onNet(PhotoEvents.UPLOAD_PHOTO, async (image: string) => {
const _source = getSource();
try {
const identifier = getIdentifier(_source);
await uploadPhoto(identifier, image);
emitNet(PhotoEvents.UPLOAD_PHOTO_SUCCESS, _source);
const photo = await uploadPhoto(identifier, image);
emitNet(PhotoEvents.UPLOAD_PHOTO_SUCCESS, _source, photo);
} catch (e) {
photoLogger.error(`Failed to upload photo, ${e.message}`, {
source: _source,