This commit is contained in:
1ilit 2023-12-26 16:40:47 +02:00
parent 0e041ed913
commit 2395a334bb
2 changed files with 19 additions and 5 deletions

View File

@ -176,6 +176,11 @@ export default function Templates() {
newWindow.name = "t " + id; newWindow.name = "t " + id;
}; };
const forkTemplate = (id) => {
const newWindow = window.open("/editor", "_blank");
newWindow.name = "lt " + id;
};
useEffect(() => { useEffect(() => {
document.title = "Templates | drawDB"; document.title = "Templates | drawDB";
}, []); }, []);
@ -225,7 +230,10 @@ export default function Templates() {
<div className="text-lg font-bold text-zinc-700"> <div className="text-lg font-bold text-zinc-700">
{t.title} {t.title}
</div> </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> <i className="fa-solid fa-code-fork"></i>
</button> </button>
</div> </div>
@ -252,7 +260,10 @@ export default function Templates() {
{c.title} {c.title}
</div> </div>
<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> <i className="fa-solid fa-code-fork"></i>
</button> </button>
</div> </div>

View File

@ -493,7 +493,10 @@ export default function Editor() {
return; return;
} }
if (diagram) { if (diagram) {
if (id === 0 && window.name === "") { if (
(id === 0 && window.name === "") ||
window.name.split(" ")[0] === "lt"
) {
db.diagrams db.diagrams
.add({ .add({
name: title, name: title,
@ -547,7 +550,7 @@ export default function Editor() {
}; };
const name = window.name.split(" "); const name = window.name.split(" ");
const op = name[0]; const op = name[0];
const diagram = window.name === "" || op === "d"; const diagram = window.name === "" || op === "d" || op === "lt";
save(diagram); save(diagram);
}, [tables, relationships, notes, areas, types, title, id, state]); }, [tables, relationships, notes, areas, types, title, id, state]);
@ -635,7 +638,7 @@ export default function Editor() {
break; break;
} }
case "lt": { case "lt": {
console.log("Loading template with id", did); loadTemplate(did);
break; break;
} }
case "t": { case "t": {