Refactor code to improve error handling and add dependencies to useEffect hooks

This commit is contained in:
Sergey Krashevich 2023-07-06 18:31:00 +03:00
parent a468ed8071
commit 6172595863
No known key found for this signature in database
GPG Key ID: 625171324E7D3856

View File

@ -103,7 +103,7 @@ export default function CameraMasks({ camera }) {
if (window.navigator.clipboard && window.navigator.clipboard.writeText) { if (window.navigator.clipboard && window.navigator.clipboard.writeText) {
// Use Clipboard API if available // Use Clipboard API if available
window.navigator.clipboard.writeText(textToCopy).catch((err) => { window.navigator.clipboard.writeText(textToCopy).catch((err) => {
// console.error('Failed to copy text: ', err); throw new Error('Failed to copy text: ', err);
}); });
} else { } else {
// Fallback to document.execCommand('copy') // Fallback to document.execCommand('copy')
@ -118,7 +118,7 @@ export default function CameraMasks({ camera }) {
throw new Error('Failed to copy text'); throw new Error('Failed to copy text');
} }
} catch (err) { } catch (err) {
//console.error('Failed to copy text: ', err); throw new Error('Failed to copy text: ', err);
} }
document.body.removeChild(textarea); document.body.removeChild(textarea);
@ -139,7 +139,7 @@ export default function CameraMasks({ camera }) {
// handle error // handle error
//console.error(error); //console.error(error);
} }
}, [motionMaskPoints]); }, [camera, motionMaskPoints]);
// Zone methods // Zone methods
@ -177,7 +177,7 @@ ${Object.keys(zonePoints)
if (window.navigator.clipboard && window.navigator.clipboard.writeText) { if (window.navigator.clipboard && window.navigator.clipboard.writeText) {
// Use Clipboard API if available // Use Clipboard API if available
window.navigator.clipboard.writeText(textToCopy).catch((err) => { window.navigator.clipboard.writeText(textToCopy).catch((err) => {
//console.error('Failed to copy text: ', err); throw new Error('Failed to copy text: ', err);
}); });
} else { } else {
// Fallback to document.execCommand('copy') // Fallback to document.execCommand('copy')
@ -192,7 +192,7 @@ ${Object.keys(zonePoints)
throw new Error('Failed to copy text'); throw new Error('Failed to copy text');
} }
} catch (err) { } catch (err) {
//console.error('Failed to copy text: ', err); throw new Error('Failed to copy text: ', err);
} }
document.body.removeChild(textarea); document.body.removeChild(textarea);
@ -213,7 +213,7 @@ ${Object.keys(zonePoints)
// handle error // handle error
//console.error(error); //console.error(error);
} }
}, [zonePoints]); }, [camera, zonePoints]);
// Object methods // Object methods
const handleEditObjectMask = useCallback( const handleEditObjectMask = useCallback(
@ -269,7 +269,7 @@ ${Object.keys(objectMaskPoints)
// handle error // handle error
//console.error(error); //console.error(error);
} }
}, [objectMaskPoints]); }, [camera, objectMaskPoints]);
const handleAddToObjectMask = useCallback( const handleAddToObjectMask = useCallback(
(key) => { (key) => {
@ -556,13 +556,6 @@ function MaskValues({
); );
const handleSave = useCallback(
(event) => {
const { key } = event.target.dataset;
onSave(key);
},
[onAdd]
);
return ( return (
<div className="overflow-hidden" onMouseOver={handleMousein} onMouseOut={handleMouseout}> <div className="overflow-hidden" onMouseOver={handleMousein} onMouseOut={handleMouseout}>