-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitcher.js
executable file
·66 lines (56 loc) · 1.38 KB
/
Switcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React from 'react'
//import { connect } from 'react-redux'
import universal from 'react-universal-component'
import isLoading from '../selectors/isLoading'
import { graphql } from 'react-apollo'
import gql from 'graphql-tag'
import styles from '../css/Switcher'
const UniversalComponent = universal(({page}) => import(`../page/${page}`), {
minDelay: 500,
loading: () => (
<div className={styles.spinner}>
<div/>
</div>
),
error: () => <div className={styles.notFound}>PAGE NOT FOUND - 404</div>
})
const Switcher = ({page, direction, isLoading, feedQuery}) => {
return (
<div className={styles.switcher}>
<UniversalComponent page={page} isLoading={isLoading}/>
</div>
)
}
/*
const mapStateToProps = state => ({
page: state.page,
direction: state.direction,
isLoading: isLoading(state)
})*/
const GET_PAGE = gql`
query getPage {
state {
page @client
}
}
`;
const WrappedComponent = graphql(GET_PAGE, {
props: ({data: {loading, error, state}}) => {
if (loading) {
return {loading};
}
console.log(loading)
console.log(state);
console.log(state.page);
if (error) {
return {error};
}
return {
loading: false,
direction: state.direction,
page:state.page
};
}
})(Switcher);
export default WrappedComponent;
//export default connect(mapStateToProps)(Switcher)