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
21 changes: 21 additions & 0 deletions 08week/timeline-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
2,164 changes: 2,164 additions & 0 deletions 08week/timeline-app/README.md

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions 08week/timeline-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "timeline-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-scripts": "1.0.12"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Binary file added 08week/timeline-app/public/favicon.ico
Binary file not shown.
46 changes: 46 additions & 0 deletions 08week/timeline-app/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap-theme.min.css">

<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
15 changes: 15 additions & 0 deletions 08week/timeline-app/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
39 changes: 39 additions & 0 deletions 08week/timeline-app/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.App {
text-align: center;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
}

.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
}

.App-intro {
font-size: large;
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}

#button-timeline {
margin-bottom: 20px;
}

.panel {
width: 402px;
margin: auto;
margin-bottom: 20px;
}

#button-panel {
display: flex;
justify-content: space-around;
}
89 changes: 89 additions & 0 deletions 08week/timeline-app/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React, { Component } from 'react';
import './App.css';
import TimeLine from './TimeLine';
import Button from 'react-bootstrap/lib/Button';

class App extends Component {
/** Two Components, one parent that takes a user's status
* and a child that displays all the statuses */
constructor(props){
super(props);
this.state = {
inputValue: '',
timeLine: [],
editCard: null,
editValue: '',
}
}
handleChange(e){
this.setState({inputValue: e.target.value});
}
handleClick=()=>{
const card = {
createdAt: new Date(),
text: this.state.inputValue,
color: 'blue',
id: this.state.timeLine.length + 1
};
this.setState({timeLine: [...this.state.timeLine, card], inputValue: ''})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice method

};

deleteStatus=(id)=>{
// console.log(id ,this.state.timeLine);
const deleteCardList = this.state.timeLine.filter((card, index) =>{
return card.id !== id;
});
this.setState({timeLine: deleteCardList});
};

// These methods handle the editing task
initEdit=(id)=>{ // To activate edit mode
// console.log('In initEdit', id);
this.setState({editCard: id,});
};

handleChange2=(e)=>{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this a more specific function name

// console.log('In handleChange2', e.target.value);
this.setState({editValue: e.target.value});
};

saveEdit=(id)=>{
// console.log('In saveEdit', id);
const timeLine=[...this.state.timeLine];
timeLine[id-1]['text'] = this.state.editValue;
this.setState({
timeLine: timeLine,
editCard: null,
editValue: ''
});
};

render() {
// let Button = ReactBootstrap;
return (
<div className="App">
<input
onChange={(e) => this.handleChange(e)}
value={this.state.inputValue}
type="text"
/>
<Button
id="button-timeline"
bsStyle="primary"
bsSize="large"
onClick={this.handleClick}>Submit</Button>
<TimeLine
deleteStatus={this.deleteStatus}
list={this.state.timeLine}
initEdit={this.initEdit}
editCard={this.state.editCard}
handleChange2={this.handleChange2}
editValue={this.state.editValue}
saveEdit={this.saveEdit}
/>
</div>
);
}
}

export default App;
8 changes: 8 additions & 0 deletions 08week/timeline-app/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});
67 changes: 67 additions & 0 deletions 08week/timeline-app/src/TimeLine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { Component } from 'react';
import './App.css';
import { Panel, Button, FormControl } from 'react-bootstrap';
// import { InputGroup, FormGroup, FormControl, DropdownButton, MenuItem } from 'react-bootstrap';


class TimeLine extends Component {
renderList(){
if(this.props.list && this.props.list.length > 0){
return this.props.list.map((card, index) =>{
return(
<Panel
header={card.text}
bsStyle="primary"
key={index}
>
{this.props.editCard === card.id? (
<div>
<FormControl
type="text"
value={this.props.editValue}
placeholder={card.text}
onChange={(e)=>this.props.handleChange2(e)}
/>
<Button
bsStyle="primary"
onClick={() => this.props.saveEdit(card.id)}
>
Submit
</Button>
</div>
) : (
<div id="button-panel">
<Button
bsStyle="warning"
onClick={() => this.props.initEdit(card.id)}
>
Edit
</Button>
<Button
bsStyle="danger"
onClick={() => this.props.deleteStatus(card.id)}
>
Delete
</Button>
</div>
)}
</Panel>
)
});
}
}
render() {
return (
<div className="">
{this.renderList()}
</div>
);
}
}

export default TimeLine;

// <div key={index}>
// <h2>{card.text}</h2>
// <p onClick={() => this.props.deleteStatus(card.id)}>X</p>
// </div>
30 changes: 30 additions & 0 deletions 08week/timeline-app/src/Timeline.old.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { Component } from 'react';
import './App.css';

class TimeLine extends Component {
// Two components, one parent that takes a user's status, and a child that
// displays all the statuses.
constructor(props) {
super(props);
this.state = {
};
}

renderList() {
return this.props.list.map((card, index)=> {
return <h3 key={index}>{card.text}</h3>
});
}

render() {
console.log(this.state);
return (
<div className="">
<h1>Timeline</h1>
{this.renderList()}
</div>
);
}
}

export default TimeLine;
Loading