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

Ej/zustand store #738

Merged
merged 19 commits into from
Aug 3, 2023
Merged

Ej/zustand store #738

merged 19 commits into from
Aug 3, 2023

Conversation

lightlii
Copy link
Contributor

Contributor checklist:

  • My contribution is not related to translations. Please submit translation changes via our Mapeo Crowdin project
  • My commits are in nice logical chunks with good commit messages
  • I have walked through the QA Manual Testing
    Script
    and updated it if necessary.
  • If my changes depend upon an update to a dependency, I have updated the package-lock.json file using npm install --package-lock
  • My changes have been tested with the mobile app.
  • My changes are ready to be shipped to users on Windows, Mac, and Linux using the production version of the application built with electron-builder.

Description

Adds zustand state store with persistence using our current conf store. Versioning is achieved with a STORE_VERSION constant applied to the store, not sure if this is the best way, open to feedback.

closes #735

@lightlii
Copy link
Contributor Author

ok looks like versioning might be better handled in the conf store? looking at the migrations section here

@lightlii
Copy link
Contributor Author

added another commit with some types on the store. Not sure they're any good though, Zustand's typescript docs are a bit vague unfortunately...

@lightlii
Copy link
Contributor Author

Ok I'm slightly more confident in my typings now but still need someone to look over them

@lightlii lightlii marked this pull request as ready for review July 18, 2023 13:57
@lightlii lightlii requested a review from ErikSin July 18, 2023 13:58
@lightlii
Copy link
Contributor Author

lightlii commented Jul 19, 2023

after a little back and forth with @gmaclennan on slack we've decided to replace conf with electron-store. It uses conf under the hood so is theoretically compatible with current persisted configs. I'll go ahead and use this PR to make that change I think since it's so small

@lightlii
Copy link
Contributor Author

lightlii commented Jul 19, 2023

lastly, since we now have a means of persisting state through zustand I suggest removing the createPersistedState. It would be less confusing to have only a single way of persisting state in the app. There's only a single use of it in the app so its a very minor change and again I can roll it into this PR if you agree @ErikSin ?

I haven't been able to confirm it's fully compatible with existing persisted configs but the only thing we're saving is the active tab so at worst user won't see their last tab once when opening the next update which I'd argue is an acceptable trade-off

@ErikSin
Copy link
Contributor

ErikSin commented Jul 19, 2023

That sounds good! Thanks @lightlii

Copy link
Contributor

@ErikSin ErikSin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set up a meeting to figure out your pre-commit steps that don't seem to be working

In order to utilize typescript, you need to add "//@ts-check" to the first line of every file. store.js has some ts errors that you are not seeing currently.

I think store.js should be stored in the folder hooks since it just returns hooks

src/renderer/store.js Outdated Show resolved Hide resolved
src/renderer/store.js Outdated Show resolved Hide resolved
Comment on lines 11 to 14
* @returns {Promise<string | null>}
*/
getItem: async key => {
return (await store.get(key)) || null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a typing issue here. Typescript is expecting string or null. store.get return unknown. You will have to cast a type here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure how casting works in jsdoc, I've pushed something. Can you take a look and confirm that what you meant?

/**
* @type {import('zustand/middleware').StateStorage}
*/
const storage = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably set a schema to storage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what that would look like or how best implement it... We can chat about that later though

import SyncView from './SyncView'
import { STATES as updateStates, UpdaterView, UpdateTab } from './UpdaterView'
import useUpdater from './UpdaterView/useUpdater'
import Loading from './Loading'
import buildConfig from '../../build-config'
import { usePersistedUiStore } from '../store'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update the import!

@lightlii lightlii mentioned this pull request Jul 26, 2023
@lightlii lightlii merged commit 5cab203 into master Aug 3, 2023
9 checks passed
@lightlii lightlii deleted the ej/zustand-store branch August 3, 2023 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce Zustand Store
2 participants