diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx
index 9788a4c..98b4428 100644
--- a/phone/src/Phone.tsx
+++ b/phone/src/Phone.tsx
@@ -22,9 +22,31 @@ import { useSelloutService } from "./apps/sellout/hooks/useSelloutService";
import { useBankService } from './apps/bank/hooks/useBankService';
import { useMessagesService } from "./apps/messages/hooks/useMessageService";
import { useNotesService } from "./apps/notes/hooks/useNotesService";
+import { usePhotoService } from "./apps/camera/hooks/usePhotoService";
import Nui from "./os/nui-events/utils/Nui";
//These events are just for testing. Comment it out before building.
+setTimeout(() => {
+ window.dispatchEvent(
+ new MessageEvent("message", {
+ data: {
+ app: "CAMERA",
+ method: "setPhotos",
+ data: [
+ {
+ id: 1,
+ image: 'https://i.imgur.com/OO8wx6Z.jpg',
+ },
+ {
+ id: 1,
+ image: 'https://i.imgur.com/pqGBiST.jpg'
+ }
+ ],
+ },
+ })
+ );
+}, 1000);
+
setTimeout(() => {
window.dispatchEvent(
new MessageEvent("message", {
@@ -37,6 +59,8 @@ setTimeout(() => {
);
}, 1000);
+
+
setTimeout(() => {
window.dispatchEvent(
new MessageEvent("message", {
@@ -162,37 +186,6 @@ setTimeout(() => {
)
}, 1000)
-setTimeout(() => {
- window.dispatchEvent(
- new MessageEvent("message", {
- data: {
- app: "CONTACTS",
- method: "setContacts",
- data: [
- {
- id: 1,
- number: "345-4366",
- display: "chip",
- avatar: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/200px-Rotating_earth_%28large%29.gif'
- },
- {
- id: 2,
- number: "456-4366",
- display: "shit",
- avatar: ''
- },
- {
- id: 3,
- number: "123-4366",
- display: "rocky",
- avatar: 'https://i.imgur.com/B8ta5Aa.jpeg'
- },
- ],
- },
- })
- );
-}, 1000);
-
setTimeout(() => {
window.dispatchEvent(
new MessageEvent("message", {
@@ -236,6 +229,7 @@ function Phone() {
useBankService();
useMessagesService()
useNotesService();
+ usePhotoService();
if (visibility === false) {
return null;
diff --git a/phone/src/apps/camera/components/CameraApp.tsx b/phone/src/apps/camera/components/CameraApp.tsx
new file mode 100644
index 0000000..404313c
--- /dev/null
+++ b/phone/src/apps/camera/components/CameraApp.tsx
@@ -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 (
+
+
+
+ {/*
+
+
+
+
+ */}
+ {!modal ? : null}
+
+
+ )
+}
+
+export default CameraApp;
diff --git a/phone/src/apps/camera/components/grid/GalleryGrid.tsx b/phone/src/apps/camera/components/grid/GalleryGrid.tsx
new file mode 100644
index 0000000..9a3ead6
--- /dev/null
+++ b/phone/src/apps/camera/components/grid/GalleryGrid.tsx
@@ -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 (
+
+
+
+
+
+ )
+
+ return (
+
+
+
+
+
+ {photos.map(photo => (
+ handlePhotoOpen(photo)}>
+
+
+ ))}
+
+
+ )
+}
diff --git a/phone/src/apps/camera/components/grid/grid.styles.ts b/phone/src/apps/camera/components/grid/grid.styles.ts
new file mode 100644
index 0000000..5e7008b
--- /dev/null
+++ b/phone/src/apps/camera/components/grid/grid.styles.ts
@@ -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;
\ No newline at end of file
diff --git a/phone/src/apps/camera/components/modal/GalleryModal.tsx b/phone/src/apps/camera/components/modal/GalleryModal.tsx
new file mode 100644
index 0000000..10ea82d
--- /dev/null
+++ b/phone/src/apps/camera/components/modal/GalleryModal.tsx
@@ -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 (
+
+
+
+
+
+
+
+
+
+
+ )
+}
diff --git a/phone/src/apps/camera/components/modal/ShareModal.tsx b/phone/src/apps/camera/components/modal/ShareModal.tsx
new file mode 100644
index 0000000..1d7d024
--- /dev/null
+++ b/phone/src/apps/camera/components/modal/ShareModal.tsx
@@ -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 (
+
+
+
+
+
Where do you want to share the photo?
+
+
+
+
+
+ )
+}
diff --git a/phone/src/apps/camera/components/modal/modal.styles.ts b/phone/src/apps/camera/components/modal/modal.styles.ts
new file mode 100644
index 0000000..c16478e
--- /dev/null
+++ b/phone/src/apps/camera/components/modal/modal.styles.ts
@@ -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;
\ No newline at end of file
diff --git a/phone/src/apps/camera/hooks/state.ts b/phone/src/apps/camera/hooks/state.ts
new file mode 100644
index 0000000..d098ba4
--- /dev/null
+++ b/phone/src/apps/camera/hooks/state.ts
@@ -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
+ })
+}
\ No newline at end of file
diff --git a/phone/src/apps/camera/hooks/usePhotoMeta.ts b/phone/src/apps/camera/hooks/usePhotoMeta.ts
new file mode 100644
index 0000000..5c31a5c
--- /dev/null
+++ b/phone/src/apps/camera/hooks/usePhotoMeta.ts
@@ -0,0 +1,7 @@
+import { useRecoilState } from 'recoil';
+import { photoState } from './state';
+
+export const usePhotoMeta = () => {
+ const [meta, setMeta] = useRecoilState(photoState.photoMeta);
+ return { meta, setMeta};
+}
\ No newline at end of file
diff --git a/phone/src/apps/camera/hooks/usePhotoModal.ts b/phone/src/apps/camera/hooks/usePhotoModal.ts
new file mode 100644
index 0000000..39aafe2
--- /dev/null
+++ b/phone/src/apps/camera/hooks/usePhotoModal.ts
@@ -0,0 +1,7 @@
+import { useRecoilState } from 'recoil';
+import { photoState } from './state';
+
+export const usePhotoModal = () => {
+ const [modal, setModal] = useRecoilState(photoState.modal);
+ return { modal, setModal}
+}
\ No newline at end of file
diff --git a/phone/src/apps/camera/hooks/usePhotoService.ts b/phone/src/apps/camera/hooks/usePhotoService.ts
new file mode 100644
index 0000000..b080ff2
--- /dev/null
+++ b/phone/src/apps/camera/hooks/usePhotoService.ts
@@ -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();
+}
\ No newline at end of file
diff --git a/phone/src/apps/camera/hooks/usePhotos.ts b/phone/src/apps/camera/hooks/usePhotos.ts
new file mode 100644
index 0000000..1c4d781
--- /dev/null
+++ b/phone/src/apps/camera/hooks/usePhotos.ts
@@ -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(photoState.photos);
+ return photos;
+}
\ No newline at end of file
diff --git a/phone/src/apps/camera/hooks/useShareLink.ts b/phone/src/apps/camera/hooks/useShareLink.ts
new file mode 100644
index 0000000..ecb1b9b
--- /dev/null
+++ b/phone/src/apps/camera/hooks/useShareLink.ts
@@ -0,0 +1,7 @@
+import { useRecoilState } from 'recoil';
+import { photoState } from './state';
+
+export const useShareLink = () => {
+ const [ shareLink, setShareLink ] = useRecoilState(photoState.shareLink);
+ return { shareLink, setShareLink }
+}
\ No newline at end of file
diff --git a/phone/src/apps/camera/hooks/useShareModal.ts b/phone/src/apps/camera/hooks/useShareModal.ts
new file mode 100644
index 0000000..66dfec1
--- /dev/null
+++ b/phone/src/apps/camera/hooks/useShareModal.ts
@@ -0,0 +1,7 @@
+import { useRecoilState } from 'recoil';
+import { photoState } from './state';
+
+export const useShareModal = () => {
+ const [ shareModal, setShareModal ] = useRecoilState(photoState.shareModal);
+ return { shareModal, setShareModal }
+}
\ No newline at end of file
diff --git a/phone/src/apps/sellout/hooks/state.ts b/phone/src/apps/sellout/hooks/state.ts
index 46d6a3e..3f1c4f9 100644
--- a/phone/src/apps/sellout/hooks/state.ts
+++ b/phone/src/apps/sellout/hooks/state.ts
@@ -4,5 +4,5 @@ export const selloutState = {
listing: atom({
key: "listing",
default: [],
- }),
+ })
};
diff --git a/phone/src/apps/twitter/hooks/state.ts b/phone/src/apps/twitter/hooks/state.ts
index 6349459..053e463 100644
--- a/phone/src/apps/twitter/hooks/state.ts
+++ b/phone/src/apps/twitter/hooks/state.ts
@@ -40,5 +40,5 @@ export const twitterState = {
notification: atom({
key: "notification",
default: null,
- }),
+ })
};
diff --git a/phone/src/common/interfaces/photo.ts b/phone/src/common/interfaces/photo.ts
new file mode 100644
index 0000000..48e0ad3
--- /dev/null
+++ b/phone/src/common/interfaces/photo.ts
@@ -0,0 +1,4 @@
+export interface IPhoto {
+ image: string;
+ id: number
+}
\ No newline at end of file
diff --git a/phone/src/os/apps/hooks/useApps.tsx b/phone/src/os/apps/hooks/useApps.tsx
index 40b4d25..58afc58 100644
--- a/phone/src/os/apps/hooks/useApps.tsx
+++ b/phone/src/os/apps/hooks/useApps.tsx
@@ -16,7 +16,7 @@ import {
faPlaneArrival,
faPhoneAlt,
faWonSign,
- faStickyNote
+ faStickyNote,
} from "@fortawesome/free-solid-svg-icons";
import { faTwitter } from "@fortawesome/free-brands-svg-icons";
@@ -25,6 +25,7 @@ import SettingsIcon from "@material-ui/icons/Settings";
import MessageIcon from "@material-ui/icons/Message";
import { atom } from "recoil";
import { CalculatorIcon } from "../../../apps/calculator/components/CalculatorIcon";
+import CameraAltIcon from '@material-ui/icons/CameraAlt';
import { Route } from "react-router-dom";
import { DialerApp } from "../../../apps/dialer/components/DialerApp";
import { ContactsApp } from "../../../apps/contacts/components/ContactsApp";
@@ -36,6 +37,7 @@ import { TwitterApp } from "../../../apps/twitter/components/TwitterApp";
import { ExampleApp } from "../../../apps/example/components/ExampleApp";
import { SelloutApp } from "../../../apps/sellout/components/SelloutApp";
import { NotesApp } from "../../../apps/notes/NotesApp";
+import CameraApp from "../../../apps/camera/components/CameraApp";
const appsState = atom({
key: "apps",
@@ -122,6 +124,15 @@ const appsState = atom({
path: "/notes",
Route: () =>
},
+ {
+ id: "CAMERA",
+ name: 'APPS_CAMERA',
+ icon: ,
+ backgroundColor: grey['A400'],
+ color: common.white,
+ path: "/camera",
+ Route: () =>
+ },
{
id: "EXAMPLE",
nameLocale: "APPS_EXAMPLE",
diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts
index dfe2942..55bf52c 100644
--- a/resources/client/cl_main.ts
+++ b/resources/client/cl_main.ts
@@ -226,6 +226,25 @@ setTick(() => {
}
});
+
+// setTick(() => {
+// if (isPhoneOpen) {
+// DisableControlAction(0, 1, true)
+// DisableControlAction(0, 2, true)
+// DisableControlAction(0, 24, true)
+// DisableControlAction(0, 257, true)
+// DisableControlAction(0, 25, true)
+// DisableControlAction(0, 263, true)
+// } else {
+// EnableControlAction(0, 1, true)
+// EnableControlAction(0, 2, true)
+// EnableControlAction(0, 24, true)
+// EnableControlAction(0, 257, true)
+// EnableControlAction(0, 25, true)
+// EnableControlAction(0, 263, true)
+// }
+// })
+
async function Phone() {
if (config.PhoneAsItem) {
console.log("CONFIG ON");
@@ -247,6 +266,8 @@ async function Phone() {
);
sendPhoneConfig();
SetNuiFocus(true, true);
+ //SetNuiFocusKeepInput(true)
+
} else {
isPhoneOpen = false;
SendNuiMessage(
@@ -258,6 +279,8 @@ async function Phone() {
})
);
SetNuiFocus(false, false);
+ //SetNuiFocusKeepInput(false)
+
await phoneCloseAnim(); // Animation starts after the UI is closed.
}
} else {
@@ -282,6 +305,8 @@ async function Phone() {
);
sendPhoneConfig();
SetNuiFocus(true, true);
+ //SetNuiFocusKeepInput(true)
+
} else {
isPhoneOpen = false;
SendNuiMessage(
@@ -293,6 +318,8 @@ async function Phone() {
})
);
SetNuiFocus(false, false);
+ //SetNuiFocusKeepInput(false)
+
await phoneCloseAnim(); // Animation starts after the UI is closed.
}
}
@@ -322,6 +349,11 @@ on(`__cfx_nui:${events.OPEN_APP_BANK}`, () => {
emitNet(events.BANK_GET_CREDENTIALS);
})
+RegisterNuiCallbackType(events.OPEN_APP_CAMERA);
+on(`__cfx_nui:${events.OPEN_APP_CAMERA}`, () => {
+ emitNet(events.CAMERA_FETCH_PHOTOS);
+})
+
RegisterCommand(
"phone",
() => {
@@ -367,25 +399,25 @@ function countPhone(cb: any) {
let destroyedPhone = false;
-setTick(async () => {
- while (config.SwimDestroy) {
- await Delay(config.RunRate * 1000);
- if (IsPedSwimming(PlayerPedId())) {
- let chance = Math.floor(Math.random() * 100 + 1);
- if (chance <= config.DestoryChance) {
- countPhone((countPhone: boolean) => {
- if (countPhone) {
- ESX.ShowNotification("Your phone is ruined from the water!");
- destroyedPhone = true;
- }
- });
- }
- if (destroyedPhone) {
- await Delay(config.DestroyPhoneReCheck * 60000);
- }
- }
- }
-});
+// setTick(async () => {
+// while (config.SwimDestroy) {
+// await Delay(config.RunRate * 1000);
+// if (IsPedSwimming(PlayerPedId())) {
+// let chance = Math.floor(Math.random() * 100 + 1);
+// if (chance <= config.DestoryChance) {
+// countPhone((countPhone: boolean) => {
+// if (countPhone) {
+// ESX.ShowNotification("Your phone is ruined from the water!");
+// destroyedPhone = true;
+// }
+// });
+// }
+// if (destroyedPhone) {
+// await Delay(config.DestroyPhoneReCheck * 60000);
+// }
+// }
+// }
+// });
onNet("phone:sendCredentials", (number: string) => {
SendNuiMessage(
diff --git a/resources/client/cl_photo.ts b/resources/client/cl_photo.ts
new file mode 100644
index 0000000..7a02ca5
--- /dev/null
+++ b/resources/client/cl_photo.ts
@@ -0,0 +1,143 @@
+import events from "../utils/events";
+import { Delay } from "../utils/fivem";
+import { tokenData } from '../utils/token';
+
+const exp = (global as any).exports
+
+function closePhoneTemp() {
+ SendNuiMessage(
+ //Hides phone
+ JSON.stringify({
+ app: "PHONE",
+ method: "setVisibility",
+ data: false,
+ })
+ );
+}
+
+function openPhoneTemp() {
+ SendNuiMessage(
+ //Opens phone
+ JSON.stringify({
+ app: "PHONE",
+ method: "setVisibility",
+ data: true,
+ })
+ );
+}
+
+
+let takingPhoto = false
+
+function CellFrontCamActivate(activate: any) {
+ return Citizen.invokeNative('0x2491A93618B7D838', activate)
+}
+
+RegisterNuiCallbackType(events.CAMERA_TAKE_PHOTO);
+on(`__cfx_nui:${events.CAMERA_TAKE_PHOTO}`, async () => {
+ CreateMobilePhone(1);
+ CellCamActivate(true, true);
+
+ closePhoneTemp()
+ SetNuiFocus(false, false);
+
+ takingPhoto = true;
+
+ while (takingPhoto) {
+ await Delay(0);
+ let frontCam = false;
+
+ if (IsControlJustPressed(1, 27)) {
+ if (!frontCam) {
+ frontCam = true;
+ CellFrontCamActivate(true);
+ } else {
+ frontCam = false;
+ CellFrontCamActivate(false);
+ }
+
+ } else if (IsControlJustPressed(1, 176)) {
+ takePhoto()
+ await Delay(200)
+ console.log("phone closing")
+ DestroyMobilePhone();
+ CellCamActivate(false, false);
+
+ openPhoneTemp()
+ SetNuiFocus(true, true);
+
+ takingPhoto = false;
+
+ } else if (IsControlJustPressed(1, 177)) {
+ DestroyMobilePhone();
+ CellCamActivate(false, false);
+
+ openPhoneTemp()
+ SetNuiFocus(true, true);
+
+ takingPhoto = false;
+ break;
+ }
+ }
+});
+
+//setTick(async () => {
+// while (takingPhoto) {
+// await Delay(0);
+//
+// if (IsControlReleased(1, 177)) {
+// DestroyMobilePhone();
+// CellCamActivate(false, false);
+// takingPhoto = false;
+// SetNuiFocus(true, true);
+// break;
+// }
+// }
+//})
+
+
+
+onNet(events.CAMERA_SEND_PHOTOS, (photos: string[]) => {
+ console.log(photos)
+ SendNuiMessage(
+ JSON.stringify({
+ app: "CAMERA",
+ method: "setPhotos",
+ data: photos
+ })
+ )
+})
+
+
+function takePhoto() {
+ const [width, height] = GetActiveScreenResolution();
+ console.log("photo taken")
+ exp["screenshot-basic"].requestScreenshotUpload(
+ "https://api.imgur.com/3/image",
+ "imgur",
+ {
+ headers: {
+ 'authorization': `Client-ID ${ tokenData.token }`,
+ 'content-type': 'multipart/form-data'
+ }
+ },
+ (data: string) => {
+ console.log("herrrrroooooooo")
+ const imageLink = JSON.parse(data).data.link;
+ emitNet(events.CAMERA_UPLOAD_PHOTO, imageLink)
+ }
+ );
+}
+
+
+// delete photo
+
+RegisterNuiCallbackType(events.CAMERA_DELETE_PHOTO);
+on(`__cfx_nui:${events.CAMERA_DELETE_PHOTO}`, (data: any) => {
+ emitNet(events.CAMERA_DELETE_PHOTO, data)
+})
+
+onNet(events.CAMERA_DELETE_PHOTO_SUCCESS, () => {
+ emitNet(events.CAMERA_FETCH_PHOTOS)
+})
+
diff --git a/resources/client/client.ts b/resources/client/client.ts
index e119803..065ef80 100644
--- a/resources/client/client.ts
+++ b/resources/client/client.ts
@@ -5,6 +5,7 @@ import './cl_contacts';
import './cl_sellout';
import './cl_bank';
import './cl_notes';
+import './cl_photo';
import './cl_messages';
export let ESX: ESXClient = null;
diff --git a/resources/server/server.ts b/resources/server/server.ts
index 92c120a..dde0be2 100644
--- a/resources/server/server.ts
+++ b/resources/server/server.ts
@@ -7,6 +7,7 @@ import './sv_contacts';
import './sv_sellout';
import './sv_bank';
import './sv_notes';
+import './sv_photo';
import './sv_messages';
export let ESX: ESXServer = null;
diff --git a/resources/server/sv_photo.ts b/resources/server/sv_photo.ts
new file mode 100644
index 0000000..a910ee4
--- /dev/null
+++ b/resources/server/sv_photo.ts
@@ -0,0 +1,44 @@
+import events from '../utils/events';
+import { ESX, getSource } from './server';
+import { pool } from './db';
+import { useIdentifier } from './functions';
+import { IPhoto } from '../../phone/src/common/interfaces/photo';
+
+async function uploadPhoto(identifier: string, image: string) {
+ const query = 'INSERT INTO npwd_phone_gallery (identifier, image) VALUES (?, ?)';
+ await pool.query(query, [identifier, image])
+}
+
+async function getPhotosByIdentifier(identifier: string): Promise {
+ const query = "SELECT id, image FROM npwd_phone_gallery WHERE identifier = ? ORDER BY id DESC";
+ const [ results ] = await pool.query(query, [identifier]);
+ const photos = results;
+ return photos;
+}
+
+async function deletePhoto(photo: IPhoto, identifier: string) {
+ const query = "DELETE FROM npwd_phone_gallery WHERE id = ? AND identifier = ?";
+ await pool.query(query, [photo.id, identifier])
+ console.log(photo.id)
+}
+
+onNet(events.CAMERA_UPLOAD_PHOTO, async (image: string) => {
+ const identifier = await useIdentifier()
+ await uploadPhoto(identifier, image)
+})
+
+onNet(events.CAMERA_FETCH_PHOTOS, async () => {
+ const identifier = await useIdentifier();
+ const photos = await getPhotosByIdentifier(identifier)
+ emitNet(events.CAMERA_SEND_PHOTOS, getSource(), photos)
+})
+
+onNet(events.CAMERA_DELETE_PHOTO, async (photo: IPhoto) => {
+ try {
+ const identifier = await useIdentifier()
+ await deletePhoto(photo, identifier)
+ emitNet(events.CAMERA_DELETE_PHOTO_SUCCESS, getSource())
+ } catch (error) {
+ console.log(error)
+ }
+})
\ No newline at end of file
diff --git a/resources/utils/events.ts b/resources/utils/events.ts
index eff022e..af74ccd 100644
--- a/resources/utils/events.ts
+++ b/resources/utils/events.ts
@@ -81,6 +81,14 @@ export default {
OPEN_APP_CONTACTS: 'phone:app:CONTACTS',
OPEN_APP_BANK: 'phone:app:BANK',
OPEN_APP_NOTES: 'phone:app:NOTES',
- OPEN_APP_LISTINGS: 'phone:app:SELLOUT'
+ OPEN_APP_LISTINGS: 'phone:app:SELLOUT',
+ OPEN_APP_CAMERA: 'phone:app:CAMERA',
+ // camera
+ CAMERA_TAKE_PHOTO: 'phone:TakePhoto',
+ CAMERA_UPLOAD_PHOTO: 'phone:UploadPhoto',
+ CAMERA_FETCH_PHOTOS: 'phone:FetchPhotos',
+ CAMERA_SEND_PHOTOS: 'phone:SendPhotos',
+ CAMERA_DELETE_PHOTO: 'photo:deletePhoto',
+ CAMERA_DELETE_PHOTO_SUCCESS: 'phone:deletePhotoSuccess'
}