Skip to content

Free, simple, and intuitive online database diagram editor and SQL generator.

Fix save

1ilit2395a334bb5a
diff --git a/src/pages/Templates.jsx b/src/pages/Templates.jsx
index fe6ff814..9eb8265b 100644
--- a/src/pages/Templates.jsx
+++ b/src/pages/Templates.jsx
@@ -176,6 +176,11 @@ export default function Templates() {
newWindow.name = "t " + id;
};
+ const forkTemplate = (id) => {
+ const newWindow = window.open("/editor", "_blank");
+ newWindow.name = "lt " + id;
+ };
+
useEffect(() => {
document.title = "Templates | drawDB";
}, []);
@@ -225,7 +230,10 @@ export default function Templates() {
<div className="text-lg font-bold text-zinc-700">
{t.title}
</div>
- <button className="border rounded px-2 py-1 bg-white hover:bg-gray-200 transition-all duration-300">
+ <button
+ className="border rounded px-2 py-1 bg-white hover:bg-gray-200 transition-all duration-300"
+ onClick={() => forkTemplate(t.id)}
+ >
<i className="fa-solid fa-code-fork"></i>
</button>
</div>
@@ -252,7 +260,10 @@ export default function Templates() {
{c.title}
</div>
<div>
- <button className="me-1 border rounded px-2 py-1 bg-white hover:bg-gray-200 transition-all duration-300">
+ <button
+ className="me-1 border rounded px-2 py-1 bg-white hover:bg-gray-200 transition-all duration-300"
+ onClick={() => forkTemplate(c.id)}
+ >
<i className="fa-solid fa-code-fork"></i>
</button>
</div>
diff --git a/src/pages/editor.jsx b/src/pages/editor.jsx
index 63b80402..83887c18 100644
--- a/src/pages/editor.jsx
+++ b/src/pages/editor.jsx
@@ -493,7 +493,10 @@ export default function Editor() {
return;
}
if (diagram) {
- if (id === 0 && window.name === "") {
+ if (
+ (id === 0 && window.name === "") ||
+ window.name.split(" ")[0] === "lt"
+ ) {
db.diagrams
.add({
name: title,
@@ -547,7 +550,7 @@ export default function Editor() {
};
const name = window.name.split(" ");
const op = name[0];
- const diagram = window.name === "" || op === "d";
+ const diagram = window.name === "" || op === "d" || op === "lt";
save(diagram);
}, [tables, relationships, notes, areas, types, title, id, state]);
@@ -635,7 +638,7 @@ export default function Editor() {
break;
}
case "lt": {
- console.log("Loading template with id", did);
+ loadTemplate(did);
break;
}
case "t": {