-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Task solution #1774
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
Dominik-Dudek-code
wants to merge
1
commit into
mate-academy:master
Choose a base branch
from
Dominik-Dudek-code:develop
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
Task solution #1774
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
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,6 +1,7 @@ | ||
| import React from 'react'; | ||
| import 'bulma/css/bulma.css'; | ||
| import './App.scss'; | ||
| import classNames from 'classnames'; | ||
|
|
||
| export const goods = [ | ||
| 'Dumplings', | ||
|
|
@@ -15,58 +16,86 @@ export const goods = [ | |
| 'Garlic', | ||
| ]; | ||
|
|
||
| export const App: React.FC = () => ( | ||
| <main className="section container"> | ||
| <h1 className="title">No goods selected</h1> | ||
| type State = { | ||
| selectedGood: string; | ||
| }; | ||
|
|
||
| <h1 className="title is-flex is-align-items-center"> | ||
| Jam is selected | ||
| {/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} | ||
| <button data-cy="ClearButton" type="button" className="delete ml-3" /> | ||
| </h1> | ||
| export class App extends React.Component<{}, State> { | ||
| state = { | ||
| selectedGood: 'Jam', | ||
| }; | ||
|
|
||
| <table className="table"> | ||
| <tbody> | ||
| <tr data-cy="Good"> | ||
| <td> | ||
| <button data-cy="AddButton" type="button" className="button"> | ||
| + | ||
| </button> | ||
| </td> | ||
| handleDeleteClick = () => { | ||
| this.setState({ | ||
| selectedGood: '', | ||
| }); | ||
| }; | ||
|
|
||
| <td data-cy="GoodTitle" className="is-vcentered"> | ||
| Dumplings | ||
| </td> | ||
| </tr> | ||
| handleGoodsClick = (good: string) => { | ||
| this.setState({ | ||
| selectedGood: good, | ||
| }); | ||
| }; | ||
|
|
||
| <tr data-cy="Good" className="has-background-success-light"> | ||
| <td> | ||
| render(): React.ReactNode { | ||
| const { selectedGood } = this.state; | ||
|
|
||
| return ( | ||
| <main className="section container"> | ||
| {selectedGood.length !== 0 ? ( | ||
|
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. Using |
||
| <h1 className="title is-flex is-align-items-center"> | ||
| {selectedGood} is selected | ||
| {/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} | ||
| <button | ||
| data-cy="RemoveButton" | ||
| data-cy="ClearButton" | ||
| type="button" | ||
| className="button is-info" | ||
| > | ||
| - | ||
| </button> | ||
| </td> | ||
|
|
||
| <td data-cy="GoodTitle" className="is-vcentered"> | ||
| Jam | ||
| </td> | ||
| </tr> | ||
| className="delete ml-3" | ||
| onClick={this.handleDeleteClick} | ||
| /> | ||
| </h1> | ||
| ) : ( | ||
| <h1 className="title">No goods selected</h1> | ||
| )} | ||
|
|
||
| <tr data-cy="Good"> | ||
| <td> | ||
| <button data-cy="AddButton" type="button" className="button"> | ||
| + | ||
| </button> | ||
| </td> | ||
| <table className="table"> | ||
| <tbody> | ||
| {goods.map(good => { | ||
| return ( | ||
| <tr | ||
| data-cy="Good" | ||
| key={good} | ||
| className={classNames({ | ||
| 'has-background-success-light': selectedGood === good, | ||
| })} | ||
| > | ||
| <td> | ||
| <button | ||
| data-cy={ | ||
| good === selectedGood ? 'RemoveButton' : 'AddButton' | ||
| } | ||
| type="button" | ||
| className={ | ||
| good === selectedGood ? 'button is-info' : 'button' | ||
| } | ||
| onClick={ | ||
| good === selectedGood | ||
| ? this.handleDeleteClick | ||
| : () => this.handleGoodsClick(good) | ||
| } | ||
| > | ||
| {good === selectedGood ? '-' : '+'} | ||
| </button> | ||
| </td> | ||
|
|
||
| <td data-cy="GoodTitle" className="is-vcentered"> | ||
| Garlic | ||
| </td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| </main> | ||
| ); | ||
| <td data-cy="GoodTitle" className="is-vcentered"> | ||
| {good} | ||
| </td> | ||
| </tr> | ||
| ); | ||
| })} | ||
| </tbody> | ||
| </table> | ||
| </main> | ||
| ); | ||
| } | ||
| } | ||
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.
Consider specifying the type of the props in the
React.Componentgeneric type. Currently, it's using an empty object{}which is fine if there are no props, but it's good practice to explicitly define it for clarity and future maintenance.