forked from AustinCodingAcademy/javascript-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Week8a Timeline using React / React Bootstrap #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
copelandhouse2
wants to merge
4
commits into
gh-pages
Choose a base branch
from
week8a-timeline
base: gh-pages
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7f1a2f4
Timeline React initial push. Contains a number of libraries... React…
copelandhouse2 d619388
Adding an edit function
copelandhouse2 44b8683
Added react bootstrap visuals. Added input box, edit button. Added …
copelandhouse2 7ff5844
Got basic edit to work. It is updating the card. However, if you de…
copelandhouse2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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* |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: ''}) | ||
| }; | ||
|
|
||
| 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)=>{ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice method