mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 07:33:12 +09:00
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:
1 parent
42cd099eea
commit
0e6d33aa82
3 files changed
+43
-17
No files matched your search
@@ -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" }));
|
||||
}
|
||||
Reference in new issue
Block a user