Skip to content

Commit d576114

Browse files
committed
base setup
0 parents  commit d576114

File tree

23 files changed

+14258
-0
lines changed

23 files changed

+14258
-0
lines changed

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env","@babel/preset-react"]
3+
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

package-lock.json

+8,301
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "reactredux",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "webpack --config webpack.config.js --mode development"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"devDependencies": {
12+
"@babel/core": "^7.0.0-rc.1",
13+
"@babel/preset-env": "^7.0.0-rc.1",
14+
"@babel/preset-react": "^7.0.0-rc.1",
15+
"babel-cli": "^6.26.0",
16+
"babel-core": "^6.26.3",
17+
"babel-loader": "^8.0.0-beta.4",
18+
"babel-polyfill": "^6.26.0",
19+
"express": "^4.16.3",
20+
"node-sass": "^4.9.3",
21+
"react": "^16.4.2",
22+
"react-dom": "^16.4.2",
23+
"react-redux": "^5.0.7",
24+
"redux": "^4.0.0",
25+
"sass-loader": "^7.1.0",
26+
"webpack": "^4.16.5",
27+
"webpack-cli": "^3.1.0"
28+
},
29+
"dependencies": {
30+
"babel-preset-es2015": "^6.24.1",
31+
"css-loader": "^1.0.0",
32+
"react-player": "^1.6.4",
33+
"redux-saga": "^0.16.0",
34+
"style-loader": "^0.22.1"
35+
}
36+
}

src/client/actions/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { action } from "../helpers/actionCreator";
2+
import * as actions from '../constants/index';
3+
4+
export const add = (text) => action(actions.ADD, { text });

src/client/components/App.jsx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import ReactPlayer from 'react-player'
4+
import '../styles/App.scss'
5+
export default class App extends React.Component {
6+
constructor(props) {
7+
super(props);
8+
}
9+
render() {
10+
return this.props.number == 1 ?(
11+
<div>
12+
<ReactPlayer url='https://www.youtube.com/watch?v=ysz5S6PUM-U' playing />
13+
</div>
14+
): <div className="container"> Praba <input type="button" value = "Play Me" onClick = {()=> this.props.add(1)}/> </div>;
15+
}
16+
}
17+
18+
App.propTypes = {
19+
number: PropTypes.string,
20+
add: PropTypes.func,
21+
recipes: PropTypes.array,
22+
};

src/client/constants/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const ADD = 'ADD';
2+
export const SAVE = 'SAVE';
3+
export const START_APPLICATION = 'START_APPLICATION';
4+
export const ADD_RECIPES = 'ADD_RECIPES';

src/client/containers/App.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { bindActionCreators } from 'redux';
2+
import { connect } from 'react-redux';
3+
import App from '../components/App';
4+
import { add } from '../actions'
5+
6+
const mapStateToProps = (state) => ({
7+
number: state.add.number,
8+
recipes: state.recipe.recipes,
9+
});
10+
11+
const mapDispatchToProps = (dispatch) => bindActionCreators({
12+
add,
13+
}, dispatch);
14+
15+
const AppContainer = connect(mapStateToProps, mapDispatchToProps)(App);
16+
17+
export default AppContainer;

src/client/helpers/actionCreator.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const action = (type, payload = {}) => ({ type, payload });

src/client/index.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import { render } from 'react-dom';
3+
import { Provider } from 'react-redux';
4+
import { createStore, applyMiddleware } from 'redux'
5+
import createSagaMiddleware from 'redux-saga'
6+
import cr from './reducers/combined';
7+
import AppContainer from './containers/App';
8+
import rootSaga from './sagas/combined'
9+
const sagaMiddleware = createSagaMiddleware();
10+
import * as actions from "./constants"
11+
// then run the saga
12+
const store = createStore(cr, applyMiddleware(sagaMiddleware))
13+
sagaMiddleware.run(rootSaga)
14+
export const action = type => store.dispatch({ type });
15+
action(actions.START_APPLICATION);
16+
17+
render(
18+
<Provider store={store}>
19+
<AppContainer />
20+
</Provider>,
21+
document.getElementById('app')
22+
);

src/client/reducers/add.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as actions from '../constants';
2+
3+
const add = (state = {}, action) => {
4+
switch (action.type) {
5+
case actions.SAVE:
6+
return Object.assign({}, state, {
7+
number: action.number,
8+
});
9+
default:
10+
return state;
11+
}};
12+
13+
export default add;

