-
Notifications
You must be signed in to change notification settings - Fork 15
hw3 done #31
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
grudolobichdeleted
wants to merge
1
commit into
romabelka:master
Choose a base branch
from
grudolobichdeleted:hw3
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
hw3 done #31
Changes from all commits
Commits
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
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
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
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,48 @@ | ||
import React, { useState } from 'react' | ||
|
||
function commentForm() { | ||
const [author, setAuthor] = useState('') | ||
const [comment, setComment] = useState('') | ||
const [validationError, setValidationError] = useState('') | ||
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. Зачем отдельный стейт под ошибки? |
||
|
||
function authorInputHandler({ target }) { | ||
const { value } = target | ||
|
||
setAuthor(value) | ||
} | ||
|
||
function commentInputHandler({ target }) { | ||
const { value } = target | ||
|
||
setComment(value) | ||
} | ||
|
||
function validateData(event) { | ||
event.preventDefault() | ||
setValidationError('') | ||
|
||
if (comment.length < 5) { | ||
setValidationError(`${validationError}Comment must be longer than 5 characters`) | ||
} | ||
|
||
if (author.length < 5) { | ||
setValidationError(`${validationError}; author must be longer than 5 characters`) | ||
} | ||
} | ||
|
||
return ( | ||
<section> | ||
<h2>New comment</h2> | ||
<form action="/"> | ||
<input type="text" onInput={authorInputHandler} placeholder="Author name" /> | ||
<div> | ||
<textarea placeholder="Comment text" onInput={commentInputHandler} cols="30" rows="10" /> | ||
</div> | ||
<div style={{ color: 'red' }}>{validationError}</div> | ||
<button onClick={validateData}>submit</button> | ||
</form> | ||
</section> | ||
) | ||
} | ||
|
||
export default commentForm |
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,15 +1,28 @@ | ||
import React, { useState } from 'react' | ||
import React from 'react' | ||
import { connect } from 'react-redux' | ||
import Select from 'react-select' | ||
|
||
function SelectFilter({ articles }) { | ||
const [selected, setSelection] = useState(null) | ||
import { selectArticles } from '../../ac/index' | ||
|
||
function SelectFilter({ articles, selectArticles, selected }) { | ||
const options = articles.map((article) => ({ | ||
label: article.title, | ||
value: article.id | ||
})) | ||
|
||
return <Select options={options} value={selected} onChange={setSelection} isMulti /> | ||
return <Select options={options} value={selected} onChange={selectArticles} isMulti /> | ||
} | ||
|
||
export default SelectFilter | ||
const mapStateToProps = (state) => ({ | ||
articles: state.articles, | ||
selected: state.articlesFilter.selected | ||
}) | ||
|
||
const mapDispatchToProps = { | ||
selectArticles | ||
} | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(SelectFilter) |
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,3 +1,6 @@ | ||
export const INCREMENT = 'INCREMENT' | ||
|
||
export const DELETE_ARTICLE = 'DELETE_ARTICLE' | ||
|
||
export const SELECT_ARTICLES = 'SELECT_ARTICLES' | ||
export const SET_RANGE = 'SET_RANGE' |
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,31 @@ | ||
import { SELECT_ARTICLES, SET_RANGE } from '../constants' | ||
|
||
const initialState = { | ||
range: { | ||
from: null, | ||
to: null | ||
}, | ||
selected: null | ||
} | ||
|
||
export default (filtersState = initialState, action) => { | ||
const { type, payload } = action | ||
|
||
switch (type) { | ||
case SELECT_ARTICLES: { | ||
return { | ||
...filtersState, | ||
selected: payload | ||
} | ||
} | ||
|
||
case SET_RANGE: { | ||
return { | ||
...filtersState, | ||
range: payload | ||
} | ||
} | ||
default: | ||
return filtersState | ||
} | ||
} |
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,10 @@ | ||
import { combineReducers } from 'redux' | ||
import counterReducer from './counter' | ||
import articles from './articles' | ||
import articlesFilter from './articles-filter' | ||
|
||
export default combineReducers({ | ||
counter: counterReducer, | ||
articles | ||
articles, | ||
articlesFilter | ||
}) |
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.
Названия компонент с большой буквы должны быть