-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Local storage #2158
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
Local storage #2158
Conversation
@lindapaiste @raclim I suggest we store all the preferences locally and I also want to organize the constants as mentioned in the todos of that file. |
This is a good idea but I think it needs more thought and discussion.
|
Yess I also agree with this we should definitely store all the preferences locally |
What approach u think would be the best for the localstorage |
Tough question because like I said we are dealing with a lot of code which is already not great. We would The API call to update the preferences for logged-in users is handled by thunk actions in the
Instead of a conditional execution with The above code would become:
and then the helper would become:
The Re: middleware. We can't easily check if an action is a preferences action because the actions don't follow the sort of consistent naming pattern that redux toolkit actions do so we can't use the I'm busy today but I can play this more tomorrow. I'm also really tempted to put in a PR that rewrites this whole reducer and its actions. This is an example where the legacy code is hard to work with and makes it hard to add new features. |
I'll get back to this |
Hey @lindapaiste, sorry got stuck with some other things at that time. Before you write a PR that rewrites this whole reducer and Its actions would you like me to make the code changes you suggested in |
@dewanshDT I actually did end up rewriting the whole reducer but I tried it two different ways and I haven't put in a PR because I'm not sure which one I prefer. I have a tendency to over-analyze things 🙃 I think that you should go ahead and handle the You can probably model it after the code that we have for |
Ok let me get this down in writing. Approach 1 - Separate action creators for each action. This generally makes the most sense, but the downside here is that I am sending the entire preferences object to the API on each change so it's a larger payload being set across the network. Which I think I could fix but the code is really simple to just send the entire reducer/slice file
actions/middleware file
Approach 2 - This has only one core action to update the state. Then I have action creator functions as wrappers around that action for each specific preference. That way I know when I make the API call which specific properties have changed and can just send those. reducer/slice file
actions/middleware file
Both approaches are using Where I left off with this is thinking that Approach 1 is definitely better but that I should see if I can figure out how to send a smaller API payload by looking at the changes in the state. Maybe it doesn't matter. |
...and it took longer to type that out than to fix it! Only a few extra lines to send a smaller payload with the help of lodash
I haven't put in the |
Approach 1 defines separate action creators for each preference option and adds an extra reducer to the slice that handles updating the entire preferences object. The middleware listens for actions from the preferences slice and dispatches a PUT request to the API with the entire preferences object. Approach 2 defines a single action creator, setPreferences, that takes an object with partial preference options as its payload. The middleware listens specifically for this action creator and dispatches a PUT request to the API with the payload. Overall, Approach 2 is more concise and easier to maintain since it uses a single action creator for all preference options. Additionally, the middleware specifically listens for the setPreferences action creator, making it more targeted and efficient. @lindapaiste let me know, what you think. |
Thanks so much for all of your work on this! I don't think we're going to implement this for now, but might be something to potentially explore in the future! |
Fixes #2144
Changes: these changes allows the editor to store the theme locally for the next refresh
I have verified that this pull request:
npm run lint
)npm run test
)develop
branch.Fixes #123