Skip to content

Commit 8aa3044

Browse files
committed
migration
1 parent 118c546 commit 8aa3044

File tree

82 files changed

+3354
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+3354
-0
lines changed

front/src/Root.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// @flow
2+
3+
// #region imports
4+
import React, { Component, Fragment } from 'react';
5+
import { Router, Switch, Route } from 'react-router-dom';
6+
import compose from 'recompose/compose';
7+
import createHistory from 'history/createBrowserHistory';
8+
import withMainLayout from './hoc/withMainLayout';
9+
import MainRoutes from './routes/MainRoutes';
10+
import ScrollToTop from './components/scrollToTop/ScrollToTop';
11+
import LogoutRoute from './components/logoutRoute';
12+
import AuthProvider from './contexts/auth/providerComponent';
13+
import { devToolsStore } from './contexts/withDevTools';
14+
import Login from './pages/login';
15+
import GlobalStyle from './style/GlobalStyles';
16+
// #endregion
17+
18+
// #region flow types
19+
type Props = any;
20+
type State = any;
21+
// #endregion
22+
23+
// #region constants
24+
const MainApp = compose(withMainLayout())(MainRoutes);
25+
26+
const history = createHistory();
27+
// #endregion
28+
29+
class Root extends Component<Props, State> {
30+
componentDidMount() {
31+
// init devTools (so that will be visible in Chrome redux devtools tab):
32+
devToolsStore && devToolsStore.init();
33+
}
34+
35+
render() {
36+
return (
37+
<Router history={history}>
38+
<Fragment>
39+
<GlobalStyle />
40+
<AuthProvider>
41+
<ScrollToTop>
42+
<Switch>
43+
<Route exact path="/login" component={Login} />
44+
{/* Application with main layout (could have multiple applications with different layouts) */}
45+
<MainApp />
46+
{/* logout: just redirects to login (App will take care of removing the token) */}
47+
<LogoutRoute path="/logout" />
48+
</Switch>
49+
</ScrollToTop>
50+
</AuthProvider>
51+
</Fragment>
52+
</Router>
53+
);
54+
}
55+
}
56+
57+
export default Root;
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// @flow
2+
/* eslint-disable no-undefined */
3+
4+
// #region imports
5+
import React, { Component } from 'react';
6+
import BackToTopButton from './backToTopButton/BackToTopButton';
7+
import { Motion, spring, presets } from 'react-motion';
8+
// #endregion
9+
10+
// #region flow types
11+
type Props = {
12+
minScrollY: number,
13+
scrollTo?: string,
14+
onScrollDone?: () => any,
15+
};
16+
17+
type State = {
18+
windowScrollY: number,
19+
showBackButton: boolean,
20+
tickingScollObserve: boolean,
21+
};
22+
// #endregion
23+
24+
class BackToTop extends Component<Props, State> {
25+
static defaultProps = {
26+
minScrollY: 120,
27+
onScrollDone: () => {},
28+
};
29+
30+
state = {
31+
windowScrollY: 0,
32+
showBackButton: false,
33+
tickingScollObserve: false,
34+
};
35+
36+
// #region lifecycle methods
37+
componentDidMount() {
38+
if (typeof window !== 'undefined') {
39+
window.addEventListener('scroll', this.handleWindowScroll);
40+
}
41+
}
42+
43+
componentWillUnmount() {
44+
if (typeof window !== 'undefined') {
45+
window.removeEventListener('scroll', this.handleWindowScroll);
46+
}
47+
}
48+
49+
render() {
50+
const { showBackButton } = this.state;
51+
return (
52+
<Motion style={{ x: spring(showBackButton ? 0 : 120, presets.stiff) }}>
53+
{({ x }) => (
54+
<BackToTopButton
55+
position={'bottom-right'}
56+
onClick={this.handlesOnBackButtonClick}
57+
motionStyle={{
58+
WebkitTransform: `translate3d(${x}px, 0, 0)`,
59+
transform: `translate3d(${x}px, 0, 0)`,
60+
}}
61+
/>
62+
)}
63+
</Motion>
64+
);
65+
}
66+
// #endregion
67+
68+
// #region on windows scroll callback
69+
handleWindowScroll = () => {
70+
if (window) {
71+
const { windowScrollY, tickingScollObserve } = this.state;
72+
const { minScrollY } = this.props;
73+
74+
/* eslint-disable no-undefined */
75+
const currentWindowScrollY =
76+
window.pageYOffset !== undefined
77+
? window.pageYOffset
78+
: (
79+
document.documentElement ||
80+
document.body.parentNode ||
81+
document.body
82+
).scrollTop;
83+
/* eslint-enable no-undefined */
84+
85+
// scroll event fires to often, using window.requestAnimationFrame to limit computations
86+
if (!tickingScollObserve) {
87+
window.requestAnimationFrame(() => {
88+
if (windowScrollY !== currentWindowScrollY) {
89+
const shouldShowBackButton =
90+
currentWindowScrollY >= minScrollY ? true : false;
91+
92+
this.setState({
93+
windowScrollY: currentWindowScrollY,
94+
showBackButton: shouldShowBackButton,
95+
});
96+
}
97+
this.setState({ tickingScollObserve: false });
98+
});
99+
}
100+
101+
this.setState({ tickingScollObserve: true });
102+
}
103+
};
104+
// #endregion
105+
106+
// #region on button click (smooth scroll)
107+
handlesOnBackButtonClick = (event: SyntheticEvent<>) => {
108+
if (event) {
109+
event.preventDefault();
110+
}
111+
const { minScrollY } = this.props;
112+
const { windowScrollY } = this.state;
113+
114+
if (window && windowScrollY && windowScrollY > minScrollY) {
115+
// using here smoothscroll-polyfill
116+
window.scroll({ top: 0, left: 0, behavior: 'smooth' });
117+
// smoothScroll.scrollTo(scrollTo, this.scrollDone);
118+
}
119+
};
120+
121+
scrollDone = () => {
122+
const { onScrollDone } = this.props;
123+
if (onScrollDone) {
124+
onScrollDone();
125+
}
126+
};
127+
// #endregion
128+
}
129+
130+
export default BackToTop;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// @flow
2+
3+
// #region imports
4+
import React from 'react';
5+
import renderer from 'react-test-renderer'; // needed both for snpashot testing but also to prevent errors from enzyme
6+
import BackToTop from '../BackToTop';
7+
// #endregion
8+
9+
describe('BackToTop component', () => {
10+
it('renders as expected', () => {
11+
const props = {
12+
minScrollY: 10,
13+
scrollTo: null,
14+
onScrollDone: () => {},
15+
};
16+
17+
const component = renderer
18+
.create(
19+
<div>
20+
<BackToTop {...props} />
21+
</div>,
22+
)
23+
.toJSON();
24+
expect(component).toMatchSnapshot();
25+
});
26+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`BackToTop component renders as expected 1`] = `
4+
<div>
5+
<button
6+
className="btn"
7+
onClick={[Function]}
8+
style={
9+
Object {
10+
"WebkitTransform": "translate3d(120px, 0, 0)",
11+
"backgroundColor": "#4A4A4A",
12+
"bottom": "40px",
13+
"left": "",
14+
"opacity": 0.5,
15+
"position": "fixed",
16+
"right": "-10px",
17+
"transform": "translate3d(120px, 0, 0)",
18+
"width": "100px",
19+
"zIndex": 10,
20+
}
21+
}
22+
>
23+
<div
24+
className="sc-bdVaJa eYqzQM"
25+
>
26+
<svg
27+
fill="#F1F1F1"
28+
height="24px"
29+
viewBox="0 0 512 512"
30+
width="24px"
31+
>
32+
<path
33+
d="M256,213.7L256,213.7L256,213.7l174.2,167.2c4.3,4.2,11.4,4.1,15.8-0.2l30.6-29.9c4.4-4.3,4.5-11.3,0.2-15.5L264.1,131.1 c-2.2-2.2-5.2-3.2-8.1-3c-3-0.1-5.9,0.9-8.1,3L35.2,335.3c-4.3,4.2-4.2,11.2,0.2,15.5L66,380.7c4.4,4.3,11.5,4.4,15.8,0.2L256,213.7z"
34+
/>
35+
</svg>
36+
</div>
37+
</button>
38+
</div>
39+
`;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// @flow
2+
3+
// #region imports
4+
import React from 'react';
5+
import cx from 'classnames';
6+
import UpIcon from './UpIcon';
7+
import WithRightMargin from './styled/WithRightMargin';
8+
// #endregion
9+
10+
// #region flow types
11+
type Props = {
12+
position: 'bottom-left' | 'bottom-right',
13+
onClick: (event: SyntheticEvent<>) => any,
14+
children: any,
15+
motionStyle: any,
16+
...any,
17+
};
18+
// #endregion
19+
20+
// #region constants
21+
const defaultBackGroundColor = '#4A4A4A';
22+
const sideOffset = '-10px';
23+
const bottomOffset = '40px';
24+
const defaultWidth = '100px';
25+
const defaultZindex = 10;
26+
const defaultOpacity = 0.5;
27+
const defaultStyle = {
28+
position: 'fixed',
29+
right: sideOffset,
30+
left: '',
31+
bottom: bottomOffset,
32+
width: defaultWidth,
33+
zIndex: defaultZindex,
34+
opacity: defaultOpacity,
35+
backgroundColor: defaultBackGroundColor,
36+
};
37+
// #endregion
38+
39+
const BackToTopButton = ({
40+
onClick,
41+
position,
42+
children,
43+
motionStyle,
44+
}: Props) => {
45+
const buttonStyle = setPosition(position, {
46+
...motionStyle,
47+
...defaultStyle,
48+
});
49+
50+
return (
51+
<button
52+
style={buttonStyle}
53+
className={cx({
54+
btn: true,
55+
})}
56+
onClick={onClick}
57+
>
58+
{!children && (
59+
<WithRightMargin>
60+
<UpIcon color={'#F1F1F1'} />
61+
</WithRightMargin>
62+
)}
63+
{!!children && children}
64+
</button>
65+
);
66+
};
67+
68+
// #region statics
69+
BackToTopButton.defaultProps = {
70+
position: 'bottom-right',
71+
};
72+
73+
BackToTopButton.displayName = 'BackToTopButton';
74+
// #endregion
75+
76+
// #region helpers
77+
function setPosition(position = 'bottom-right', refStyle = defaultStyle): any {
78+
const style = { ...refStyle };
79+
80+
switch (position) {
81+
case 'bottom-right':
82+
style.right = sideOffset;
83+
style.left = '';
84+
return style;
85+
86+
case 'bottom-left':
87+
style.right = '';
88+
style.left = sideOffset;
89+
return style;
90+
91+
default:
92+
return refStyle;
93+
}
94+
}
95+
// #endregion
96+
97+
export default BackToTopButton;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @flow
2+
3+
// #region imports
4+
import React from 'react';
5+
// #endregion
6+
7+
// #region flow types
8+
type Props = {
9+
color: string,
10+
};
11+
// #endregion
12+
13+
const UpIcon = ({ color }: Props) => {
14+
return (
15+
<svg width="24px" height="24px" viewBox="0 0 512 512" fill={`${color}`}>
16+
<path
17+
d="M256,213.7L256,213.7L256,213.7l174.2,167.2c4.3,4.2,11.4,4.1,15.8-0.2l30.6-29.9c4.4-4.3,4.5-11.3,0.2-15.5L264.1,131.1
18+
c-2.2-2.2-5.2-3.2-8.1-3c-3-0.1-5.9,0.9-8.1,3L35.2,335.3c-4.3,4.2-4.2,11.2,0.2,15.5L66,380.7c4.4,4.3,11.5,4.4,15.8,0.2L256,213.7z"
19+
/>
20+
</svg>
21+
);
22+
};
23+
24+
// #region statics
25+
UpIcon.defaultProps = {
26+
color: '#F1F1F1',
27+
};
28+
29+
UpIcon.displayName = 'UpIcon';
30+
// #endregion
31+
32+
export default UpIcon;

0 commit comments

Comments
 (0)