-
Notifications
You must be signed in to change notification settings - Fork 14k
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
chore: Refactor localstorage into typesafe version #17832
chore: Refactor localstorage into typesafe version #17832
Conversation
/testenv up |
@etr2460 Ephemeral environment spinning up at http://54.201.109.147:8080. Credentials are |
Codecov Report
@@ Coverage Diff @@
## master #17832 +/- ##
==========================================
- Coverage 67.17% 67.16% -0.02%
==========================================
Files 1609 1608 -1
Lines 64797 64798 +1
Branches 6855 6851 -4
==========================================
- Hits 43530 43520 -10
- Misses 19411 19419 +8
- Partials 1856 1859 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for cleaning things up! This definitely looks cleaner. Just have one little non-blocking suggestion for your consideration.
@@ -164,7 +164,8 @@ function ChartList(props: ChartListProps) { | |||
const [preparingExport, setPreparingExport] = useState<boolean>(false); | |||
|
|||
const { userId } = props.user; | |||
const userKey = getFromLocalStorage(userId?.toString(), null); | |||
// TODO: Fix usage of localStorage keying on the user id | |||
const userKey = dangerouslyGetItemDoNotUse(userId?.toString(), null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think userKey
may actually be userProfile
or userSettings
. We can also do type coercing to avoid calling the private dangerous functions:
const userProfile = getItem(String(userId || '') as "FIXME_user_profile_by_user_id", null);
type LocalStorageValues {
// it's a bad practice to use the raw user id as storage keys
// we should at least prefix them.
FIXME_user_profile_by_user_id: {
thumbnails: boolean;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll update the variable name. personally i prefer using the dangerous function here though, since it seems a bit easier to parse than the type assertion (that's clearly not true)
4caa3b7
to
ce48f9a
Compare
Ephemeral environment shutdown and build artifacts deleted. |
SUMMARY
Refactors localstorage usage into a typesafe version, and unifies the key constants into an enum so that we can ensure they aren't reused by accident
Precursor to #17708
TESTING INSTRUCTIONS
CI, new unit tests for my changes, test various features in testenv
ADDITIONAL INFORMATION
to: @ktmud @rusackas @graceguo-supercat @pkdotson