Skip to content
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

Enable SSR on all pages #129

Merged
merged 3 commits into from
Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/containers/GroupsNameContainer/GroupsNameContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import GroupsName, {

class GroupsNameContainer extends Component {
componentWillMount() {
GroupsNameContainer.loadData(this.props);
this.props.loadAsync();
}

componentWillReceiveProps(newProps) {
if (this.props.groupId !== newProps.groupId) {
GroupsNameContainer.loadData(newProps);
newProps.loadAsync();
}
}

static loadData = ({ loadGroupIfNeeded }) => {
loadGroupIfNeeded();
static loadAsync = ({ groupId }, dispatch) => {
dispatch(fetchPublicGroupIfNeeded(groupId));
};

render() {
Expand All @@ -38,14 +38,15 @@ class GroupsNameContainer extends Component {
GroupsNameContainer.propTypes = {
groupId: PropTypes.string.isRequired,
group: ImmutablePropTypes.map,
noLink: PropTypes.bool
noLink: PropTypes.bool,
loadAsync: PropTypes.func.isRequired
};

export default connect(
(state, { groupId }) => ({
group: publicGroupSelector(groupId)(state)
}),
(dispatch, { groupId }) => ({
loadGroupIfNeeded: () => dispatch(fetchPublicGroupIfNeeded(groupId))
loadAsync: () => GroupsNameContainer.loadAsync({ groupId }, dispatch)
})
)(GroupsNameContainer);
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import LicencesTable from '../../components/Instances/LicencesTable';
import { fetchInstanceLincences } from '../../redux/modules/licences';
import { getLicencesOfInstance } from '../../redux/selectors/licences';

import { clientOnly } from '../../helpers/clientOnly';

class LicencesTableContainer extends Component {
static loadAsync = ({ instanceId }, dispatch) =>
dispatch(fetchInstanceLincences(instanceId));
Expand Down Expand Up @@ -44,8 +42,6 @@ export default connect(
}),
(dispatch, { instance }) => ({
loadAsync: () =>
clientOnly(() =>
LicencesTableContainer.loadAsync({ instanceId: instance.id }, dispatch)
)
LicencesTableContainer.loadAsync({ instanceId: instance.id }, dispatch)
})
)(LicencesTableContainer);
12 changes: 5 additions & 7 deletions src/containers/UsersNameContainer/UsersNameContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ import UsersName, {
LoadingUsersName,
FailedUsersName
} from '../../components/Users/UsersName';
import { clientOnly } from '../../helpers/clientOnly';

class UsersNameContainer extends Component {
componentWillMount() {
this.props.loadData();
this.props.loadAsync();
}

componentWillReceiveProps(newProps) {
if (this.props.userId !== newProps.userId) {
newProps.loadData();
newProps.loadAsync();
}
}

static loadData = (userId, dispatch) => {
static loadAsync = ({ userId }, dispatch) => {
dispatch(fetchProfileIfNeeded(userId));
};

Expand Down Expand Up @@ -56,7 +55,7 @@ UsersNameContainer.propTypes = {
large: PropTypes.bool,
user: ImmutablePropTypes.map,
noLink: PropTypes.bool,
loadData: PropTypes.func.isRequired
loadAsync: PropTypes.func.isRequired
};

export default connect(
Expand All @@ -66,7 +65,6 @@ export default connect(
}),
(dispatch, { userId }) => ({
loadProfileIfNeeded: () => dispatch(fetchProfileIfNeeded(userId)),
loadData: () =>
clientOnly(() => UsersNameContainer.loadData(userId, dispatch))
loadAsync: () => UsersNameContainer.loadAsync({ userId }, dispatch)
})
)(UsersNameContainer);
1 change: 0 additions & 1 deletion src/helpers/clientOnly.js

This file was deleted.

6 changes: 2 additions & 4 deletions src/pages/Exercise/Exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import { exercisePipelinesSelector } from '../../redux/selectors/pipelines';
import { loggedInUserIdSelector } from '../../redux/selectors/auth';
import { supervisorOfSelector } from '../../redux/selectors/groups';

import { clientOnly } from '../../helpers/clientOnly';
import withLinks from '../../hoc/withLinks';
import { getLocalizedName } from '../../helpers/getLocalizedData';

Expand All @@ -77,7 +76,7 @@ const messages = defineMessages({
class Exercise extends Component {
state = { forkId: null };

static loadAsync = (dispatch, exerciseId) =>
static loadAsync = ({ exerciseId }, dispatch) =>
Promise.all([
dispatch(fetchExerciseIfNeeded(exerciseId)),
dispatch(fetchReferenceSolutionsIfNeeded(exerciseId)),
Expand Down Expand Up @@ -468,8 +467,7 @@ export default withLinks(
};
},
(dispatch, { params: { exerciseId } }) => ({
loadAsync: () =>
clientOnly(() => Exercise.loadAsync(dispatch, exerciseId)),
loadAsync: () => Exercise.loadAsync({ exerciseId }, dispatch),
assignExercise: groupId =>
dispatch(assignExercise(groupId, exerciseId)),
push: url => dispatch(push(url)),
Expand Down
4 changes: 1 addition & 3 deletions src/pages/ReferenceSolution/ReferenceSolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Row, Col, Button } from 'react-bootstrap';

import withLinks from '../../hoc/withLinks';
import Page from '../../components/layout/Page';
import { clientOnly } from '../../helpers/clientOnly';

import {
fetchReferenceSolutionsIfNeeded,
Expand Down Expand Up @@ -212,8 +211,7 @@ export default withLinks(
referenceSolutions: referenceSolutionsSelector(exerciseId)(state)
}),
(dispatch, { params }) => ({
loadAsync: () =>
clientOnly(() => ReferenceSolution.loadAsync(params, dispatch)),
loadAsync: () => ReferenceSolution.loadAsync(params, dispatch),
refreshSolutionEvaluations: () => {
dispatch(fetchReferenceSolutions(params.exerciseId));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ImmutablePropTypes from 'react-immutable-proptypes';

import withLinks from '../../hoc/withLinks';
import Page from '../../components/layout/Page';
import { clientOnly } from '../../helpers/clientOnly';

import { fetchReferenceSolutionsIfNeeded } from '../../redux/modules/referenceSolutions';
import { referenceSolutionsSelector } from '../../redux/selectors/referenceSolutions';
Expand Down Expand Up @@ -162,9 +161,7 @@ export default withLinks(
}),
(dispatch, { params }) => ({
loadAsync: () =>
clientOnly(() =>
ReferenceSolutionEvaluation.loadAsync(params, dispatch)
),
ReferenceSolutionEvaluation.loadAsync(params, dispatch),
downloadEvaluationArchive: e => {
e.preventDefault();
dispatch(downloadEvaluationArchive(params.evaluationId));
Expand Down
3 changes: 1 addition & 2 deletions src/pages/Submission/Submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
isSuperAdmin
} from '../../redux/selectors/users';
import { loggedInUserIdSelector } from '../../redux/selectors/auth';
import { clientOnly } from '../../helpers/clientOnly';
import { getLocalizedName } from '../../helpers/getLocalizedData';

class Submission extends Component {
Expand Down Expand Up @@ -150,7 +149,7 @@ export default injectIntl(
isSuperAdmin(loggedInUserIdSelector(state))(state)
}),
(dispatch, { params }) => ({
loadAsync: () => clientOnly(() => Submission.loadAsync(params, dispatch))
loadAsync: () => Submission.loadAsync(params, dispatch)
})
)(Submission)
);
3 changes: 2 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const renderWithoutSSR = (res, renderProps) => {
};

const renderPage = (res, store, renderProps) => {
let reduxState = serialize(store.getState(), { isJSON: true });
let html = renderToString(
<Provider store={store}>
<RouterContext {...renderProps} />
Expand All @@ -69,7 +70,7 @@ const renderPage = (res, store, renderProps) => {
res.render('index', {
html,
head,
reduxState: serialize(store.getState(), { isJSON: true }),
reduxState,
bundle,
style: '/style.css'
});
Expand Down