Skip to content
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

add quote list #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from 'react';
import Quote from './quote/Quote'

function App() {
return (
<div>Welcome To Momentum</div>
);
return (
<div>
<div>Welcome To Momentum</div>
<Quote/>
</div>
);
}

export default App;
4 changes: 0 additions & 4 deletions src/quote/Data.js → src/quote/Data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ class Data extends Component {

};

constructor(props){
super(props);
}

render() {
return (
<div className="quote-data">
Expand Down
16 changes: 9 additions & 7 deletions src/quote/Quote.js → src/quote/Quote.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ import QuoteList from './QuoteList';

class Quote extends Component {
state = {

searchData: ''
};

constructor(props){
super(props);
}
getSearchData = (data) =>{
this.setState({
searchData: data
})
};
Copy link
Contributor

Choose a reason for hiding this comment

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

; <- 린트에 걸리지 않나요 ??


render() {
return (
<div className="quote">
<QuoteSearch/>
<QuoteData quote={}/>
<QuoteList/>
<QuoteSearch getSearchData={this.getSearchData}/>
<QuoteData quote={"I'm happy!"}/>
<QuoteList searchString={this.state.searchData}/>
</div>
);
}
Expand Down
30 changes: 0 additions & 30 deletions src/quote/QuoteList.js

This file was deleted.

42 changes: 42 additions & 0 deletions src/quote/QuoteList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, {Component} from 'react';
import PropTypes from "prop-types";
import QuoteListItemClass from "./js/QuoteListItemClass";
import QuoteListItem from "./QuoteListItem";

class QuoteList extends Component {
state = {};

render() {
return (
<div className="quote-list">
<ul>
{this.props.quoteList.map((value, key) => {
return <QuoteListItem quote={value} searchString={this.props.searchString} key={`quote-list-${key}`}/>
})}
</ul>
</div>
);
}
}

QuoteList.propTypes = {
quoteList: PropTypes.arrayOf(PropTypes.instanceOf(QuoteListItemClass)).isRequired,
searchString: PropTypes.string
};

QuoteList.defaultProps = {
quoteList: [
new QuoteListItemClass('Helen Keller','The best and most beautiful things in the world cannot be seen or even touched - they must be felt with the heart.'),
new QuoteListItemClass('Oscar Wilde','Keep love in your heart. A life without it is like a sunless garden when the flowers are dead.'),
new QuoteListItemClass('Aristotle','It is during our darkest moments that we must focus to see the light.'),
new QuoteListItemClass('Maya Angelou','Try to be a rainbow in someone\'s cloud.'),
new QuoteListItemClass('Joseph Campbell\n','Find a place inside where there\'s joy, and the joy will burn out the pain.'),
new QuoteListItemClass('Audrey Hepburn','Nothing is impossible, the word itself says \'I\'m possible\'!'),
new QuoteListItemClass('Robert Louis Stevenson','Don\'t judge each day by the harvest you reap but by the seeds that you plant.'),
new QuoteListItemClass('Buddha','Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment.\n'),
new QuoteListItemClass('Edmund Burke','The only thing necessary for the triumph of evil is for good men to do nothing.'),
new QuoteListItemClass('Lucius Annaeus Seneca','One of the most beautiful qualities of true friendship is to understand and to be understood.'),
]
};

export default QuoteList;
27 changes: 0 additions & 27 deletions src/quote/QuoteListItem.js

This file was deleted.

36 changes: 36 additions & 0 deletions src/quote/QuoteListItem.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, {Component} from 'react';
import PropTypes from "prop-types";
import QuoteListItemClass from './js/QuoteListItemClass'
import './css/QuoteListItem.css'

class QuoteListItem extends Component {
state = {};

Copy link
Contributor

Choose a reason for hiding this comment

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

사용하지 않는 state라면 없어도 괜찮을것 같습니다.

setHighlight = () => {
const idx = this.props.quote.data.indexOf(this.props.searchString);
if (idx !== -1 ) {
return (<>
<span>{this.props.quote.data.slice(0, idx)}</span>
<b>{this.props.quote.data.slice(idx, idx + this.props.searchString.length)}</b>
<span>{this.props.quote.data.slice(idx + this.props.searchString.length, this.props.quote.data.length)}</span>
</>);
} else {
return <span>{this.props.quote.data}</span>;
}
};

Copy link
Contributor

Choose a reason for hiding this comment

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

const { quote, searchStrung } = this.props;

와 같이 해준다면 더 코드가 간결해 질것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오 맞네요

render() {
return (
<li className="quote-list-item">
{this.props.quote.name} - {this.setHighlight()}
</li>
);
}
}

QuoteListItem.propTypes = {
quote: PropTypes.instanceOf(QuoteListItemClass).isRequired,
searchString: PropTypes.string
};

export default QuoteListItem;
20 changes: 0 additions & 20 deletions src/quote/Search.js

This file was deleted.

29 changes: 29 additions & 0 deletions src/quote/Search.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, {Component} from 'react';

class Search extends Component {
state = {
data: ''
};

handleChange = (e) => {
this.props.getSearchData(e.target.value);
this.setState({
data: e.target.value,
})
};

onClick = () => {

};

render() {
return (
<div>
<input className="quote-search" onChange={this.handleChange}/>
<input type="button" value="검색" onClick={this.onClick}/>
</div>
);
}
}

export default Search;
3 changes: 3 additions & 0 deletions src/quote/css/QuoteListItem.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
b{
background-color: skyblue;
}