mubaris / curiosity

Find Amazing Github :octocat: Projects :zap:
https://mubaris.github.io/curiosity/
247 stars 66 forks source link

Allow users to add and remove usernames #29

Closed maiquynhtruong closed 7 years ago

maiquynhtruong commented 7 years ago

I changed the usernames array to be stored with localStorage. This is for #6.

I have not make any changes to UI. I just wanted my code to be reviewed before it is merged. I was thinking about using some of the localStorage library but I have some problem with numeric keys and string values. I planned to do something like for (var i = 0; i < USERNAMES.length; i++) { localStorage.setItem('user', {i: USERNAMES[i]}) } to store the usernames in localStorage the same way you use an array. But that adds some complexity when you constantly add and remove items out of the array, i.e you constantly have to increment/decrement. So I resorted to using JSON.stringify() and JSON.parse(). Google search something like "localStorage array" to see more details.

I'm not sure about your UI suggestions so let's discuss that. I'll make changes and we can merge later.

maiquynhtruong commented 7 years ago

Why everything failed :/

mubaris commented 7 years ago

This method is not persistent. Once you reload the page, it goes back to the original array. Therefore, I'm reverting this PR and closing it.

maiquynhtruong commented 7 years ago

Looks like data in localStorage isn't saved when your reload the page? Or do you have any suggestions how to persist saved data when you reload page?

mubaris commented 7 years ago

Using a localStorage library will be better.