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
+51 -34

No files matched your search

@@ -1,43 +1,49 @@
import React from 'react'
import Modal from '../../../../ui/components/Modal'
import React, { useRef, useState } from 'react';
import Modal from '../../../../ui/components/Modal';
import { useShareLink } from '../../hooks/useShareLink';
import { useShareModal } from '../../hooks/useShareModal'
import { useShareModal } from '../../hooks/useShareModal';
import { Button } from '@material-ui/core';
import MessageIcon from '@material-ui/icons/Message';
import { useHistory } from 'react-router-dom';
import { useModal } from '../../../twitter/hooks/useModal';
import { setClipboard } from '../../../../os/phone/hooks/useClipboard';
import CloseIcon from '@material-ui/icons/Close';
import useStyles from './modal.styles';
import Nui from '../../../../os/nui-events/utils/Nui';
export const ShareModal = (meta) => {
const classes = useStyles();
const { shareModal, setShareModal } = useShareModal();
const { shareLink, setShareLink } = useShareLink();
const { setModalVisible } = useModal();
const { setShareLink } = useShareLink();
let history = useHistory();
const _handleClose = () => {
setShareModal(false)
setShareLink(null)
}
setShareModal(false);
setShareLink(null);
};
const handleCopyImage = () => {
setClipboard(meta.image);
};
return (
<Modal visible={shareModal} handleClose={_handleClose}>
<div className={classes.shareModal}>
<Button style={{ position: 'absolute', right: 0, width: '10%' }} onClick={_handleClose}><CloseIcon /></Button>
<Button
style={{ position: 'absolute', right: 0, width: '10%' }}
onClick={_handleClose}
>
<CloseIcon />
</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 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>
<p>{meta.image}</p>
<Button onClick={handleCopyImage} variant='contained'>
Copy image
</Button>
</div>
</div>
</Modal>
)
}
);
};
+3 -3
View File
@@ -1,12 +1,12 @@
import { atom } from "recoil";
import { atom } from 'recoil';
export const phoneState = {
visibility: atom({
key: "phoneVisibility",
key: 'phoneVisibility',
default: false,
}),
phoneConfig: atom({
key: "phoneConfig",
key: 'phoneConfig',
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 { phoneState } from "./state";
import { useNuiEvent } from "../../nui-events/hooks/useNuiEvent";
import { usePhone } from "./usePhone";
import { useSetRecoilState } from 'recoil';
import { phoneState } from './state';
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
import { usePhone } from './usePhone';
export const usePhoneService = () => {
const setVisibility = useSetRecoilState(phoneState.visibility);
const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig);
useNuiEvent("PHONE", "setVisibility", setVisibility);
useNuiEvent("PHONE", "phoneConfig", setPhoneConfig);
useNuiEvent('PHONE', 'setVisibility', setVisibility);
useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig);
return usePhone();
};