From c2456708eb78dcfd8af84399139ee007fd18508f Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 4 Dec 2020 23:03:52 +0100 Subject: [PATCH 01/12] feat(events): events for camera app --- resources/utils/events.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/resources/utils/events.ts b/resources/utils/events.ts index 7403739..374b4e1 100644 --- a/resources/utils/events.ts +++ b/resources/utils/events.ts @@ -67,6 +67,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' } From 96e5f1a46dce318a84f1e6507f7c92078284fa33 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 4 Dec 2020 23:04:10 +0100 Subject: [PATCH 02/12] mock data --- phone/src/Phone.tsx | 56 ++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index b6bc26c..cea2e3c 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -21,8 +21,30 @@ import { useTwitterService } from "./apps/twitter/hooks/useTwitterService"; import { useSelloutService } from "./apps/sellout/hooks/useSelloutService"; import { useBankService } from './apps/bank/hooks/useBankService'; import { useNotesService } from "./apps/notes/hooks/useNotesService"; +import { usePhotoService } from "./apps/camera/hooks/usePhotoService"; //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", { @@ -35,6 +57,8 @@ setTimeout(() => { ); }, 1000); + + setTimeout(() => { window.dispatchEvent( new MessageEvent("message", { @@ -160,37 +184,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", { @@ -233,6 +226,7 @@ function Phone() { useSelloutService(); useBankService(); useNotesService(); + usePhotoService(); if (visibility === false) { return null; From 17be6511474ddca5359d35723533b023ac984f88 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 4 Dec 2020 23:04:46 +0100 Subject: [PATCH 03/12] removed a share link test --- phone/src/apps/sellout/hooks/state.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: [], - }), + }) }; From c8fc6a0245d3ae996dfe8e34f4acd5385e1456b9 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 4 Dec 2020 23:05:25 +0100 Subject: [PATCH 04/12] feat(phone/apps): useApps camera app --- phone/src/os/apps/hooks/useApps.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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", From d671ece127a1bc4b40dcb4d3b49f80d01be0fbd6 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 4 Dec 2020 23:06:01 +0100 Subject: [PATCH 05/12] removed a share link test --- phone/src/apps/twitter/hooks/state.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, - }), + }) }; From f7ffd461ac1bc410cf8288e266f6507adcd487f3 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 4 Dec 2020 23:06:56 +0100 Subject: [PATCH 06/12] feat(phone/client): fetch photos when opening camera app --- resources/client/cl_main.ts | 70 +++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 19 deletions(-) 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( From 5590f592f72496aa6018b83087766f2ae45300f0 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 4 Dec 2020 23:07:30 +0100 Subject: [PATCH 07/12] import files to clinet.ts --- resources/client/client.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/client/client.ts b/resources/client/client.ts index 10c3786..84acbd1 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'; export let ESX: ESXClient = null; From a341803547f04ae514cec3fe54f73dde6c0ca5ad Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 4 Dec 2020 23:07:42 +0100 Subject: [PATCH 08/12] import files to server.ts --- resources/server/server.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/server/server.ts b/resources/server/server.ts index a0640ab..f6c3a31 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'; export let ESX: ESXServer = null; From 580fb12e922b87ddd73678c12610757e87dd0d9a Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 4 Dec 2020 23:08:14 +0100 Subject: [PATCH 09/12] feat(interface): added common interface for photo --- phone/src/common/interfaces/photo.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 phone/src/common/interfaces/photo.ts 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 From 5b85efedf168fcf97f4a9b1820c521d6890246c1 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 4 Dec 2020 23:09:20 +0100 Subject: [PATCH 10/12] initial commit for camera app --- .../src/apps/camera/components/CameraApp.tsx | 30 +++++++++ .../camera/components/grid/GalleryGrid.tsx | 62 ++++++++++++++++++ .../camera/components/grid/grid.styles.ts | 19 ++++++ .../camera/components/modal/GalleryModal.tsx | 65 +++++++++++++++++++ .../camera/components/modal/ShareModal.tsx | 43 ++++++++++++ .../camera/components/modal/modal.styles.ts | 39 +++++++++++ phone/src/apps/camera/hooks/state.ts | 24 +++++++ phone/src/apps/camera/hooks/usePhotoMeta.ts | 7 ++ phone/src/apps/camera/hooks/usePhotoModal.ts | 7 ++ .../src/apps/camera/hooks/usePhotoService.ts | 10 +++ phone/src/apps/camera/hooks/usePhotos.ts | 14 ++++ phone/src/apps/camera/hooks/useShareLink.ts | 7 ++ phone/src/apps/camera/hooks/useShareModal.ts | 7 ++ 13 files changed, 334 insertions(+) create mode 100644 phone/src/apps/camera/components/CameraApp.tsx create mode 100644 phone/src/apps/camera/components/grid/GalleryGrid.tsx create mode 100644 phone/src/apps/camera/components/grid/grid.styles.ts create mode 100644 phone/src/apps/camera/components/modal/GalleryModal.tsx create mode 100644 phone/src/apps/camera/components/modal/ShareModal.tsx create mode 100644 phone/src/apps/camera/components/modal/modal.styles.ts create mode 100644 phone/src/apps/camera/hooks/state.ts create mode 100644 phone/src/apps/camera/hooks/usePhotoMeta.ts create mode 100644 phone/src/apps/camera/hooks/usePhotoModal.ts create mode 100644 phone/src/apps/camera/hooks/usePhotoService.ts create mode 100644 phone/src/apps/camera/hooks/usePhotos.ts create mode 100644 phone/src/apps/camera/hooks/useShareLink.ts create mode 100644 phone/src/apps/camera/hooks/useShareModal.ts 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 From 1116687d88553289263885c89f3cd9c8d124fb9c Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 4 Dec 2020 23:09:59 +0100 Subject: [PATCH 11/12] feat(photo/client): initial commit for client-side functionality --- resources/client/cl_photo.ts | 143 +++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 resources/client/cl_photo.ts 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) +}) + From f5cdebeaf76aed5ee6f5a66d8ee4b691fe117a6b Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 4 Dec 2020 23:10:15 +0100 Subject: [PATCH 12/12] feat(photo/client): initial commit for server-side functionality --- resources/server/sv_photo.ts | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 resources/server/sv_photo.ts 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