Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions 05 SimpleApp_Navigation/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"env",
{
"modules": false
}
]
]
}
45 changes: 45 additions & 0 deletions 05 SimpleApp_Navigation/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "sample",
"version": "1.0.0",
"description": "In this sample we are going to setup the basic plumbing to \"build\" our project and launch it in a dev server.",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --mode development --inline --hot --open",
"build": "webpack --mode development",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/react": "^16.3.12",
"@types/react-dom": "^16.0.5",
"@types/react-redux": "^5.0.16",
"@types/react-router": "^3.0.15",
"@types/react-router-redux": "^4.0.51",
"@types/redux-thunk": "^2.1.0",
"awesome-typescript-loader": "^5.0.0",
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6.1",
"css-loader": "^0.28.11",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.4.0",
"style-loader": "^0.20.3",
"typescript": "^2.8.1",
"url-loader": "^1.0.1",
"webpack": "^4.5.0",
"webpack-cli": "^2.0.14",
"webpack-dev-server": "^3.1.0"
},
"dependencies": {
"babel-polyfill": "^6.26.0",
"bootstrap": "^4.1.0",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-redux": "^5.0.7",
"react-router": "^3.2.1",
"react-router-redux": "^4.0.8",
"redux": "^4.0.0",
"redux-thunk": "^2.2.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 06 Simple App
# 05 Simple App

This sample series takes as starting point _02 Change Name_

Expand Down Expand Up @@ -323,7 +323,8 @@ export const App = () => {
- import {NameEditContainer} from './nameEditContainer';
+ import { Link } from 'react-router'

export const App = (props: { children? }) => {
- export const App = () => {
+ export const App = (props: { children? }) => {
return (
<div>
- <HelloWorldContainer/>
Expand Down
20 changes: 20 additions & 0 deletions 05 SimpleApp_Navigation/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import { Link } from 'react-router';

export const App = (props: { children?}) => {
return (
<div>
<header>
Links:
{' '}
<Link to="/">Login</Link>
{' '}
<Link to="/student-list">Student List</Link>
{' '}
<Link to="/student-detail">Student Detail</Link>
</header>
<div style={{ marginTop: '1.5em' }}>{props.children}</div>
</div>
);
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

export const actionsEnums = {
USERPROFILE_UPDATE_EDITING_LOGIN: 'USERPROFILE_UPDATE_EDITING_LOGIN',
USERPROFILE_PERFORM_LOGIN : 'USERPROFILE_PERFORM_LOGIN'
}
USERPROFILE_PERFORM_LOGIN: 'USERPROFILE_PERFORM_LOGIN'
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
<title></title>
</head>
<body>
<h1>Sample app</h1>
<div id="root">
<div class="well">
<h1>Sample app</h1>
<div id="root">
</div>
</div>
</body>
</html>
</html>
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { createStore, applyMiddleware, compose } from 'redux';
import { Router, Route, IndexRoute, hashHistory } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux'
import { syncHistoryWithStore } from 'react-router-redux';
import { createStore, applyMiddleware, compose } from 'redux';
import reduxThunk from 'redux-thunk';
import { Provider } from 'react-redux';
import {reducers} from './reducers'
import {App} from './app';
import {LoginContainer} from './pages/login';
import {StudentListContainer} from './pages/student-list';
import {StudentDetailContainer} from './pages/student-detail';

import { reducers } from './reducers';
import { App } from './app';
import { LoginContainer } from './pages/login';
import { StudentListContainer } from './pages/student-list';
import { StudentDetailContainer } from './pages/student-detail';

const nonTypedWindow: any = window;
let store = createStore(
reducers,
compose(
applyMiddleware(reduxThunk),
window['devToolsExtension'] ? window['devToolsExtension']() : f => f
)
)
);

const history = syncHistoryWithStore(hashHistory, store);

ReactDOM.render(
<Provider store={store}>
<Provider store={store}>
<div>
<Router history={history}>
<Route path="/" component={App}>
<IndexRoute component={LoginContainer}/>
<Route path="login" component={LoginContainer}/>
<Route path="student-list" component={StudentListContainer}/>
<Route path="student-detail" component={StudentDetailContainer}/>
<IndexRoute component={LoginContainer} />
<Route path="login" component={LoginContainer} />
<Route path="student-list" component={StudentListContainer} />
<Route path="student-detail" component={StudentDetailContainer} />
</Route>
</Router>
</div>
</Provider>,
document.getElementById('root')
);

</Provider>
,
document.getElementById('root'));
3 changes: 3 additions & 0 deletions 05 SimpleApp_Navigation/src/model/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './login';
export * from './loginResponse';
export * from './userProfile';
9 changes: 9 additions & 0 deletions 05 SimpleApp_Navigation/src/model/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class LoginEntity {
login : string;
password : string;

public constructor() {
this.login = '';
this.password = '';
}
}
4 changes: 4 additions & 0 deletions 05 SimpleApp_Navigation/src/model/userProfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class UserProfile {
fullname : string;
role : string;
}
28 changes: 28 additions & 0 deletions 05 SimpleApp_Navigation/src/pages/login/actions/loginRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { actionsEnums } from '../../../common/actionsEnums';
import { LoginResponse } from '../../../model/loginResponse';
import { LoginEntity } from '../../../model/login';
import { loginApi } from '../../../rest-api/loginApi';
import { hashHistory } from 'react-router';

export const loginRequestStartedAction = (login: LoginEntity) => {
return function (dispatcher) {
const promise = loginApi.login(login);
promise.then(
data => {
dispatcher(loginRequestCompletedAction(data));
// This is not ideal to have it here, maybe move it to middleware?
if (data.succeeded == true) {
hashHistory.push('/student-list');
}
}
);
return promise;
}
}

const loginRequestCompletedAction = (loginResponse: LoginResponse) => {
return {
type: actionsEnums.USERPROFILE_PERFORM_LOGIN,
payload: loginResponse
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { actionsEnums } from '../../../common/actionsEnums';
import { LoginEntity } from '../../../model/login';

export const updateEditingLogin = (loginInfo: LoginEntity) => {
return {
type: actionsEnums.USERPROFILE_UPDATE_EDITING_LOGIN,
payload: loginInfo
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ export const Form = (props: Props) => {
</form>
</div>
);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from "react"

export const Header = () => {
return (
return (
<div className="panel-heading">
<h3 className="panel-title">Please sign in</h3>
</div>
);
}
}
1 change: 1 addition & 0 deletions 05 SimpleApp_Navigation/src/pages/login/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { LoginContainer } from './loginContainer';
28 changes: 28 additions & 0 deletions 05 SimpleApp_Navigation/src/pages/login/login.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from 'react';
import { Header } from './components/header';
import { Form } from './components/form';
import { LoginEntity } from '../../model/login';

interface Props {
loginInfo: LoginEntity;
updateLoginInfo: (loginInfo: LoginEntity) => void;
performLogin: (loginInfo: LoginEntity) => void;
}

export const LoginComponent = (props: Props) => {
return (
<div className="container">
<div className="row">
<div className="col-md-4 col-md-offset-4">
<div className="panel panel-default">
<Header />
<Form loginInfo={props.loginInfo}
updateLoginInfo={props.updateLoginInfo.bind(this)}
performLogin={() => props.performLogin(props.loginInfo)}
/>
</div>
</div>
</div>
</div>
)
}
23 changes: 23 additions & 0 deletions 05 SimpleApp_Navigation/src/pages/login/loginContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { connect } from 'react-redux';
import { LoginComponent } from './login';
import { LoginEntity } from '../../model/login';
import { updateEditingLogin } from './actions/updateEditingLogin';
import { loginRequestStartedAction } from './actions/loginRequest';

const mapStateToProps = (state) => {
return {
loginInfo: state.sessionReducer.editingLogin
}
}

const mapDispatchToProps = (dispatch) => {
return {
updateLoginInfo: (loginInfo: LoginEntity) => dispatch(updateEditingLogin(loginInfo)),
performLogin: (loginInfo: LoginEntity) => dispatch(loginRequestStartedAction(loginInfo))
}
}

export const LoginContainer = connect(
mapStateToProps
, mapDispatchToProps
)(LoginComponent);
1 change: 1 addition & 0 deletions 05 SimpleApp_Navigation/src/pages/student-detail/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {StudentDetailContainer} from './studentDetailContainer';
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export const StudentDetailComponent = () => {
return (
<h2>I'm the StudentDetail page</h2>
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { connect } from 'react-redux';
import { StudentDetailComponent } from './studentDetail';

const mapStateToProps = (state) => {
return {
}
return {
}
}

const mapDispatchToProps = (dispatch) => {
Expand All @@ -12,6 +12,6 @@ const mapDispatchToProps = (dispatch) => {
}

export const StudentDetailContainer = connect(
mapStateToProps
,mapDispatchToProps
)(StudentDetailComponent);
mapStateToProps
, mapDispatchToProps
)(StudentDetailComponent);
1 change: 1 addition & 0 deletions 05 SimpleApp_Navigation/src/pages/student-list/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {StudentListContainer} from './studentListContainer';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

export const StudentListComponent = () => {
return (
<h2>I'm the StudentList page</h2>
)
}
return (
<h2>I'm the StudentList page</h2>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { connect } from 'react-redux';
import { StudentListComponent } from './studentList';

const mapStateToProps = (state) => {
return {
}
return {
}
}

const mapDispatchToProps = (dispatch) => {
Expand All @@ -12,6 +12,6 @@ const mapDispatchToProps = (dispatch) => {
}

export const StudentListContainer = connect(
mapStateToProps
,mapDispatchToProps
)(StudentListComponent);
mapStateToProps
, mapDispatchToProps
)(StudentListComponent);
8 changes: 8 additions & 0 deletions 05 SimpleApp_Navigation/src/reducers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { combineReducers} from 'redux';
import { sessionReducer } from './session';
import { routerReducer, RouterState } from 'react-router-redux';

export const reducers = combineReducers({
sessionReducer,
routing: routerReducer
});
Loading