This repository was archived by the owner on Nov 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Add better return types for the API functions #218
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
REACT_APP_API_HOST=https://addons.mozilla.org | ||
|
||
# This is the placeholder used in the `index.html` file to inject the | ||
# authentication token on runtime. | ||
REACT_APP_AUTH_TOKEN_PLACEHOLDER=__AUTH_TOKEN__ | ||
REACT_APP_AUTHENTICATION_COOKIE=frontend_auth_token | ||
|
||
# This is the language that will be sent with all API requests. | ||
REACT_APP_DEFAULT_API_LANG=en-US | ||
REACT_APP_DEFAULT_API_VERSION=v4dev | ||
|
||
REACT_APP_FXA_CONFIG=amo |
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
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 |
---|---|---|
|
@@ -8,24 +8,25 @@ import { | |
withRouter, | ||
} from 'react-router-dom'; | ||
import makeClassName from 'classnames'; | ||
import log from 'loglevel'; | ||
|
||
import { ApplicationState, ConnectedReduxProps } from '../../configureStore'; | ||
import styles from './styles.module.scss'; | ||
import { ApiState, actions as apiActions } from '../../reducers/api'; | ||
import { | ||
ExternalUser, | ||
User, | ||
actions as userActions, | ||
fetchCurrentUserProfile, | ||
getCurrentUser, | ||
} from '../../reducers/users'; | ||
import * as api from '../../api'; | ||
import Navbar from '../Navbar'; | ||
import Browse from '../../pages/Browse'; | ||
import Index from '../../pages/Index'; | ||
import NotFound from '../../pages/NotFound'; | ||
import { gettext } from '../../utils'; | ||
|
||
type PublicProps = { | ||
export type PublicProps = { | ||
_fetchCurrentUserProfile: typeof fetchCurrentUserProfile; | ||
_log: typeof log; | ||
authToken: string | null; | ||
}; | ||
|
||
|
@@ -43,6 +44,11 @@ type Props = PublicProps & | |
/* eslint-enable @typescript-eslint/indent */ | ||
|
||
export class AppBase extends React.Component<Props> { | ||
static defaultProps = { | ||
_fetchCurrentUserProfile: fetchCurrentUserProfile, | ||
_log: log, | ||
}; | ||
|
||
componentDidMount() { | ||
const { authToken, dispatch } = this.props; | ||
|
||
|
@@ -51,18 +57,13 @@ export class AppBase extends React.Component<Props> { | |
} | ||
} | ||
|
||
async componentDidUpdate(prevProps: Props) { | ||
const { apiState, dispatch, profile } = this.props; | ||
componentDidUpdate(prevProps: Props) { | ||
const { apiState, profile } = this.props; | ||
|
||
if (!profile && prevProps.apiState.authToken !== apiState.authToken) { | ||
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. These kind of if statements make me sad. We should look into simplifying it with 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. Agreed. Should we file an issue? This patch gets too big. 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. Definitely. Not high priority: #246 |
||
const response = (await api.callApi({ | ||
apiState, | ||
endpoint: '/accounts/profile/', | ||
})) as ExternalUser; | ||
|
||
if (response && response.name) { | ||
dispatch(userActions.loadCurrentUser({ user: response })); | ||
} | ||
const { _fetchCurrentUserProfile, dispatch } = this.props; | ||
|
||
dispatch(_fetchCurrentUserProfile()); | ||
} | ||
} | ||
|
||
|
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.