From 059529e69da8fa6533203f14e11c8fd2af4b1871 Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Tue, 3 Jan 2023 23:46:13 -0500 Subject: [PATCH] fix safari clipboard bs --- client/src/components/dialogs/ExportRoute.tsx | 235 ++++++++++-------- 1 file changed, 131 insertions(+), 104 deletions(-) diff --git a/client/src/components/dialogs/ExportRoute.tsx b/client/src/components/dialogs/ExportRoute.tsx index a78f38af..b0011fde 100644 --- a/client/src/components/dialogs/ExportRoute.tsx +++ b/client/src/components/dialogs/ExportRoute.tsx @@ -10,6 +10,9 @@ import { ListItemText, ListSubheader, IconButton, + Box, + CircularProgress, + Typography, } from '@mui/material' import Grid2 from '@mui/material/Unstable_Grid2/Grid2' import ContentCopy from '@mui/icons-material/ContentCopy' @@ -30,6 +33,8 @@ interface Props { export default function ExportRoute({ open, setOpen, geojson }: Props) { const scannerType = useStatic((s) => s.scannerType) + + const [loading, setLoading] = React.useState(false) const [route, setRoute] = React.useState([]) const [stats, setStats] = React.useState<{ max: number @@ -86,9 +91,44 @@ export default function ExportRoute({ open, setOpen, geojson }: Props) { setRoute(newRoute) return '' } + + const getClipboard = async (inputRoute?: number[][]) => { + if (typeof ClipboardItem && navigator.clipboard.write) { + // Safari bs (also works for Chrome) + const text = new ClipboardItem({ + 'text/plain': (inputRoute + ? convert( + inputRoute, + scannerType === 'rdm' ? 'text' : 'altText', + false, + ) + : getRoutes(true) + ).then( + (input) => + new Blob([input], { + type: 'text/plain', + }), + ), + }) + navigator.clipboard.write([text]) + } else { + // Firefox + navigator.clipboard.writeText( + await (inputRoute + ? convert( + inputRoute, + scannerType === 'rdm' ? 'text' : 'altText', + false, + ) + : getRoutes(true)), + ) + } + } + useDeepCompareEffect(() => { if (open === 'route') { - getRoutes() + setLoading(true) + getRoutes().then(() => setLoading(false)) } }, [geojson, open]) @@ -96,115 +136,102 @@ export default function ExportRoute({ open, setOpen, geojson }: Props) { setOpen('')}> setOpen('')}>Export Route - - - - {route.map((feat, i) => { - return ( - - - - - - navigator.clipboard.writeText( - await convert( - feat, - scannerType === 'rdm' ? 'text' : 'altText', - false, - ), - ) - } - > - - + {loading ? ( + + + Loading + + ) : ( + + + + {route.map((feat, i) => { + return ( + + + + + getClipboard(feat)} + > + + + + [Geofence {i + 1}] - [Geofence {i + 1}] - - - {feat.map((point, j) => ( - - ))} - - ) - })} - - - - - acc + cur.length, 0)} - label="Count" - type="number" - fullWidth - disabled - /> - - - - - - + + {feat.map((point, j) => ( + + ))} + + ) + })} + - - + + + + + + + + + + + + + - + )} - +