I know it was a snow day, but I felt the need to at least put some time towards LibriFox. I felt as if there was a lot of stuff that we were so close to creating, and so I decided to work on it a bit!
Today, I accomplished something I find important: savable settings.
We already have JSON and search functionality will hopefully come tomorrow, so I did some research into how I could get the settings to save, and return as soon as a user comes back in the app.
At first, I messed around with creating files manually. I couldn't find anything on Mozilla's website about savable settings (maybe I didn't look enough?) so I worked on some very large and complicated methods to do it for me. I was able to get settings to save, but I couldn't add settings to the file. I tried help from various websites. I was ending up in the same place every time, the FileHandle API. Which, I now understand, but I don't really need it [yet].
I then did some more research and found that it was a lot more simpler. In fact, it's just a single line. This line involves a variable called localStorage, which looks like it's pretty much on every app - however I include checks to make sure it exists in my methods to make sure the file is saving.
LocalStorage defines the settings file. You basically just code:
localStorage.setItem(key, value)
And the settings are saved. You can later go back:
localStorage.getValue(key)
And get the value of any key you have previously set.
Here's my two usable methods that I have tested:
function writeToSettings(key, value){ // Writes a key, value pair to settings
if(window.localStorage){
localStorage.setItem(key, value);
}
}
function getValue(key){ // Gets a value based on a key provided
if(window.localStorage){
localStorage.getItem(key);
}
}
However, I'm currently having an issue as to it not saving when the app closes. I'll look into this more tomorrow.
This is working out well. I'm hoping to use the work you and Alex are doing to gather resources for developing an organized curriculum in the future (starting next Summer). The iRomin tutorials look fabulous. They were written a few years back, so I don't know if they still work (I hope so), but even if they don't, they could be brought up to date. They are well organized and well written. Very nice!
ReplyDeletebtw. Great to see your dedication to this, posting on a snow day!