-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[No QA] [TS migration] Migrate 'Link.js' lib to TypeScript #28257
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
Changes from 1 commit
e5cf992
4662d7d
e36f442
1df720f
d6b95ed
5d5f0ff
4b8f24a
9a22d2e
2bad6b7
f8a156d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,4 @@ | ||||||||
import Onyx from 'react-native-onyx'; | ||||||||
import lodashGet from 'lodash/get'; | ||||||||
import _ from 'underscore'; | ||||||||
import ONYXKEYS from '../../ONYXKEYS'; | ||||||||
import asyncOpenURL from '../asyncOpenURL'; | ||||||||
import * as API from '../API'; | ||||||||
|
@@ -10,29 +8,23 @@ import * as Url from '../Url'; | |||||||
let isNetworkOffline = false; | ||||||||
Onyx.connect({ | ||||||||
key: ONYXKEYS.NETWORK, | ||||||||
callback: (val) => (isNetworkOffline = lodashGet(val, 'isOffline', false)), | ||||||||
callback: (value) => (isNetworkOffline = value?.isOffline ?? false), | ||||||||
}); | ||||||||
|
||||||||
let currentUserEmail; | ||||||||
let currentUserEmail: string; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I would be more safe if we specify that this variable can be undefined, because it's only populated in the callback of Onyx, so before that happens it's undefined and we should consider this possibility. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or if we only care about the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is an option too, @kubabutkiewicz We can change this one to: let currentUserEmail = ''; |
||||||||
Onyx.connect({ | ||||||||
key: ONYXKEYS.SESSION, | ||||||||
callback: (val) => (currentUserEmail = lodashGet(val, 'email', '')), | ||||||||
callback: (value) => (currentUserEmail = value?.email ?? ''), | ||||||||
}); | ||||||||
|
||||||||
/** | ||||||||
* @param {String} [url] the url path | ||||||||
* @param {String} [shortLivedAuthToken] | ||||||||
* | ||||||||
* @returns {Promise<string>} | ||||||||
*/ | ||||||||
function buildOldDotURL(url, shortLivedAuthToken) { | ||||||||
const hasHashParams = url.indexOf('#') !== -1; | ||||||||
const hasURLParams = url.indexOf('?') !== -1; | ||||||||
function buildOldDotURL(url?: string, shortLivedAuthToken?: string): Promise<string> { | ||||||||
kubabutkiewicz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
const hasHashParams = url?.indexOf('#') !== -1; | ||||||||
const hasURLParams = url?.indexOf('?') !== -1; | ||||||||
|
||||||||
const authTokenParam = shortLivedAuthToken ? `authToken=${shortLivedAuthToken}` : ''; | ||||||||
const emailParam = `email=${encodeURIComponent(currentUserEmail)}`; | ||||||||
|
||||||||
const params = _.compact([authTokenParam, emailParam]).join('&'); | ||||||||
const paramsArray = [authTokenParam, emailParam]; | ||||||||
const params = paramsArray.filter(Boolean).join('&'); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i love this pattern, congrats @kubabutkiewicz 🔥
Comment on lines
+26
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB: I don't see the need of introducing new variable
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any feedback? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bump, though not blocker There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for me it was looking more clear when did that, should I revert that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine |
||||||||
|
||||||||
return Environment.getOldDotEnvironmentURL().then((environmentURL) => { | ||||||||
const oldDotDomain = Url.addTrailingForwardSlash(environmentURL); | ||||||||
|
@@ -42,18 +34,11 @@ function buildOldDotURL(url, shortLivedAuthToken) { | |||||||
}); | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* @param {String} url | ||||||||
* @param {Boolean} shouldSkipCustomSafariLogic When true, we will use `Linking.openURL` even if the browser is Safari. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we leave this note in? It might be useful for the future! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added @dangrous 😄 |
||||||||
*/ | ||||||||
function openExternalLink(url, shouldSkipCustomSafariLogic = false) { | ||||||||
function openExternalLink(url: string, shouldSkipCustomSafariLogic = false) { | ||||||||
asyncOpenURL(Promise.resolve(), url, shouldSkipCustomSafariLogic); | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* @param {String} url the url path | ||||||||
*/ | ||||||||
function openOldDotLink(url) { | ||||||||
function openOldDotLink(url: string) { | ||||||||
if (isNetworkOffline) { | ||||||||
buildOldDotURL(url).then((oldDotURL) => openExternalLink(oldDotURL)); | ||||||||
return; | ||||||||
|
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.
Same.
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.
actually here it would stay
false
before this callback fires 🤔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 are right @adhorodyski! Sorry @kubabutkiewicz , but could you revert this one?