Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

Commit

Permalink
fix(#113): init app properly before loading additional views to preve…
Browse files Browse the repository at this point in the history
…nt invalid auth session states
  • Loading branch information
Andreas Gasser committed May 13, 2019
1 parent 1bb48db commit 6e8528d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/app/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import AppHeader from './AppHeader';
import AppFooter from './AppFooter';
import AppRoutes from './AppRoutes';

import AppLoadingView from './AppLoadingView';

import { Theme } from '../styles';

const StyledAppContent = styled(Box)`
Expand All @@ -23,6 +25,7 @@ const StyledAppContent = styled(Box)`
class App extends Component {
static propTypes = {
isAuthenticated: PropTypes.bool.isRequired,
didLoad: PropTypes.bool.isRequired,
loadApplication: PropTypes.func.isRequired,
username: PropTypes.string,
message: PropTypes.shape({
Expand All @@ -42,7 +45,13 @@ class App extends Component {
}

render() {
const { isAuthenticated, username, message } = this.props;
const {
isAuthenticated,
didLoad,
username,
message,
} = this.props;

return (
<Grommet theme={Theme} full>
<AppMessage
Expand All @@ -54,7 +63,10 @@ class App extends Component {
/>
<StyledAppContent fill justify="between" direction="column">
<Box flex fill pad="none">
<AppRoutes isAuthenticated={isAuthenticated} />
{ didLoad
? <AppRoutes isAuthenticated={isAuthenticated} />
: <AppLoadingView />
}
<AppFooter />
</Box>
</StyledAppContent>
Expand Down
2 changes: 2 additions & 0 deletions src/app/AppContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { logOutUser } from '../redux/auth';
import { isAuthenticatedSelector, authUsernameSelector } from '../redux/auth/selectors';

import { loadApplication } from '../redux/application';
import { applicationDidLoadSelector } from '../redux/application/selectors';
import {
messageShowSelector,
messageTextSelector,
Expand All @@ -17,6 +18,7 @@ import {

const mapStateToProps = state => ({
isAuthenticated: isAuthenticatedSelector(state),
didLoad: applicationDidLoadSelector(state),
username: authUsernameSelector(state),
message: {
show: messageShowSelector(state),
Expand Down
27 changes: 27 additions & 0 deletions src/app/AppLoadingView.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import styled from 'styled-components';

import LoadingIndicator from '../ui/async/LoadingIndicator';
import View from '../ui/View';

import { Colors } from '../styles';

const StyledContainer = styled(View)`
text-align: center;
color: ${Colors.ColorsPalette.TextFaded};
`;

const AppLoadingView = () => (
<View>
<StyledContainer>
<h3>Please stay tuned, app is loading.</h3>
<LoadingIndicator size={120} />
</StyledContainer>
</View>
);

export const __testables__ = {
StyledContainer,
};

export default AppLoadingView;
7 changes: 7 additions & 0 deletions src/redux/application/selectors.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { createSelector } from 'reselect';

import { AppStatus } from './index';

export const applicationStateSelector = state => state.application || {};

export const applicationStatusSelector = createSelector(
applicationStateSelector,
({ status }) => status,
);

export const applicationDidLoadSelector = createSelector(
applicationStatusSelector,
status => status && status === AppStatus.APPLICATION_DID_LOAD,
);

0 comments on commit 6e8528d

Please sign in to comment.