Commit e811216d authored by Viacheslav Pavlov's avatar Viacheslav Pavlov
Browse files

Fixed SSR

parent a90a0588
......@@ -9,7 +9,7 @@ export default function fetchComponentData(dispatch, branch, search) {
}
// Provide params to static needs
component.needs.map((need) => {
component.needs.filter((need) => need({ search, params: match.params })).map((need) => {
return dispatch(need({ search, params: match.params }));
})
// a nice array of Promises
......
......@@ -53,7 +53,7 @@ export const loadAccessionsPage = (page: IPageRequest) => (dispatch, getState) =
});
};
export const loadAccession = ({ uuid, doi }: { uuid: string, doi: string }) => (dispatch) => {
export const loadAccession = ({ uuid, doi }: { uuid?: string, doi?: string }) => (dispatch) => {
const loader = doi ? getByDoi : getByUuid;
const lookup = doi ? doi : uuid;
......
......@@ -35,9 +35,11 @@ export const removeAccessionFromMyList = (accUUID: string) => (dispatch, getStat
}
};
export const initMyList = (myList: any) => (dispatch) => {
if (myList.accessions) {
return dispatch(initAccessions(myList.accessions));
export const initMyList = () => (dispatch) => {
if (typeof window !== 'undefined') {
const myList = JSON.parse(window.localStorage.getItem('myList'));
if (myList && myList.accessions) {
return dispatch(initAccessions(myList.accessions));
}
}
return dispatch(initAccessions([]));
};
......@@ -21,7 +21,7 @@ interface IAppProps extends React.ClassAttributes<any> {
route: any;
location: any;
updateHistory: (path: string) => void;
initMyList: (myList: any) => void;
initMyList: () => void;
}
class App extends React.Component<IAppProps, any> {
......@@ -29,12 +29,9 @@ class App extends React.Component<IAppProps, any> {
public constructor(props: any) {
super(props);
}
public componentWillMount() {
public componentDidMount() {
const { initMyList } = this.props;
const myList = JSON.parse(window.localStorage.getItem('myList'));
if (myList) {
initMyList(myList);
}
initMyList();
}
public componentWillReceiveProps(nextProps) {
const {updateHistory} = this.props;
......
......@@ -39,7 +39,7 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
protected static needs = [
({ params: { uuid, doi } }) => {
return uuid || doi ? loadAccession({ uuid, doi: `10.${doi}` }) : null;
return doi ? loadAccession({ doi: `10.${doi}` }) : loadAccession({ uuid });
},
];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment