|
5 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | */ |
7 | 7 |
|
8 | | -import { type MouseEvent, type RefObject, useCallback, useEffect, useMemo, useState } from 'react'; |
| 8 | +import { type MouseEvent, type RefObject, useCallback, useMemo, useState } from 'react'; |
9 | 9 | import { Button, Menu, MenuItem } from '@mui/material'; |
10 | 10 | import { FormattedMessage } from 'react-intl'; |
11 | 11 | import SaveIcon from '@mui/icons-material/Save'; |
12 | 12 | import SaveSpreadsheetDialog from './save-spreadsheet-dialog'; |
13 | 13 | import { |
| 14 | + copytoClipboard, |
14 | 15 | CsvDownloadProps, |
15 | 16 | EquipmentType, |
16 | 17 | FILTER_EQUIPMENTS, |
17 | | - useClipboard, |
18 | 18 | useCsvExport, |
19 | 19 | useSnackMessage, |
20 | 20 | useStateBoolean, |
@@ -60,24 +60,21 @@ export default function SaveSpreadsheetButton({ |
60 | 60 | const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); |
61 | 61 | const customSaveDialogOpen = useStateBoolean(false); |
62 | 62 | const saveFilterDialogOpen = useStateBoolean(false); |
63 | | - const { downloadCSVData, getCSVData } = useCsvExport(); |
64 | 63 | const language = useSelector((state: AppState) => state.computedLanguage); |
65 | 64 |
|
66 | 65 | const handleClick = useCallback((event: MouseEvent<HTMLButtonElement>) => setAnchorEl(event.currentTarget), []); |
67 | 66 | const handleClose = useCallback(() => setAnchorEl(null), []); |
68 | 67 |
|
69 | 68 | const { snackInfo, snackError } = useSnackMessage(); |
70 | | - const clipboard = useClipboard(); |
| 69 | + const { downloadCSVData, getCSVData } = useCsvExport(); |
| 70 | + |
| 71 | + const onClipboardCopy = useCallback(() => { |
| 72 | + snackInfo({ headerId: 'spreadsheet/clipboard/success' }); |
| 73 | + }, [snackInfo]); |
71 | 74 |
|
72 | | - useEffect(() => { |
73 | | - if (clipboard.copyState === 'SUCCESS') { |
74 | | - snackInfo({ headerId: 'spreadsheet/clipboard/success' }); |
75 | | - clipboard.ready(); |
76 | | - } else if (clipboard.copyState === 'ERROR') { |
77 | | - snackError({ headerId: 'spreadsheet/clipboard/error' }); |
78 | | - clipboard.ready(); |
79 | | - } |
80 | | - }, [clipboard, snackInfo, snackError]); |
| 75 | + const onClipboardError = useCallback(() => { |
| 76 | + snackError({ headerId: 'spreadsheet/clipboard/error' }); |
| 77 | + }, [snackError]); |
81 | 78 |
|
82 | 79 | const getCsvProps = useCallback( |
83 | 80 | (csvCase: SpreadsheetSaveOptionId.COPY_CSV | SpreadsheetSaveOptionId.EXPORT_CSV) => { |
@@ -117,7 +114,7 @@ export default function SaveSpreadsheetButton({ |
117 | 114 | action: () => { |
118 | 115 | const csvProps = getCsvProps(SpreadsheetSaveOptionId.COPY_CSV); |
119 | 116 | if (csvProps) { |
120 | | - clipboard.copy(getCSVData(csvProps) ?? ''); |
| 117 | + copytoClipboard(getCSVData(csvProps) ?? '', onClipboardCopy, onClipboardError); |
121 | 118 | } |
122 | 119 | }, |
123 | 120 | disabled: dataSize === 0, |
@@ -146,8 +143,9 @@ export default function SaveSpreadsheetButton({ |
146 | 143 | saveFilterDialogOpen.setTrue, |
147 | 144 | tableDefinition.type, |
148 | 145 | getCsvProps, |
149 | | - clipboard, |
150 | 146 | getCSVData, |
| 147 | + onClipboardCopy, |
| 148 | + onClipboardError, |
151 | 149 | downloadCSVData, |
152 | 150 | ] |
153 | 151 | ); |
|
0 commit comments