agama-project / agama

A service-based Linux installer
GNU General Public License v2.0
135 stars 41 forks source link

Improve usage of browser local storage #1044

Open joseivanlopez opened 7 months ago

joseivanlopez commented 7 months ago

Agama implements a React hook for using local storage, see https://github.com/openSUSE/agama/blob/master/web/src/utils.js#L172. This hook is currently used three times:

There are some problems with the current approach:

The useLocalStorage hook should be improved. It should storage everything in a single object for Agama, and each value has to indicate when to reset and its default value.

const agamaLocalStorage = [
  { 
    id: "storageSpaceActionsExpanded",
    resetOn: "productChange",
    default: []
  },
  { 
    id: "otherValue",
    resetOn: null,
    default: 10
  }
]

localStorage.setItem("agama", JSON.stringify(agamaLocalStorage))

And Agama should reset the values to its default when that events happen.

balsa-asanovic commented 5 months ago

Hey, can I have a shot at this?

joseivanlopez commented 5 months ago

Hi! I am not sure if we will really need this. For now, I think we can keep it on hold and reevalute later. Thanks!

dgdavid commented 5 months ago

Hi! I am not sure if we will really need this. For now, I think we can keep it on hold and reevalute later. Thanks!

Just in time since I was about to comment:

Sure, go ahead. Please, remember publishing valuable changes as soon as possible (you can open a draft PR). It's a way of gathering early feedback and been able to foresee if we are going in the right direction.

Also, do not hesitate of asking for help as soon as you get stuck with something or you need an advise.

Last but not least, I believe that resetOn could be a collection instead of a single value. Or maybe @joseivanlopez has another view and he prefers more granularity in the data stored.

But I agree, better to re-evaluate if it is really needed before Balsa starts contributing.

balsa-asanovic commented 4 months ago

Okay then, I'll try looking for something else to work on.