Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve usage of browser local storage #1044

Open
joseivanlopez opened this issue Feb 20, 2024 · 4 comments
Open

Improve usage of browser local storage #1044

joseivanlopez opened this issue Feb 20, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@joseivanlopez
Copy link
Contributor

joseivanlopez commented Feb 20, 2024

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:

  • Arbitrary keys are used for storing data: "agama-iscsi-discovery", "storage-space-actions-expanded", "storage-space-actions-auto-expanded".
  • The data is never reset, and sometimes it should be deleted after certain event (e.g., "storage-space-actions-expanded" after changing a product).

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.

@joseivanlopez joseivanlopez added the enhancement New feature or request label Feb 20, 2024
@balsa-asanovic
Copy link
Contributor

Hey, can I have a shot at this?

@joseivanlopez
Copy link
Contributor Author

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
Copy link
Contributor

dgdavid commented May 3, 2024

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants