Skip to content
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: 5 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"devDependencies": {
"@cypress/react18": "^2.0.1",
"@mate-academy/scripts": "^1.8.5",
"@mate-academy/scripts": "^2.1.3",
"@mate-academy/students-ts-config": "*",
"@mate-academy/stylelint-config": "*",
"@types/node": "^20.14.10",
Expand Down
133 changes: 84 additions & 49 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import React from 'react';
import 'bulma/css/bulma.css';
import './App.scss';

type State = {
selectedGood: string;
};

type Props = {};

export const goods = [
'Dumplings',
'Carrot',
Expand All @@ -15,58 +21,87 @@ export const goods = [
'Garlic',
];

export const App: React.FC = () => (
<main className="section container">
<h1 className="title">No goods selected</h1>

<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<Props, State> {
state: State = {
selectedGood: 'Jam',
};

<table className="table">
<tbody>
<tr data-cy="Good">
<td>
<button data-cy="AddButton" type="button" className="button">
+
</button>
</td>
handelClick = (good: string) => {

Choose a reason for hiding this comment

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

This violates checklist item #1: "Method's name should start with a verb". There seems to be a typo in the method name. It should be handleClick to start with a verb and follow common naming conventions.

if (good === this.state.selectedGood) {
this.clearSelection();
} else {
this.selectGood(good);
}
}

<td data-cy="GoodTitle" className="is-vcentered">
Dumplings
</td>
</tr>
clearSelection = () => {
this.setState({ selectedGood: '' });
};

<tr data-cy="Good" className="has-background-success-light">
<td>
<button
data-cy="RemoveButton"
type="button"
className="button is-info"
>
-
</button>
</td>
selectGood = (good: string) => {
this.setState({ selectedGood: good });
};

<td data-cy="GoodTitle" className="is-vcentered">
Jam
</td>
</tr>
render() {
return (
<main className="section container">
<h1 className="title is-flex is-align-items-center">
{this.state.selectedGood !== '' ? (
<>
{this.state.selectedGood} is selected
<button
data-cy="ClearButton"
type="button"
className="delete ml-3"
onClick={this.clearSelection}
/>
</>
) : (
'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
key={good}
data-cy="Good"
className={
good === this.state.selectedGood
? 'has-background-success-light'
: ''
}
>
<td>
<button
data-cy={
good === this.state.selectedGood
? 'RemoveButton'
: 'AddButton'
}
type="button"
className={
good === this.state.selectedGood
? 'button is-info'
: 'button'
}
onClick={() => this.handelClick(good)}
>
{good === this.state.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>
);
}
}