Skip to content
This repository was archived by the owner on Mar 3, 2020. It is now read-only.

Commit 70e1a8a

Browse files
committed
Fixes Series SSR
1 parent 1cf90b2 commit 70e1a8a

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

velog-frontend/src/containers/series/SeriesContainer.js

+4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import SeriesTemplate from '../../components/series/SeriesTemplate/SeriesTemplat
1212
type Props = {
1313
series: ?SeriesData,
1414
editing: boolean,
15+
shouldCancel: boolean,
1516
} & ContextRouter;
1617

1718
class SeriesContainer extends Component<Props> {
1819
initialize = async () => {
20+
if (!this.props.shouldCancel) return;
21+
SeriesActions.initialize();
1922
const { username, urlSlug } = this.props.match.params;
2023
if (!username || !urlSlug) return;
2124
try {
@@ -85,5 +88,6 @@ export default withRouter(
8588
connect((state: State) => ({
8689
series: state.series.series,
8790
editing: state.series.editing,
91+
shouldCancel: state.common.ssr && !state.common.router.altered,
8892
}))(SeriesContainer),
8993
);

velog-frontend/src/containers/user/UserSeriesContainer.js

+3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import { type SeriesItemData } from 'store/modules/profile';
99

1010
type Props = {
1111
seriesList: ?(SeriesItemData[]),
12+
shouldCancel: boolean,
1213
} & ContextRouter;
1314
class UserSeriesContainer extends Component<Props> {
1415
initialize = async () => {
16+
if (this.props.shouldCancel) return;
1517
const { username } = this.props.match.params;
1618
try {
1719
if (!username) return;
@@ -38,4 +40,5 @@ class UserSeriesContainer extends Component<Props> {
3840

3941
export default connect((state: State) => ({
4042
seriesList: state.profile.seriesList,
43+
shouldCancel: state.common.ssr && !state.common.router.altered,
4144
}))(withRouter(UserSeriesContainer));

velog-frontend/src/routeConfig.js

+39
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { actionCreators as profileActions } from 'store/modules/profile';
55
import { actionCreators as listingActions } from 'store/modules/listing';
66
import { actionCreators as commonActions } from 'store/modules/common';
77
import { actionCreators as followActions } from 'store/modules/follow';
8+
import { actionCreators as seriesActions } from 'store/modules/series';
9+
810
import { bindActionCreators } from 'redux';
911
import type { State } from 'store';
1012
import { type Match } from 'react-router';
@@ -154,6 +156,43 @@ const routes = [
154156
},
155157
stop: true,
156158
},
159+
{
160+
path: '/@:username/series/:urlSlug',
161+
preload: async (ctx: any, { dispatch, getState }: any, match: Match) => {
162+
const SeriesActions = bindActionCreators(seriesActions, dispatch);
163+
const { username, urlSlug } = match.params;
164+
if (!username || !urlSlug) return null;
165+
return SeriesActions.getSeries({
166+
username,
167+
urlSlug,
168+
});
169+
},
170+
stop: true,
171+
},
172+
{
173+
path: '/@:username/series',
174+
exact: true,
175+
preload: async (ctx: any, { dispatch, getState }: any, match: Match) => {
176+
const { username } = match.params;
177+
const ProfileActions = bindActionCreators(profileActions, dispatch);
178+
const FollowActions = bindActionCreators(followActions, dispatch);
179+
if (!username) return null;
180+
ProfileActions.setSideVisibility(false);
181+
await Promise.all([
182+
ProfileActions.getProfile(username),
183+
ProfileActions.getSeriesList(username),
184+
]);
185+
const state: State = getState();
186+
const { profile } = state.profile;
187+
if (profile) {
188+
if (ctx.state.logged) {
189+
await FollowActions.getUserFollow(profile.id);
190+
}
191+
}
192+
return Promise.resolve();
193+
},
194+
stop: true,
195+
},
157196
{
158197
path: '/@:username/:urlSlug',
159198
component: Post,

0 commit comments

Comments
 (0)