-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
ref(sandbox): Demo Header Update & fix email localstorage #29625
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,25 @@ | ||
| import getCookie from 'app/utils/getCookie'; | ||
|
|
||
| // return email query parameter | ||
| export function emailQueryParameter(): string { | ||
| const email = localStorage.getItem('email'); | ||
| const queryParameter = email ? `?email=${email}` : ''; | ||
| return queryParameter; | ||
| export function extraQueryParameter(): URLSearchParams { | ||
| // cookies that have = sign are quotes so extra quotes need to be removed | ||
| const extraQueryString = getCookie('extra_query_string')?.replaceAll('"', '') || ''; | ||
| const extraQuery = new URLSearchParams(extraQueryString); | ||
| return extraQuery; | ||
| } | ||
|
|
||
| // return extra query depending, depending on if used in getStartedUrl | ||
| export function extraQueryParameter(getStarted: boolean): string { | ||
| export function extraQueryParameterWithEmail(): URLSearchParams { | ||
| const params = extraQueryParameter(); | ||
| const email = localStorage.getItem('email'); | ||
| const extraQueryString = getCookie('extra_query_string'); | ||
| // cookies that have = sign are quotes so extra quotes need to be removed | ||
| const extraQuery = extraQueryString ? extraQueryString.replaceAll('"', '') : ''; | ||
| if (email) { | ||
| params.append('email', email); | ||
| } | ||
| return params; | ||
| } | ||
|
|
||
| if (getStarted) { | ||
| const emailSeparator = email ? '&' : '?'; | ||
| const getStartedSeparator = extraQueryString ? emailSeparator : ''; | ||
| return getStartedSeparator + extraQuery; | ||
| export function urlAttachQueryParams(url: string, params: URLSearchParams): string { | ||
| const queryString = params.toString(); | ||
| if (queryString) { | ||
| return url + '?' + queryString; | ||
| } | ||
| const extraSeparator = extraQueryString ? `?` : ''; | ||
| return extraSeparator + extraQuery; | ||
| return url; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@Neo-Zhixing It would be nice to keep that as a link but doing that would require us to make a HoC that listens for local storage changes and re-renders the child when that happens. Maybe too much work given the level of importance. But I'd still add a comment explaining why we are calling
window.openthis wayThere 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 thought about listening to local storage changes but that requires us to replace
localStorage.setItemwhich is a global change. Will add lots of maintenance overhead.https://stackoverflow.com/questions/26974084/listen-for-changes-with-localstorage-on-the-same-window
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.
Will add comment.
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.
You can do this with a react hook, which I think we already do in some places
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.
@evanpurkhiser and which hook is that?
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 also don't know if a hook works here when a different part of the app is updating the local storage. I think this hook only works when you're changing the session storage with the
setStatethat the hook returns in that single component.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.
it would work if you have a state that is updated on localstorage change. You can use the
storageevent for that.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.
@evanpurkhiser
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.
https://stackoverflow.com/questions/35865481/storage-event-not-firing
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.
ew gross event. Yeah just do what you've got here. Or put it in reflux but 🤷