feat(phone/hooks): implemented clipboard

This commit is contained in:
Christopher committed 2020-12-11 20:42:03 +01:00
1 parent e13b064d73
commit 550eb8f38f
6 files changed
+50 -33

No files matched your search

@@ -1,43 +1,49 @@
import React from 'react' import React, { useRef, useState } from 'react';
import Modal from '../../../../ui/components/Modal' import Modal from '../../../../ui/components/Modal';
import { useShareLink } from '../../hooks/useShareLink'; import { useShareLink } from '../../hooks/useShareLink';
import { useShareModal } from '../../hooks/useShareModal' import { useShareModal } from '../../hooks/useShareModal';
import { Button } from '@material-ui/core'; import { Button } from '@material-ui/core';
import MessageIcon from '@material-ui/icons/Message'; import MessageIcon from '@material-ui/icons/Message';
import { useHistory } from 'react-router-dom'; import { setClipboard } from '../../../../os/phone/hooks/useClipboard';
import { useModal } from '../../../twitter/hooks/useModal';
import CloseIcon from '@material-ui/icons/Close'; import CloseIcon from '@material-ui/icons/Close';
import useStyles from './modal.styles'; import useStyles from './modal.styles';
import Nui from '../../../../os/nui-events/utils/Nui';
export const ShareModal = (meta) => { export const ShareModal = (meta) => {
const classes = useStyles(); const classes = useStyles();
const { shareModal, setShareModal } = useShareModal(); const { shareModal, setShareModal } = useShareModal();
const { shareLink, setShareLink } = useShareLink(); const { setShareLink } = useShareLink();
const { setModalVisible } = useModal();
let history = useHistory();
const _handleClose = () => { const _handleClose = () => {
setShareModal(false) setShareModal(false);
setShareLink(null) setShareLink(null);
} };
const handleCopyImage = () => {
setClipboard(meta.image);
};
return ( return (
<Modal visible={shareModal} handleClose={_handleClose}> <Modal visible={shareModal} handleClose={_handleClose}>
<div className={classes.shareModal}> <div className={classes.shareModal}>
<Button style={{ position: 'absolute', right: 0, width: '10%' }} onClick={_handleClose}><CloseIcon /></Button> <Button
<div className={classes.innerShareModal}> style={{ position: 'absolute', right: 0, width: '10%' }}
<h4 style={{ textAlign: 'center', marginTop: 20 }}>Where do you want to share the photo?</h4> onClick={_handleClose}
<Button> >
{<MessageIcon />} Message <CloseIcon />
</Button> </Button>
<div className={classes.innerShareModal}>
<h4 style={{ textAlign: 'center', marginTop: 20 }}>
Where do you want to share the photo?
</h4>
<Button>{<MessageIcon />} Message</Button>
<h4>Or just copy the image here:</h4> <h4>Or just copy the image here:</h4>
<p>{meta.image}</p> <Button onClick={handleCopyImage} variant='contained'>
Copy image
</Button>
</div> </div>
</div> </div>
</Modal> </Modal>
) );
} };
+3 -3
View File
@@ -1,12 +1,12 @@
import { atom } from "recoil"; import { atom } from 'recoil';
export const phoneState = { export const phoneState = {
visibility: atom({ visibility: atom({
key: "phoneVisibility", key: 'phoneVisibility',
default: false, default: false,
}), }),
phoneConfig: atom({ phoneConfig: atom({
key: "phoneConfig", key: 'phoneConfig',
default: undefined, default: undefined,
}), }),
}; };
+8
View File
@@ -0,0 +1,8 @@
export const setClipboard = (value: string) => {
const clipElem = document.createElement('input');
clipElem.value = value;
document.body.appendChild(clipElem);
clipElem.select();
document.execCommand('copy');
document.body.removeChild(clipElem);
};
+6 -6
View File
@@ -1,12 +1,12 @@
import { useSetRecoilState } from "recoil"; import { useSetRecoilState } from 'recoil';
import { phoneState } from "./state"; import { phoneState } from './state';
import { useNuiEvent } from "../../nui-events/hooks/useNuiEvent"; import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
import { usePhone } from "./usePhone"; import { usePhone } from './usePhone';
export const usePhoneService = () => { export const usePhoneService = () => {
const setVisibility = useSetRecoilState(phoneState.visibility); const setVisibility = useSetRecoilState(phoneState.visibility);
const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig); const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig);
useNuiEvent("PHONE", "setVisibility", setVisibility); useNuiEvent('PHONE', 'setVisibility', setVisibility);
useNuiEvent("PHONE", "phoneConfig", setPhoneConfig); useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig);
return usePhone(); return usePhone();
}; };
+1 -1
View File
@@ -207,7 +207,7 @@ async function carryingPhone(cb: any) {
function noPhone() { function noPhone() {
if (ESX === null) return; if (ESX === null) return;
ESX.ShowNotification("Oi Mate, No El Telephono"); ESX.ShowNotification("Oi Mate, No El Telephono", false, false, 1);
} }
function sendPhoneConfig() { function sendPhoneConfig() {
+4 -1
View File
@@ -90,5 +90,8 @@ export default {
CAMERA_FETCH_PHOTOS: 'phone:FetchPhotos', CAMERA_FETCH_PHOTOS: 'phone:FetchPhotos',
CAMERA_SEND_PHOTOS: 'phone:SendPhotos', CAMERA_SEND_PHOTOS: 'phone:SendPhotos',
CAMERA_DELETE_PHOTO: 'photo:deletePhoto', CAMERA_DELETE_PHOTO: 'photo:deletePhoto',
CAMERA_DELETE_PHOTO_SUCCESS: 'phone:deletePhotoSuccess' CAMERA_DELETE_PHOTO_SUCCESS: 'phone:deletePhotoSuccess',
// copy
PHONE_USE_CLIPBOARD: 'phone:useClipboard'
} }