-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cfa7ec
commit 2155091
Showing
38 changed files
with
411 additions
and
482 deletions.
There are no files selected for viewing
This file contains 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,35 +1,35 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"jest": true | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"jest": true | ||
}, | ||
"parser": "@babel/eslint-parser", | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"parser": "@babel/eslint-parser", | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"extends": ["plugin:react/recommended", "plugin:react-hooks/recommended"], | ||
"plugins": ["react"], | ||
"rules": { | ||
"react/jsx-filename-extension": ["warn", { "extensions": [".js", ".jsx"] }], | ||
"react/react-in-jsx-scope": "off", | ||
"import/no-unresolved": "off", | ||
"no-shadow": "off" | ||
}, | ||
"overrides": [ | ||
{ | ||
// feel free to replace with your preferred file pattern - eg. 'src/**/*Slice.js' or 'redux/**/*Slice.js' | ||
"files": ["src/**/*Slice.js"], | ||
// avoid state param assignment | ||
"rules": { "no-param-reassign": ["error", { "props": false }] } | ||
} | ||
], | ||
"ignorePatterns": [ | ||
"dist/", | ||
"build/" | ||
] | ||
} | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"extends": ["airbnb", "plugin:react/recommended", "plugin:react-hooks/recommended"], | ||
"plugins": ["react"], | ||
"rules": { | ||
"react/jsx-filename-extension": ["warn", { "extensions": [".js", ".jsx"] }], | ||
"react/react-in-jsx-scope": "off", | ||
"import/no-unresolved": "off", | ||
"no-shadow": "off" | ||
}, | ||
"overrides": [ | ||
{ | ||
// feel free to replace with your preferred file pattern - eg. 'src/**/*Slice.js' or 'redux/**/*Slice.js' | ||
"files": ["src/**/*Slice.js"], | ||
// avoid state param assignment | ||
"rules": { "no-param-reassign": ["error", { "props": false }] } | ||
} | ||
], | ||
"ignorePatterns": [ | ||
"dist/", | ||
"build/" | ||
] | ||
} |
This file contains 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 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 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 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,45 +1,45 @@ | ||
import React from 'react'; | ||
import { useSelector } from "react-redux"; | ||
import { useSelector } from 'react-redux'; | ||
import EachCarDelete from './EachCarDelete'; | ||
|
||
const DeleteList = () => { | ||
const cars = useSelector((state) => state.cars.cars) | ||
// const mockData = [ | ||
// { | ||
// "id": 3, | ||
// "name": "Car1", | ||
// "description": "Description for Car1", | ||
// "removed": false | ||
// }, | ||
// { | ||
// "id": 4, | ||
// "name": "Car1111", | ||
// "description": "Description for Car1", | ||
// "removed": false | ||
// } | ||
// ]; | ||
// const cars = mockData; | ||
const cars = useSelector((state) => state.cars.cars); | ||
// const mockData = [ | ||
// { | ||
// "id": 3, | ||
// "name": "Car1", | ||
// "description": "Description for Car1", | ||
// "removed": false | ||
// }, | ||
// { | ||
// "id": 4, | ||
// "name": "Car1111", | ||
// "description": "Description for Car1", | ||
// "removed": false | ||
// } | ||
// ]; | ||
// const cars = mockData; | ||
|
||
return ( | ||
<> | ||
<div> | ||
<h1>Cars List</h1> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Car Title</th> | ||
<th>Status</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{cars.map((car) => ( | ||
<EachCarDelete key={car.id} car={car} /> | ||
))} | ||
</tbody> | ||
<thead> | ||
<tr> | ||
<th>Car Title</th> | ||
<th>Status</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{cars.map((car) => ( | ||
<EachCarDelete key={car.id} car={car} /> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default DeleteList; | ||
export default DeleteList; |
This file contains 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,38 +1,37 @@ | ||
import PropTypes from 'prop-types'; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { deleteCar } from "../../redux/thunk"; | ||
import { markCarDelete } from "../../redux/cars/carsSlice"; | ||
import { useDispatch } from 'react-redux'; | ||
import { deleteCar } from '../../redux/thunk'; | ||
import { removeMarkStatus } from '../../redux/cars/carsSlice'; | ||
|
||
const EachCarDelete = ({car}) => { | ||
const { | ||
name, | ||
id, | ||
removed | ||
} = car; | ||
const dispatch = useDispatch(); | ||
const handleDelete = () => { | ||
dispatch(deleteCar(id)); | ||
if(!removed) { | ||
dispatch(markCarDelete(id)) | ||
} | ||
const EachCarDelete = ({ car }) => { | ||
const { | ||
name, | ||
id, | ||
removed, | ||
} = car; | ||
const dispatch = useDispatch(); | ||
const handleDelete = () => { | ||
if (removed) { | ||
return; | ||
} | ||
|
||
|
||
|
||
return ( | ||
<tr> | ||
<td>{name}</td> | ||
<td><button type='button' className={removed ? 'removed-mark' : 'remove-mark'} onClick={handleDelete}>{removed ? 'removed' : 'DELETE'}</button></td> | ||
</tr> | ||
) | ||
} | ||
dispatch(deleteCar(id)); | ||
dispatch(removeMarkStatus(id)); | ||
}; | ||
return ( | ||
<tr> | ||
<td>{name}</td> | ||
<td><button type="button" className={removed ? 'removed-mark' : 'remove-mark'} onClick={handleDelete} disabled={removed}>{removed ? 'removed' : 'DELETE'}</button></td> | ||
</tr> | ||
); | ||
}; | ||
|
||
EachCarDelete.propTypes = { | ||
car: PropTypes.shape({ | ||
name: PropTypes.string.isRequired, | ||
id: PropTypes.number.isRequired, | ||
removed: PropTypes.bool.isRequired, | ||
}).isRequired, | ||
car: PropTypes.shape({ | ||
name: PropTypes.string.isRequired, | ||
id: PropTypes.number.isRequired, | ||
removed: PropTypes.bool.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
export default EachCarDelete; |
This file contains 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
Oops, something went wrong.