Handle template loading better
This commit is contained in:
parent
78ce0839d8
commit
b9fbcfb9b6
@ -702,8 +702,8 @@ export default function ControlPanel({
|
||||
});
|
||||
};
|
||||
const createNewDiagram = (id) => {
|
||||
localStorage.setItem("args", `${id}`);
|
||||
window.open("/editor", "_blank");
|
||||
const newWindow = window.open("/editor");
|
||||
newWindow.name = "lt " + id;
|
||||
};
|
||||
|
||||
const menu = {
|
||||
|
@ -171,6 +171,10 @@ export default function Templates() {
|
||||
await db.templates.delete(id);
|
||||
};
|
||||
|
||||
const editTemplate = (id) => {
|
||||
console.log(id);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
document.title = "Templates | drawDB";
|
||||
}, []);
|
||||
@ -253,7 +257,10 @@ export default function Templates() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-around mt-2">
|
||||
<button className="w-full text-center flex justify-center items-center border rounded px-2 py-1 bg-white hover:bg-gray-200 transition-all duration-300 text-blue-500">
|
||||
<button
|
||||
className="w-full text-center flex justify-center items-center border rounded px-2 py-1 bg-white hover:bg-gray-200 transition-all duration-300 text-blue-500"
|
||||
onClick={() => editTemplate(c.id)}
|
||||
>
|
||||
<i className="bi bi-pencil-fill"></i>
|
||||
<div className="ms-1.5 font-semibold">Edit</div>
|
||||
</button>
|
||||
|
@ -578,18 +578,25 @@ export default function Editor() {
|
||||
});
|
||||
};
|
||||
|
||||
const args = localStorage.getItem("args");
|
||||
if (!args || args === "-1") {
|
||||
if (window.name === "") {
|
||||
console.log("Loading the latest diagram");
|
||||
loadLatestDiagram();
|
||||
} else {
|
||||
const did = parseInt(window.name.split(" ")[1]);
|
||||
loadDiagram(did);
|
||||
}
|
||||
if (window.name == "") {
|
||||
console.log("Loading the latest diagram");
|
||||
loadLatestDiagram();
|
||||
} else {
|
||||
console.log("Loading template with id", args);
|
||||
localStorage.setItem("args", "-1");
|
||||
const name = window.name.split(" ");
|
||||
const op = name[0];
|
||||
const did = parseInt(name[1]);
|
||||
switch (op) {
|
||||
case "d": {
|
||||
loadDiagram(did);
|
||||
break;
|
||||
}
|
||||
case "lt": {
|
||||
console.log("Loading template with id", did);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
socket.connect();
|
||||
|
Loading…
Reference in New Issue
Block a user