Skip to content

Commit 19fc318

Browse files
committed
trying to make webpack-dev-server work
1 parent 38cc805 commit 19fc318

20 files changed

+425
-1
lines changed

client/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM node:6.5.0-slim
2+
3+
RUN mkdir -p /usr/src/app
4+
WORKDIR /usr/src/app
5+
6+
COPY package.json /usr/src/app/
7+
ENV NODE_ENV development
8+
RUN npm install
9+
10+
#COPY . /usr/src/app
11+
#CMD [ "bash", "sleep 10m" ]

client/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
</head>
5+
<body lang="en">
6+
<div id="react-app"></div>
7+
<script src="/bundle.js" type="text/javascript"></script>
8+
</body></html>

client/package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "go-react-todo",
3+
"version": "1.0.0",
4+
"description": "Todo application using go & reactjs",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "NODE_ENV=production ./node_modules/webpack/bin/webpack.js",
8+
"start": "./node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot"
9+
},
10+
"keywords": [
11+
"go",
12+
"reactjs"
13+
],
14+
"author": "xTrinch",
15+
"license": "MIT",
16+
"dependencies": {
17+
"clean-webpack-plugin": "0.1.10",
18+
"copy-webpack-plugin": "3.0.1",
19+
"express": "4.14.0",
20+
"jquery": "3.1.0",
21+
"react": "15.3.0",
22+
"react-dom": "15.3.0",
23+
"react-redux": "^4.4.5",
24+
"redux": "^3.6.0",
25+
"webpack": "1.13.1"
26+
},
27+
"devDependencies": {
28+
"babel-loader": "6.2.4",
29+
"babel-preset-es2015": "6.13.2",
30+
"babel-preset-react": "6.11.1",
31+
"css-loader": "0.23.1",
32+
"less": "2.7.1",
33+
"less-loader": "2.2.3",
34+
"style-loader": "0.13.1",
35+
"webpack-dev-server": "1.14.1"
36+
}
37+
}

client/src/actions/index.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
let nextTodoId = 0
2+
export const addTodo = (text) => {
3+
return {
4+
type: 'ADD_TODO',
5+
id: nextTodoId++,
6+
text
7+
}
8+
}
9+
10+
export const setVisibilityFilter = (filter) => {
11+
return {
12+
type: 'SET_VISIBILITY_FILTER',
13+
filter
14+
}
15+
}
16+
17+
export const toggleTodo = (id) => {
18+
return {
19+
type: 'TOGGLE_TODO',
20+
id
21+
}
22+
}

client/src/components/app.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react'
2+
import Footer from './footer.jsx'
3+
import AddTodo from '../containers/addtodo.jsx'
4+
import VisibleTodoList from '../containers/visibletodolist.jsx'
5+
6+
const App = () => (
7+
<div>
8+
<AddTodo />
9+
<VisibleTodoList />
10+
<Footer />
11+
</div>
12+
)
13+
14+
export default App

client/src/components/footer.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react'
2+
import FilterLink from '../containers/filterlink.jsx'
3+
4+
const Footer = () => (
5+
<p>
6+
Show:
7+
{" "}
8+
<FilterLink filter="SHOW_ALL">
9+
All
10+
</FilterLink>
11+
{", "}
12+
<FilterLink filter="SHOW_ACTIVE">
13+
Active
14+
</FilterLink>
15+
{", "}
16+
<FilterLink filter="SHOW_COMPLETED">
17+
Completed
18+
</FilterLink>
19+
</p>
20+
)
21+
22+
export default Footer

client/src/components/link.jsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React, { PropTypes } from 'react'
2+
3+
const Link = ({ active, children, onClick }) => {
4+
if (active) {
5+
return <span>{children}</span>
6+
}
7+
8+
return (
9+
<a href="#"
10+
onClick={e => {
11+
e.preventDefault()
12+
onClick()
13+
}}
14+
>
15+
{children}
16+
</a>
17+
)
18+
}
19+
20+
Link.propTypes = {
21+
active: PropTypes.bool.isRequired,
22+
children: PropTypes.node.isRequired,
23+
onClick: PropTypes.func.isRequired
24+
}
25+
26+
export default Link

client/src/components/todo.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React, { PropTypes } from 'react'
2+
3+
const Todo = ({ onClick, completed, text }) => (
4+
<li
5+
onClick={onClick}
6+
style={{
7+
textDecoration: completed ? 'line-through' : 'none'
8+
}}
9+
>
10+
{text}
11+
</li>
12+
)
13+
14+
Todo.propTypes = {
15+
onClick: PropTypes.func.isRequired,
16+
completed: PropTypes.bool.isRequired,
17+
text: PropTypes.string.isRequired
18+
}
19+
20+
export default Todo

client/src/components/todolist.jsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { PropTypes } from 'react'
2+
import Todo from './todo.jsx'
3+
4+
const TodoList = ({ todos, onTodoClick }) => (
5+
<ul>
6+
{todos.map(todo =>
7+
<Todo
8+
key={todo.id}
9+
{...todo}
10+
onClick={() => onTodoClick(todo.id)}
11+
/>
12+
)}
13+
</ul>
14+
)
15+
16+
TodoList.propTypes = {
17+
todos: PropTypes.arrayOf(PropTypes.shape({
18+
id: PropTypes.number.isRequired,
19+
completed: PropTypes.bool.isRequired,
20+
text: PropTypes.string.isRequired
21+
}).isRequired).isRequired,
22+
onTodoClick: PropTypes.func.isRequired
23+
}
24+
25+
export default TodoList

client/src/containers/addtodo.jsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react'
2+
import { connect } from 'react-redux'
3+
import { addTodo } from '../actions/index.jsx'
4+
5+
let AddTodo = ({ dispatch }) => {
6+
let input
7+
8+
return (
9+
<div>
10+
<form onSubmit={e => {
11+
e.preventDefault()
12+
if (!input.value.trim()) {
13+
return
14+
}
15+
dispatch(addTodo(input.value))
16+
input.value = ''
17+
}}>
18+
<input ref={node => {
19+
input = node
20+
}} />
21+
<button type="submit">
22+
Add Todo
23+
</button>
24+
</form>
25+
</div>
26+
)
27+
}
28+
AddTodo = connect()(AddTodo)
29+
30+
export default AddTodo

0 commit comments

Comments
 (0)