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

HT3 #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

HT3 #26

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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"prop-types": "^15.5.10",
"react": "^15.5.0",
"react-day-picker": "^6.0.2",
"react-dom": "^15.5.0",
"react-select": "^1.0.0-rc.5",
"react-transition-group": "^1.2.0"
Expand Down
50 changes: 50 additions & 0 deletions src/components/AddCommentForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'

export default class UserForm extends PureComponent {
constructor(props){
super(props);

this.state = {
userName: '',
commentText: ''
}
this.handleUserChange = this.handleInputChange('userName');
this.handleCommentChange = this.handleInputChange('commentText');
}

render() {
let {
userName,
commentText
} = this.state;
return (
<div>
User:
<input
style = {(userName.length < 5 || userName.length > 15) ? {
'color':'red'
} : {'color':'black'}}
type = 'text'
value = {userName}
onChange = {this.handleUserChange}
/>
Comment text:
<input
style = {(commentText.length < 20 || commentText.length > 50) ? {
'color':'red'
} : {'color':'black'}}
type = 'text'
value = {commentText}
onChange = {this.handleCommentChange}
/>
</div>
)
}

handleInputChange = target => ev => {
this.setState({
[target]: ev.target.value
})
}
}
4 changes: 3 additions & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ArticlesChart from './ArticlesChart'
import UserForm from './UserForm'
import Select from 'react-select'
import 'react-select/dist/react-select.css'
import DayPicker from './DayPicker.js'

class App extends Component {
static propTypes = {
Expand All @@ -24,6 +25,7 @@ class App extends Component {

return (
<div>
<DayPicker />
<UserForm />
<Select options = {options} value = {this.state.selection} onChange = {this.changeSelection} multi />
<ArticleList articles = {articles} defaultOpenId = {articles[0].id}/>
Expand All @@ -35,4 +37,4 @@ class App extends Component {
changeSelection = selection => this.setState({ selection })
}

export default App
export default App
12 changes: 8 additions & 4 deletions src/components/CommentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {Component} from 'react'
import PropTypes from 'prop-types'
import Comment from './Comment'
import toggleOpen from '../decorators/toggleOpen'
import AddCommentForm from './AddCommentForm'

function CommentList({comments = [], isOpen, toggleOpen}) {
const text = isOpen ? 'hide comments' : 'show comments'
Expand All @@ -25,10 +26,13 @@ function getBody({comments, isOpen}) {
if (!comments.length) return <p>No comments yet</p>

return (
<ul>
{comments.map(comment => <li key={comment.id}><Comment comment={comment}/></li>)}
</ul>
<div>
<ul>
{comments.map(comment => <li key={comment.id}><Comment comment={comment}/></li>)}
</ul>
<AddCommentForm />
</div>
)
}

export default toggleOpen(CommentList)
export default toggleOpen(CommentList)
54 changes: 54 additions & 0 deletions src/components/DayPicker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { PureComponent } from 'react'
import ReactDayPicker from 'react-day-picker'
import 'react-day-picker/lib/style.css'

export default class DayPicker extends PureComponent {
state = {
first: null,
second: null
}

handleDayClick = day => {
let {
first,
second
} = this.state;

if (!first) {
this.setState({
first: day
})
} else if (!second) {
this.setState({
second: day
})
} else {
this.setState({
first: day,
second: null
})
}
};

render() {
let {
first,
second
} = this.state;
let day;
let str = first
? (second
? `Выбранный временной интервал: ${day = Math.abs(second - first)/86400000} ${day < 5 ? (day === 1 ? 'день' : 'дня') : 'дней'}`
: 'Выберите вторую дату'
)
: 'Выберите первую дату';

return <div>
<div>{ str }</div>
<ReactDayPicker
onDayClick={this.handleDayClick}
selectedDays={this.state.selectedDay}
/>
</div>
}
}