diff --git a/src/api/index.ts b/src/api/index.ts index 951f45c..ee6aefc 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -9,6 +9,11 @@ export interface AssetManifest { } class Api { + + public getSubjects(){ + return Connector.get('odata/subjects'); + } + public getModules() { return Connector.get('odata/taskModules'); } @@ -70,4 +75,4 @@ class Api { private url = (ID: number, file: string) => `odata/taskModules(${ID})/download(path='${file}')`; } -export default new Api(); \ No newline at end of file +export default new Api(); diff --git a/src/app/menus/MainMenu.tsx b/src/app/menus/MainMenu.tsx index 71ef8ef..f958ab8 100644 --- a/src/app/menus/MainMenu.tsx +++ b/src/app/menus/MainMenu.tsx @@ -11,6 +11,11 @@ export const mainListItems = (logged: boolean, onClick: () => void) => ( Вход )} + {logged && ( + + Тест + + )} {logged && ( Результаты @@ -22,4 +27,4 @@ export const mainListItems = (logged: boolean, onClick: () => void) => ( )} -); \ No newline at end of file +); diff --git a/src/app/pages/Modules/index.tsx b/src/app/pages/Modules/index.tsx index 83a0c16..79a5b1e 100644 --- a/src/app/pages/Modules/index.tsx +++ b/src/app/pages/Modules/index.tsx @@ -48,6 +48,7 @@ class Modules extends Component { } public render() { + console.log(this.props); return ( diff --git a/src/app/pages/Test/TTable.ts b/src/app/pages/Test/TTable.ts new file mode 100644 index 0000000..ed6a2b7 --- /dev/null +++ b/src/app/pages/Test/TTable.ts @@ -0,0 +1,4 @@ +import GTable from "../../containers/Table"; +import {Subject} from "../../../redux/reducers/test"; + +export default class extends GTable {} diff --git a/src/app/pages/Test/index.tsx b/src/app/pages/Test/index.tsx new file mode 100644 index 0000000..ec8f623 --- /dev/null +++ b/src/app/pages/Test/index.tsx @@ -0,0 +1,72 @@ +import * as React from 'react'; +import {Component} from "react"; +import {Col, Container, Row} from "reactstrap"; +import {connect} from "react-redux"; +import {RootState} from "../../../redux/rootReducer"; +import {actions} from "../../../redux/actions"; +import {Subject, TestState} from "../../../redux/reducers/test"; +import AsyncWrapper from "../../containers/AsyncWrapper"; +// import {RouteComponentProps, withRouter} from "react-router"; +import {InjectedAuthRouterProps} from "redux-auth-wrapper/history3/redirect"; +import T from './TTable'; +import {AppState} from "../../../redux/reducers/state"; + +interface DispatchProps { + getSubjects: any; +} + +interface StateToProps { + test: TestState; + state: AppState; +} + +type Props = DispatchProps & StateToProps & InjectedAuthRouterProps; +class Test extends Component { + + constructor(props: Props) { + super(props); + } + + public render() { + // console.log(this.props); + + return ( + + +

+ Темы +

+ + + + +
+
); + } + + private renderer(row: Subject) { + return ( + + + {row.id} + + {row.name} + {row.description} + ); + } +} + +const mapStateToProps = (state: RootState) => ({ + test: state.test, + state: state.state, +}); + +const mapDispatchToProps = { + getSubjects: actions.getSubjects, +}; + +export default connect(mapStateToProps, mapDispatchToProps)(Test); diff --git a/src/app/router/Routes.tsx b/src/app/router/Routes.tsx index 949d03f..13e1939 100644 --- a/src/app/router/Routes.tsx +++ b/src/app/router/Routes.tsx @@ -8,6 +8,7 @@ import Results from "../pages/Results"; import { connectedRouterRedirect } from 'redux-auth-wrapper/history4/redirect'; import {RootState} from "../../redux/rootReducer"; import Upload from '../pages/Upload'; +import Test from '../pages/Test'; // tslint:disable @@ -26,6 +27,7 @@ const Routes = () => ( + @@ -34,4 +36,4 @@ const Routes = () => ( ); -export default Routes; \ No newline at end of file +export default Routes; diff --git a/src/index.tsx b/src/index.tsx index 01cdbfc..36322b3 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -7,8 +7,12 @@ import {init} from "./lib/connector"; import {Promise} from 'bluebird'; global.Promise = Promise; +// init({ +// hostBase: 'http://gl-backend.svtz.ru:5000/' +// }); + init({ - hostBase: 'http://gl-backend.svtz.ru:5000/' + hostBase: 'http://bab320a0.ngrok.io/' }); ReactDOM.render( diff --git a/src/redux/actions/index.ts b/src/redux/actions/index.ts index ad26ab8..72ff7a0 100644 --- a/src/redux/actions/index.ts +++ b/src/redux/actions/index.ts @@ -3,6 +3,7 @@ import { state } from './state'; import {createServiceAction} from "./actionCreators"; import {results} from "./results"; import {user} from './user'; +import {test} from './test'; export enum ACTION_TYPES { GET= 'get', @@ -13,11 +14,13 @@ export enum ACTION_TYPES { } export const actions = { + ...test, ...modules, ...state, ...results, ...user, + ...createServiceAction('Subject', [ACTION_TYPES.GET]), ...createServiceAction('TaskModule', [ACTION_TYPES.GET, ACTION_TYPES.GET_ONE]), ...createServiceAction('TaskVariantLog', [ACTION_TYPES.GET]), ...createServiceAction('Me', [ACTION_TYPES.GET_ONE]), -}; \ No newline at end of file +}; diff --git a/src/redux/actions/test.ts b/src/redux/actions/test.ts new file mode 100644 index 0000000..ec29a97 --- /dev/null +++ b/src/redux/actions/test.ts @@ -0,0 +1,25 @@ +import {Dispatch} from 'redux'; +import {actions} from './index'; +import {Validation} from 'fp-ts/lib/Validation'; +import api from '../../api'; +import {Subject} from "../reducers/test"; + +export const test = { + getSubjects: () => { + return (dispatch: Dispatch) => { + dispatch(actions['getSubjectsAsyncStart']()); + api.getSubjects().then( + (res: Validation) => { + const data = res.getOrElse({}); + if (data.value){ + dispatch(actions['getSubjectsAsyncSuccess']({ + data: data.value + })); + }else{ + dispatch(actions['getSubjectsAsyncFail']()); + } + } + ); + } + } +}; diff --git a/src/redux/reducers/test.ts b/src/redux/reducers/test.ts new file mode 100644 index 0000000..37dcc53 --- /dev/null +++ b/src/redux/reducers/test.ts @@ -0,0 +1,26 @@ +import {Reducer} from "redux"; +import {createAsyncReducer} from "./asyncReducer"; +import {actions} from "../actions"; +import {IPageableState} from "../../types/redux"; + +export interface Subject { + id: number; + name: string; + description: string; +} + +// +// export interface Question { +// id: number; +// plain_text: string; +// description: string; +// } + + +export interface TestState extends IPageableState {} + +export const reducer: Reducer = createAsyncReducer({ + pending: actions['getSubjectsAsyncStart'], + fail: actions['getSubjectsAsyncFail'], + success: actions['getSubjectsAsyncSuccess'], +}); diff --git a/src/redux/rootReducer.ts b/src/redux/rootReducer.ts index 51ae0d0..1fb82f4 100644 --- a/src/redux/rootReducer.ts +++ b/src/redux/rootReducer.ts @@ -4,8 +4,10 @@ import {ModuleState, reducer as module} from "./reducers/module"; import {AppState, reducer as state} from "./reducers/state"; import {reducer as results, ResultsState} from "./reducers/results"; import {MyState, reducer as me} from './reducers/me'; +import {TestState, reducer as test} from "./reducers/test"; export interface RootState { + test: TestState; modules: ModulesState; module: ModuleState; state: AppState; @@ -16,10 +18,11 @@ export interface RootState { export const rootReducer: Reducer = combineReducers({ // i18n: i18nReducer, me, + test, modules, module, results, state, }); -export default rootReducer; \ No newline at end of file +export default rootReducer; diff --git a/src/redux/store.ts b/src/redux/store.ts index 94c0505..ea1fa27 100644 --- a/src/redux/store.ts +++ b/src/redux/store.ts @@ -5,8 +5,10 @@ import rootReducer, {RootState} from './rootReducer'; import {getInitialArray, getInitialObject} from "./reducers/asyncReducer"; import {ModuleData} from "./reducers/modules"; import {ResultData} from "./reducers/results"; +import {Subject} from "./reducers/test"; const initial = { + test: getInitialArray(), modules: getInitialArray(), module: getInitialObject(), state: { logged: false }, @@ -36,4 +38,4 @@ export function configureStore(initialState: RootState): Store { return stateStore; } -export const store = configureStore(initial); \ No newline at end of file +export const store = configureStore(initial);