Save point, Sidebar prevents navigation without first saving or cancelling current changes

This commit is contained in:
Daniel S. Hansen
2025-07-31 12:23:45 -07:00
parent 90704879e1
commit 364ce0b752
4 changed files with 51 additions and 18 deletions
@@ -11,11 +11,11 @@ import { CancelButton } from "../components/CancelButton";
import { SaveButton } from "../components/SaveButton";
import DeleteAllButton from "../components/DeleteAllButton";
export function DashboardCanvas({ view, setView, layout, setLayout, onLayoutChange }) {
const [isEditable, setIsEditable] = useState(false); // editable=true means static=false (vice versa)
const [isDelete, setIsDelete] = useState(false);
export function DashboardCanvas({ isEditable, setIsEditable, isDelete, setIsDelete, view, setView, layout, setLayout, originalLayout, setOriginalLayout, onLayoutChange, onChangeView }) {
// const [isEditable, setIsEditable] = useState(false); // editable=true means static=false (vice versa)
// const [isDelete, setIsDelete] = useState(false);
const [newCounter, setNewCounter] = useState(3);
const [originalLayout, setOriginalLayout] = useState([]);
// const [originalLayout, setOriginalLayout] = useState([]);
const onAddWidget = () => {
const newId = newCounter.toString();
@@ -100,15 +100,15 @@ export function DashboardCanvas({ view, setView, layout, setLayout, onLayoutChan
// Prevent navigation away from 'My Dashboard' while in Edit mode
onValueChange={(e) => {
const nextView = e.value;
if (view === "widget" && isEditable && nextView !== "widget") {
const confirmed = window.confirm(
"You have unsaved changes. Do you wish to discard them and continue?"
);
if (!confirmed) return;
onCancel();
}
setView(nextView);
onChangeView(nextView);
// if (view === "widget" && isEditable && nextView !== "widget") {
// const confirmed = window.confirm(
// "You have unsaved changes. Do you wish to discard them and continue?"
// );
// if (!confirmed) return;
// onCancel();
// }
// setView(nextView);
}}
>
<Flex