Skip to content

Commit

Permalink
Show status when mask is saved (#7212)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickM-27 committed Jul 21, 2023
1 parent bfa7a5c commit d30a738
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion frigate/http.py
Expand Up @@ -1090,7 +1090,7 @@ def config_set():
logging.error(f"Error updating config: {e}")
return "Error updating config", 500

return "Config successfully updated", 200
return "Config successfully updated, restart to apply", 200


@bp.route("/config/schema.json")
Expand Down
44 changes: 29 additions & 15 deletions web/src/routes/CameraMap.jsx
Expand Up @@ -53,6 +53,8 @@ export default function CameraMasks({ camera }) {
);

const [editing, setEditing] = useState({ set: motionMaskPoints, key: 0, fn: setMotionMaskPoints });
const [success, setSuccess] = useState();
const [error, setError] = useState();

const handleUpdateEditable = useCallback(
(newPoints) => {
Expand Down Expand Up @@ -99,7 +101,7 @@ export default function CameraMasks({ camera }) {
const textToCopy = ` motion:
mask:
${motionMaskPoints.map((mask) => ` - ${polylinePointsToPolyline(mask)}`).join('\n')}`;

if (window.navigator.clipboard && window.navigator.clipboard.writeText) {
// Use Clipboard API if available
window.navigator.clipboard.writeText(textToCopy).catch((err) => {
Expand All @@ -111,7 +113,7 @@ export default function CameraMasks({ camera }) {
textarea.value = textToCopy;
document.body.appendChild(textarea);
textarea.select();

try {
const successful = document.execCommand('copy');
if (!successful) {
Expand All @@ -120,7 +122,7 @@ export default function CameraMasks({ camera }) {
} catch (err) {
throw new Error('Failed to copy text: ', err);
}

document.body.removeChild(textarea);
}
}, [motionMaskPoints]);
Expand All @@ -133,14 +135,17 @@ export default function CameraMasks({ camera }) {
const endpoint = `config/set?${queryParameters}`;
const response = await axios.put(endpoint);
if (response.status === 200) {
// handle successful response
setSuccess(response.data);
}
} catch (error) {
// handle error
//console.error(error);
if (error.response) {
setError(error.response.data.message);
} else {
setError(error.message);
}
}
}, [camera, motionMaskPoints]);


// Zone methods
const handleEditZone = useCallback(
Expand Down Expand Up @@ -185,7 +190,7 @@ ${Object.keys(zonePoints)
textarea.value = textToCopy;
document.body.appendChild(textarea);
textarea.select();

try {
const successful = document.execCommand('copy');
if (!successful) {
Expand All @@ -194,7 +199,7 @@ ${Object.keys(zonePoints)
} catch (err) {
throw new Error('Failed to copy text: ', err);
}

document.body.removeChild(textarea);
}
}, [zonePoints]);
Expand All @@ -207,11 +212,14 @@ ${Object.keys(zonePoints)
const endpoint = `config/set?${queryParameters}`;
const response = await axios.put(endpoint);
if (response.status === 200) {
// handle successful response
setSuccess(response.data);
}
} catch (error) {
// handle error
//console.error(error);
if (error.response) {
setError(error.response.data.message);
} else {
setError(error.message);
}
}
}, [camera, zonePoints]);

Expand Down Expand Up @@ -263,11 +271,14 @@ ${Object.keys(objectMaskPoints)
const endpoint = `config/set?${queryParameters}`;
const response = await axios.put(endpoint);
if (response.status === 200) {
// handle successful response
setSuccess(response.data);
}
} catch (error) {
// handle error
//console.error(error);
if (error.response) {
setError(error.response.data.message);
} else {
setError(error.message);
}
}
}, [camera, objectMaskPoints]);

Expand Down Expand Up @@ -320,6 +331,9 @@ ${Object.keys(objectMaskPoints)
header="Warning"
/>

{success && <div className="max-h-20 text-green-500">{success}</div>}
{error && <div className="p-4 overflow-scroll text-red-500 whitespace-pre-wrap">{error}</div>}

<div className="space-y-4">
<div className="relative">
<img ref={imageRef} src={`${apiHost}/api/${camera}/latest.jpg`} />
Expand Down

0 comments on commit d30a738

Please sign in to comment.