Add workaround for landing page.
This commit is contained in:
parent
6fed7ad718
commit
68d1b9d52c
|
@ -15,7 +15,6 @@ import {UserInfo} from './user_info';
|
|||
import {DEFAULT_USER_LOGIN} from './reducers';
|
||||
|
||||
export const LOAD_PAGE_ACTION = 'LOAD_ARTICLE';
|
||||
export const LOAD_MENU_ACTION = 'LOAD_MENU';
|
||||
export const UPDATE_SITE_INFO_ACTION = 'UPDATE_APP_SITE_INFO';
|
||||
export const LOAD_INITIAL_USER_ACTION = 'INITIAL_USER';
|
||||
export const UPDATE_USER_ACTION = 'UPDATE_USER';
|
||||
|
@ -24,6 +23,11 @@ export const LOAD_THEME_ACTION = 'LOAD_THEME';
|
|||
export const SWITCH_THEME_ACTION = 'SWITCH_THEME';
|
||||
|
||||
export function fetchPage(pageSlug='') {
|
||||
if (pageSlug === '' || pageSlug === undefined) {
|
||||
// TODO: Fix crappy workaround.
|
||||
return {type: 'DO_NOTHING'};
|
||||
}
|
||||
|
||||
return async (dispatch) => {
|
||||
|
||||
const response = await fetch(`/api/pages/${pageSlug}`);
|
||||
|
|
|
@ -14,7 +14,7 @@ import {BrowserRouter} from 'react-router-dom';
|
|||
import {Provider} from 'preact-redux';
|
||||
|
||||
import appStore from './store';
|
||||
import {fetchPage, fetchSiteInfo, initialUser, loadTheme} from './actions';
|
||||
import {fetchSiteInfo, initialUser, loadTheme} from './actions';
|
||||
import {RookeriesApp} from './containers/App';
|
||||
|
||||
// Initialize application
|
||||
|
@ -22,9 +22,6 @@ appStore.dispatch(fetchSiteInfo());
|
|||
appStore.dispatch(initialUser());
|
||||
appStore.dispatch(loadTheme());
|
||||
|
||||
const location = window.location.pathname.substring(1);
|
||||
appStore.dispatch(fetchPage(location));
|
||||
|
||||
const RookeriesApp_ = (
|
||||
<Provider store={ appStore }>
|
||||
<BrowserRouter>
|
||||
|
|
|
@ -30,6 +30,7 @@ const DEFAULT_SITE_INFO = {
|
|||
},
|
||||
name: 'Rookeries',
|
||||
menu: [],
|
||||
landingPage: '',
|
||||
};
|
||||
|
||||
function siteInfoStateReducer(state = {...DEFAULT_SITE_INFO}, action) {
|
||||
|
|
|
@ -85,6 +85,13 @@ export class EditableMarkdownBlock extends Component {
|
|||
|
||||
componentDidMount() {
|
||||
let pageToLoad = this.props.match.params.pageId;
|
||||
if (pageToLoad === undefined || pageToLoad === '') {
|
||||
const landingPage = appStore.getState().site.landingPage;
|
||||
if (landingPage !== undefined || landingPage === '') {
|
||||
appStore.dispatch(fetchPage(landingPage));
|
||||
}
|
||||
}
|
||||
|
||||
appStore.dispatch(fetchPage(pageToLoad));
|
||||
this.updateEditAllowance(this.props.userCanEdit);
|
||||
}
|
||||
|
@ -92,6 +99,15 @@ export class EditableMarkdownBlock extends Component {
|
|||
componentWillReceiveProps(nextProps) {
|
||||
const {match} = this.props;
|
||||
if (match.params.pageId !== nextProps.match.params.pageId) {
|
||||
|
||||
const pageToLoad = nextProps.match.params.pageId;
|
||||
if (pageToLoad === undefined || pageToLoad === '') {
|
||||
const landingPage = appStore.getState().site.landingPage;
|
||||
if (landingPage !== undefined || landingPage === '') {
|
||||
appStore.dispatch(fetchPage(landingPage));
|
||||
}
|
||||
}
|
||||
|
||||
appStore.dispatch(fetchPage(nextProps.match.params.pageId));
|
||||
}
|
||||
this.setState({
|
||||
|
|
Loading…
Reference in New Issue