Handle template loading better

This commit is contained in:
1ilit 2023-12-24 03:06:49 +02:00
parent 78ce0839d8
commit b9fbcfb9b6
3 changed files with 29 additions and 15 deletions

View File

@ -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 = {

View File

@ -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>

View File

@ -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();