Basic dashboard components (#562)
* Case sensitive renaming * Update `cvat-js` lib. * Add `.env` file * Add basic redux capabilities * Remove `setTimeout` as it was fixes in `cvat-js` * Remove redundant state fieldmain
parent
0efd665f90
commit
9651a19c7e
@ -0,0 +1,8 @@
|
||||
REACT_APP_VERSION=${npm_package_version}
|
||||
REACT_APP_API_PROTOCOL=http
|
||||
REACT_APP_API_HOST=localhost
|
||||
REACT_APP_API_PORT=7000
|
||||
REACT_APP_API_HOST_URL=${REACT_APP_API_PROTOCOL}://${REACT_APP_API_HOST}:${REACT_APP_API_PORT}
|
||||
REACT_APP_API_FULL_URL=${REACT_APP_API_PROTOCOL}://${REACT_APP_API_HOST}:${REACT_APP_API_PORT}/api/v1
|
||||
REACT_APP_LOGIN=admin
|
||||
REACT_APP_PASSWORD=admin
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,13 @@
|
||||
export const loginAction = () => (dispatch: any) => {
|
||||
dispatch({
|
||||
type: 'LOGIN',
|
||||
payload: true,
|
||||
})
|
||||
}
|
||||
|
||||
export const logoutAction = () => (dispatch: any) => {
|
||||
dispatch({
|
||||
type: 'LOGOUT',
|
||||
payload: false,
|
||||
})
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
import React, { Component } from 'react';
|
||||
import { BrowserRouter as Router, Route, Redirect } from 'react-router-dom';
|
||||
|
||||
import Dashboard from '../dashboard/dashboard';
|
||||
|
||||
import './app.scss';
|
||||
|
||||
declare const window: any;
|
||||
|
||||
interface AppState {
|
||||
isLoggedIn: boolean;
|
||||
}
|
||||
|
||||
class App extends Component<any, AppState> {
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
isLoggedIn: false
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
window.cvat.server.login('admin', 'admin').then(
|
||||
(_response: any) => {
|
||||
this.setState({ isLoggedIn: true });
|
||||
},
|
||||
(_error: any) => {
|
||||
this.setState({ isLoggedIn: false });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
return(
|
||||
<Router>
|
||||
<div>
|
||||
<Redirect from="/" to="dashboard" />
|
||||
<Route path="/dashboard" component={ Dashboard } />
|
||||
</div>
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
||||
@ -0,0 +1,46 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
import { BrowserRouter as Router, Route, Redirect } from 'react-router-dom';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import Dashboard from '../dashboard/dashboard';
|
||||
|
||||
import { loginAction, logoutAction } from '../../actions/authentication-action';
|
||||
|
||||
import './app.scss';
|
||||
|
||||
declare const window: any;
|
||||
|
||||
const mapDispatchToProps = (dispatch: any) => ({
|
||||
login: () => { dispatch(loginAction()) },
|
||||
logout: () => { dispatch(logoutAction()) },
|
||||
})
|
||||
|
||||
const mapStateToProps = (state: any) => ({
|
||||
...state.authenticateReducer,
|
||||
})
|
||||
|
||||
class App extends PureComponent<any, any> {
|
||||
componentDidMount() {
|
||||
window.cvat.server.login(process.env.REACT_APP_LOGIN, process.env.REACT_APP_PASSWORD).then(
|
||||
(_response: any) => {
|
||||
this.props.login();
|
||||
},
|
||||
(_error: any) => {
|
||||
this.props.logout();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
return(
|
||||
<Router>
|
||||
<div>
|
||||
<Redirect from="/" to="dashboard" />
|
||||
<Route path="/dashboard" component={ Dashboard } />
|
||||
</div>
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(App);
|
||||
@ -0,0 +1,10 @@
|
||||
export default (state = {}, action: any) => {
|
||||
switch (action.type) {
|
||||
case 'LOGIN':
|
||||
return { ...state, isLoggedIn: action.payload };
|
||||
case 'LOGOUT':
|
||||
return { ...state, isLoggedIn: action.payload };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
import { combineReducers } from 'redux';
|
||||
|
||||
import authenticationReducer from './authenticate-reducer';
|
||||
|
||||
export default combineReducers({
|
||||
authenticationReducer,
|
||||
});
|
||||
@ -0,0 +1,19 @@
|
||||
import { createStore, applyMiddleware, compose } from 'redux';
|
||||
import thunk from 'redux-thunk';
|
||||
|
||||
import rootReducer from './reducers/root-reducer';
|
||||
|
||||
export default function configureStore(initialState = {}) {
|
||||
return createStore(
|
||||
rootReducer,
|
||||
initialState,
|
||||
compose(
|
||||
applyMiddleware(thunk),
|
||||
(window as any).__REDUX_DEVTOOLS_EXTENSION__
|
||||
?
|
||||
(window as any).__REDUX_DEVTOOLS_EXTENSION__({ trace: true })
|
||||
:
|
||||
(f: any) => f
|
||||
)
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue