Fix sharing bug

This commit is contained in:
J Francisco Rader committed 2021-02-06 17:18:44 -05:00
1 parent ecd826dcd3
commit 1db4dafa2d
2 files changed
+38 -13

No files matched your search

@@ -1,6 +1,8 @@
import React from 'react';
import React, { useMemo } from 'react';
import { useCalculator, CalcButton } from '../hooks/useCalculator';
import { Grid, makeStyles, Box, Paper } from '@material-ui/core';
import { Grid, makeStyles, Box, Paper, Fab } from '@material-ui/core';
import { setClipboard } from '../../../os/phone/hooks/useClipboard';
import FileCopyIcon from '@material-ui/icons/FileCopy';
const useStyles = makeStyles((theme) => ({
button: {
@@ -12,6 +14,12 @@ const useStyles = makeStyles((theme) => ({
textAlign: 'right',
overflow: 'hidden',
textOverflow: 'ellipsis',
position: 'relative',
},
copyFab: {
position: 'absolute',
top: '16px',
left: '16px',
},
}));
@@ -38,13 +46,22 @@ export const Calculator = ({ ...props }) => {
nine,
} = useCalculator();
const classes = useStyles();
const resultStr = useMemo(
() =>
result().toLocaleString(undefined, {
minimumFractionDigits: 0,
maximumFractionDigits: 4,
}),
[result]
);
return (
<Box display='flex' flexDirection='column'>
<Box flexGrow={1} component={Paper} p={4} className={classes.result}>
{result().toLocaleString(undefined, {
minimumFractionDigits: 0,
maximumFractionDigits: 4,
})}
<Fab size="small" onClick={() => setClipboard(resultStr)} className={classes.copyFab}>
<FileCopyIcon />
</Fab>
{resultStr}
</Box>
<Box>
<Grid container justify='space-around'>
@@ -1,6 +1,7 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import qs from 'qs';
import Nui from '../../../../os/nui-events/utils/Nui';
import CloseIcon from '@material-ui/icons/Close';
import Modal from '../../../../ui/components/Modal';
import PhotoLibraryIcon from '@material-ui/icons/PhotoLibrary';
import { Box, Button, TextField, Typography } from '@material-ui/core';
@@ -32,6 +33,11 @@ export const MessageImageModal = ({
const [pasteVisible, setPasteVisible] = useState(false);
const [queryParamImagePreview, setQueryParamImagePreview] = useState(null);
const removeQueryParamImage = useCallback(() => {
setQueryParamImagePreview(null);
history.replace(deleteQueryFromLocation({ pathname, search }, 'image'));
}, [history, pathname, search]);
const sendImageMessage = useCallback(
(m) => {
Nui.send('phone:sendMessage', {
@@ -45,13 +51,10 @@ export const MessageImageModal = ({
const sendFromQueryParam = useCallback(
(image) => {
setQueryParamImagePreview(null);
sendImageMessage(image);
console.log('++++', { pathname, search });
history.replace(deleteQueryFromLocation({ pathname, search }, 'image'));
removeQueryParamImage();
},
[history, pathname, search, sendImageMessage]
[removeQueryParamImage, sendImageMessage]
);
useEffect(() => {
@@ -82,8 +85,13 @@ export const MessageImageModal = ({
})}`
),
},
{
label: 'Cancel',
icon: <CloseIcon />,
onClick: onClose,
},
],
[history, pathname, search]
[onClose, history, pathname, search]
);
return (
@@ -91,7 +99,7 @@ export const MessageImageModal = ({
<ContextMenu open={isOpen} options={menuOptions} onClose={onClose} />
<Modal
visible={queryParamImagePreview}
handleClose={() => setQueryParamImagePreview(null)}
handleClose={removeQueryParamImage}
>
<Box py={1}>
<Typography paragraph>Do you want to share this image?</Typography>