src/client/reducers/combined.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { combineReducers } from 'redux';
2+
import add from "./add";
3+
import recipe from './recipe';
4+
5+
const combined = combineReducers({
6+
add,
7+
recipe
8+
});
9+
10+
export default combined;

src/client/reducers/recipe.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as actions from '../constants';
2+
3+
const recipe = (state = {}, action) => {
4+
switch (action.type) {
5+
case actions.ADD_RECIPES:
6+
return Object.assign({}, state, {
7+
recipes: action.recipes,
8+
});
9+
default:
10+
return state;
11+
}};
12+
13+
export default recipe;

src/client/sagas/add.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { call, put, takeEvery, takeLatest } from 'redux-saga/effects'
2+
import * as actions from "../constants"
3+
import { action } from '../helpers/actionCreator';
4+
5+
function* addnumber(action) {
6+
try {
7+
yield put({type: actions.SAVE, number: "1"});
8+
} catch (e) {
9+
yield put({type: "ADD_FAILED", message: e.message});
10+
}
11+
}
12+
13+
function* addWatcher() {
14+
yield takeEvery(actions.ADD, addnumber);
15+
}
16+
export default addWatcher;

src/client/sagas/combined.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { all } from 'redux-saga/effects';
2+
import addWatcher from './add';
3+
import startWatcher from './start'
4+
export default function* rootSaga() {
5+
yield all([
6+
addWatcher(),
7+
startWatcher()
8+
]);
9+
}

src/client/sagas/start.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { call, put, takeEvery, takeLatest } from 'redux-saga/effects'
2+
import * as actions from "../constants"
3+
import { action } from '../helpers/actionCreator';
4+
import { callFetch } from '../services/api'
5+
function* initalize(action) {
6+
try {
7+
const recipes = yield call(callFetch, "/recipes")
8+
yield put({type: actions.ADD_RECIPES, recipes: JSON.parse(recipes.response)});
9+
} catch (e) {
10+
yield put({type: "START_APPLICATION_FAILED", recipes: []});
11+
}
12+
}
13+
14+
function* startWatcher() {
15+
yield takeEvery(actions.START_APPLICATION, initalize);
16+
}
17+
export default startWatcher;

src/client/services/api.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import _ from 'lodash';
2+
3+
export function callFetch(endpoint, params = {}) {
4+
const requestOptions = {};
5+
if (!_.isEmpty(params)) {
6+
requestOptions['headers'] = params;
7+
}
8+
return fetch(endpoint, requestOptions)
9+
.then(
10+
response => _.get(response, 'ok') ? response.json() : Promise.reject(response)
11+
)
12+
.then(
13+
response => ({ response }),
14+
error => ({ error: error.message || 'Something bad happened' })
15+
);
16+
}
17+
18+
export function callPost(endpoint, body = {}) {
19+
const requestOptions = {
20+
credentials: 'same-origin',
21+
method: 'POST',
22+
headers: {
23+
'Accept': 'application/json',
24+
'Content-Type': 'application/json',
25+
},
26+
body: JSON.stringify(body),
27+
};
28+
return fetch(endpoint, requestOptions)
29+
.then(
30+
response => ({ response }),
31+
error => ({ error: error.message || 'Something bad happened' })
32+
);
33+
}

src/client/styles/App.scss

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.container {
2+
font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande",
3+
"Lucida Sans", Arial, sans-serif;
4+
background-color: #fff;
5+
text-transform: capitalize;
6+
}

src/dist/index.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge;" />
6+
<title>ADD</title>
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
<script src="public/bundle.js"></script>
11+
</body>
12+
</html>

src/dist/public/bundle.js

+5,087
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/server/index.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use strict";
2+
const express = require("express");
3+
const app = express();
4+
const path = require("path");
5+
const fs = require("fs");
6+
7+
app.use(express.static("../dist/"));
8+
/* istanbul ignore next */
9+
app.get("/", function(request, response) {
10+
/* istanbul ignore next */
11+
response.redirect("index.html");
12+
});
13+
app.get("/recipes", function(request, response) {
14+
var file = fs.readFileSync("./stub/recipes.json", "utf-8");
15+
//response.setHeader('Content-Type', 'application/json');
16+
response.json(file);
17+
});
18+
/* istanbul ignore next */
19+
const port = process.env.PORT || 3200;
20+
app.listen(port, function() {
21+
console.log(`Application listening on port ${port}`);
22+
});
23+
24+
module.exports = app;

0 commit comments

Comments
 (0)