-
Notifications
You must be signed in to change notification settings - Fork 10
React homework - 嘉義 Amo Lin #4
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
amo-lin
wants to merge
3
commits into
clonn:master
Choose a base branch
from
amo-lin:master
base: master
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
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| import axios from 'axios'; | ||
|
|
||
| module.exports = { | ||
| async reloadTodoDatas() { | ||
| let { data: response } = await axios.get('https://jsonplaceholder.typicode.com/todos'); | ||
| return response; | ||
| } | ||
| async reloadTodoDatas() { | ||
| let { data: response } = await axios.get('https://jsonplaceholder.typicode.com/todos'); | ||
| return response; | ||
| }, | ||
| async reloadOmdbDatas() { | ||
| let { data: response } = await axios.get('http://www.omdbapi.com/?s=Batman&apikey=34472924'); | ||
| return response; | ||
| } | ||
| }; |
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 |
|---|---|---|
| @@ -1,38 +1,25 @@ | ||
| import React from "react"; | ||
| import ReactDOM from "react-dom"; | ||
| import Header from './components/Header'; | ||
| import api from './api/base'; | ||
|
|
||
|
|
||
| import Todo from './components/Todo'; | ||
| import Product from './components/Product'; | ||
|
|
||
| class HelloMessage extends React.Component { | ||
|
|
||
| constructor(props) { | ||
| super(props); | ||
| this.state = { | ||
| todos: [] | ||
| }; | ||
| } | ||
|
|
||
| async componentDidMount() { | ||
| const todos = await api.reloadTodoDatas(); | ||
| this.setState({ | ||
| todos | ||
| }); | ||
| } | ||
| constructor(props) { | ||
| super(props); | ||
| } | ||
|
|
||
| render() { | ||
| const { todos } = this.state; | ||
| return ( | ||
| <div> | ||
| <Header/> | ||
| <div className="container"> | ||
| <h1>Hi {this.props.name}</h1> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
| render() { | ||
| return ( | ||
| <div> | ||
| <Product/> | ||
| <Todo/> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| const App = document.getElementById("app"); | ||
| ReactDOM.render(<HelloMessage name="Caesar" />, App); | ||
| ReactDOM.render(<HelloMessage/>, 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,68 @@ | ||
| .prods { | ||
| margin: 8%; | ||
| } | ||
|
|
||
| .prods-head { | ||
| color:#ffff; | ||
| background-color: rgb(40, 38, 37); | ||
| height: 8vh; | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| padding: 0 3% 0 3%; | ||
| margin: 0; | ||
| } | ||
|
|
||
| .prods-title { | ||
| font-size: 23px; | ||
| } | ||
|
|
||
| .search-type { | ||
| font-size: 20px; | ||
| color: rgb(247, 37, 33); | ||
| } | ||
|
|
||
| .prods-content ul { | ||
| list-style-type: none; | ||
| margin: 0px; | ||
| padding: 0px; | ||
| } | ||
| .prods-content ul li { | ||
| font-size: 20px; | ||
| margin: 1px 0 1px 0; | ||
| } | ||
|
|
||
| .prod-info { | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .prod-info span { | ||
| padding-left: 5px; | ||
| } | ||
|
|
||
| .prod-info a { | ||
| text-decoration: none; | ||
| } | ||
| /* | ||
| .prod-line1 { | ||
| background-color: rgb(255, 255, 231); | ||
| } | ||
|
|
||
| .prod-line2 { | ||
| background-color: rgb(238, 238, 238); | ||
| } | ||
| */ | ||
|
|
||
| .prod:nth-of-type(odd) { | ||
| background-color: rgb(255, 255, 231); | ||
| } | ||
|
|
||
| .prod:nth-of-type(even) { | ||
| background-color: rgb(238, 238, 238); | ||
| } | ||
|
|
||
| .error-message { | ||
| color: rgb(248, 2, 2); | ||
| text-align: center; | ||
| } |
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,65 @@ | ||
| import React from 'react'; | ||
| import api from '/api/base'; | ||
|
|
||
| export default class Product extends React.Component { | ||
|
|
||
| constructor(props) { | ||
| super(props); | ||
| this.state = { | ||
| prods: [], | ||
| totalNum : 0, | ||
| error:"" | ||
| }; | ||
| } | ||
|
|
||
| async componentDidMount() { | ||
| const prodInfo = await api.reloadOmdbDatas(); | ||
| let prods = []; | ||
| let errorMsg = ""; | ||
| for (let [key, value] of Object.entries(prodInfo)) { | ||
| if(key == "Search") { | ||
| prods = value; | ||
| } | ||
| if (key == "Error") { | ||
| errorMsg = value; | ||
| } | ||
| } | ||
| this.setState({ | ||
| 'prods': prods, | ||
| "error": errorMsg | ||
| }); | ||
|
|
||
| } | ||
|
|
||
| render() { | ||
| const { error } = this.state; | ||
| const { prods } = this.state; | ||
|
|
||
| let movieList = ""; | ||
| if (error.length == 0 ) { | ||
| movieList = prods.map((prod, index) => { | ||
| return ( | ||
| <li key={index} className="prod"> | ||
| <span className="prod-info"><img width="120" src={prod.Poster} alt={prod.imdbID} /><span><a href={prod.imdbID} >{prod.Title}</a></span><span>({prod.Year})</span><span>({prod.Type})</span></span> | ||
| </li> | ||
| ); | ||
| }) | ||
| } else { | ||
| movieList = <li className="error-message" >{error}</li>; | ||
| } | ||
|
|
||
| return( | ||
| <div className="prods"> | ||
| <div className="prods-head"> | ||
| <span className="prods-title">SEARCH RESULTS FOR:Batman</span> | ||
| <span>VIEW:<span className='search-type'>exact title matches</span></span> | ||
| </div> | ||
| <div className="prods-content"> | ||
| <ul> | ||
| {movieList} | ||
| </ul> | ||
| </div> | ||
| </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,41 @@ | ||
| import React from 'react'; | ||
| import api from '/api/base'; | ||
|
|
||
| export default class Todo extends React.Component { | ||
|
|
||
| constructor(props) { | ||
| super(props); | ||
| this.state = { | ||
| todos: [] | ||
| }; | ||
| } | ||
|
|
||
| async componentDidMount() { | ||
| const todos = await api.reloadTodoDatas(); | ||
| this.setState({ | ||
| 'todos': todos | ||
| }); | ||
| this.handleChecked = this.handleChecked.bind(this); | ||
| } | ||
|
|
||
| handleChecked () { | ||
| this.setState({completed: !this.state.completed}); | ||
| } | ||
|
|
||
| render() { | ||
| const { todos } = this.state; | ||
| return ( | ||
| <div className="todos"> | ||
| <ul> | ||
| {todos.map((todo) => { | ||
| return ( | ||
| <div id="item" key={todo.id}> | ||
| <input type='checkbox' value={todo.id} onChange={this.handleChecked}></input>{todo.id}. {todo.title} | ||
| </div> | ||
| ); | ||
| })} | ||
| </ul> | ||
| </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
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.
可以試試看再加上 onChange 事件,當資料改變的時候,進行 todos 資料調整。