-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[No QA] [TS migration] Migrate 'Link.js' lib to TypeScript #28257
Changes from 9 commits
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 lodashGet from 'lodash/get'; | ||||||||
import Onyx from 'react-native-onyx'; | ||||||||
import _ from 'underscore'; | ||||||||
import * as API from '@libs/API'; | ||||||||
import asyncOpenURL from '@libs/asyncOpenURL'; | ||||||||
import * as Environment from '@libs/Environment/Environment'; | ||||||||
|
@@ -10,29 +8,23 @@ import ONYXKEYS from '@src/ONYXKEYS'; | |||||||
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 = ''; | ||||||||
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) { | ||||||||
function buildOldDotURL(url: string, shortLivedAuthToken?: string): Promise<string> { | ||||||||
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; | ||||||||
|
@@ -63,7 +48,7 @@ function openOldDotLink(url) { | |||||||
asyncOpenURL( | ||||||||
// eslint-disable-next-line rulesdir/no-api-side-effects-method | ||||||||
API.makeRequestWithSideEffects('OpenOldDotLink', {}, {}) | ||||||||
.then((response) => buildOldDotURL(url, response.shortLivedAuthToken)) | ||||||||
.then((response) => (response ? buildOldDotURL(url, response.shortLivedAuthToken) : buildOldDotURL(url))) | ||||||||
.catch(() => buildOldDotURL(url)), | ||||||||
(oldDotURL) => oldDotURL, | ||||||||
); | ||||||||
|
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?