Add button to download ctl config (#743)

* Move saveJson to util file

* Add button to download ctl config

* Add icon and tooltip to describe what the button does

---------

Co-authored-by: Danielv123 <danielv@danielv.no>
This commit is contained in:
Cooldude2606andDanielv123 authored and GitHub committed 2025-04-08 20:34:50 +01:00
1 parent 42cd099eea
commit 0e6d33aa82
3 files changed
+43 -17

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
/**
* Downloads a file to the users PC, should only be used following direct user input.
* @param name Name of the file to save
* @param blob Content to save
*/
export function saveFile(name: string, blob: Blob) {
// This is the most common and best supported method, for full support we should consider using npm:file-saver
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = name;
a.addEventListener("click", (e) => {
setTimeout(() => URL.revokeObjectURL(a.href), 30 * 1000);
});
a.click();
};
/**
* Downloads a json file to the users PC
* @param name Name of the file to save, should include .json
* @param json The object to save as a formated json string
*/
export function saveJson(name: string, json: object) {
saveFile(name, new Blob([JSON.stringify(json, null, 2)], { type: "application/json" }));
}