Adds buttons to the menu to export / import the settings#2545
Adds buttons to the menu to export / import the settings#2545Ditto-IV100 wants to merge 6 commits intoRocketMap:developfrom
Conversation
| }) | ||
| } | ||
|
|
||
| function download(name, settings) { // eslint-disable-line no-unused-vars |
There was a problem hiding this comment.
download -> downloadSettings
| a.click() | ||
| document.body.removeChild(a) | ||
| } | ||
| function upload(e) { |
There was a problem hiding this comment.
upload -> loadSettings
There was a problem hiding this comment.
(And add a linebreak between this function and the one before.)
| console.log(fr.result) | ||
| upload(fr.result) | ||
| } | ||
| fr.readAsText(t.files[0]) |
There was a problem hiding this comment.
Just use file.target.files[0].
(And remove the declaration of t.)
| </div> | ||
| </div> | ||
| <div> | ||
| <center><button class="settings" onclick="download('RocketMap', JSON.stringify(JSON.stringify(localStorage)))"><i class="fa fa-upload fa-fw"></i>Export Settings</button></center> |
There was a problem hiding this comment.
What's the purpose of the double JSON.stringify()?
There was a problem hiding this comment.
You need two JSON.stringify()'s to get the quotes escaped (for loadSettings(e)).
| </div> | ||
| </div> | ||
| <div> | ||
| <center><button class="settings" onclick="downloadSettings('RocketMap', JSON.stringify(JSON.stringify(localStorage)))"><i class="fa fa-upload fa-fw"></i>Export Settings</button></center> |
There was a problem hiding this comment.
Double JSON.stringify(JSON.stringify( ? Is the double quoting necessary to make it downloadable?
There was a problem hiding this comment.
It is not necessary to download it, but to deal with the data during import. This code works fine for me. But maybe I have a cleaner solution. I have to test it.
| function openSettingsFile(file) { // eslint-disable-line no-unused-vars | ||
| var fr = new FileReader() | ||
| fr.onload = function () { | ||
| console.log(fr.result) |
| } | ||
|
|
||
| function openSettingsFile(file) { // eslint-disable-line no-unused-vars | ||
| var fr = new FileReader() |
There was a problem hiding this comment.
Use more descriptive variable names.
| } | ||
|
|
||
| function loadSettings(e) { | ||
| var t = JSON.parse(JSON.parse(e)) |
There was a problem hiding this comment.
Same here, related to my question about the double stringify.
- use Object.assign instead of Object.keys().forEach - loadSettings() no longer necessary - double quoting no longer necessary
|
@sebastienvercammen |
7844410 to
b81bb26
Compare
| } | ||
|
|
||
| function downloadSettings(name, settings) { // eslint-disable-line no-unused-vars | ||
| var a = document.createElement('a') |
There was a problem hiding this comment.
this one needs a readabillity update -> more descriptive variable name.
Description
Adds buttons to the menu to export / import the settings.
Motivation and Context
Because the settings are stored in "Local Storage", they can be lost. Not anymore! You can export the settings for a later import.
By default, the file will have the following name: "RocketMap_DD-MM-YYYY HH:mm.txt".
How Has This Been Tested?
I use it on my own server.
Screenshots (if appropriate):
Types of changes
Checklist: