Skip to content

Commit 2cc904b

Browse files
committed
Implement animated <List /> component
1 parent 94308e7 commit 2cc904b

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

client/components/List.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import {List as SuiList, TransitionGroup} from 'semantic-ui-react';
4+
5+
export default class List extends React.Component {
6+
render() {
7+
const {children, elements} = this.props;
8+
return (
9+
<TransitionGroup
10+
as={SuiList}
11+
duration={200}
12+
animation="fade left"
13+
>
14+
{elements.map(element => (
15+
<SuiList.Item key={element._id}>
16+
{children(element)}
17+
</SuiList.Item>
18+
))}
19+
</TransitionGroup>
20+
);
21+
}
22+
}
23+
24+
List.propTypes = {
25+
children: PropTypes.func.isRequired,
26+
elements: PropTypes.array.isRequired,
27+
};

client/pages/VinNumbers/VinNumberCard.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import {Button, Card} from 'semantic-ui-react';
4+
import {removeVin} from '/imports/api/vinNumbers/methods';
45

56
export default class VinNumberCard extends React.Component {
6-
// @todo #16:30min Implement remove VIN method
7+
onRemove() {
8+
const {vin: {_id}} = this.props;
9+
removeVin.callPromise({_id})
10+
.catch((err) => {
11+
alert('An error occured. Please check the console');
12+
console.error(err);
13+
});
14+
}
15+
716
// @todo #16:30min Implement approve VIN method
817
render() {
918
const {vin} = this.props;
@@ -16,7 +25,7 @@ export default class VinNumberCard extends React.Component {
1625
<Card.Content extra>
1726
<Button.Group fluid>
1827
<Button basic positive>Approve</Button>
19-
<Button basic negative>Remove</Button>
28+
<Button basic negative onClick={() => this.onRemove()}>Remove</Button>
2029
</Button.Group>
2130
</Card.Content>
2231
</Card>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import VinNumberCard from './VinNumberCard';
4+
import List from '/client/components/List';
5+
6+
export default class VinNumbers extends React.Component {
7+
render() {
8+
const {vinNumbers} = this.props;
9+
return (
10+
<List elements={vinNumbers}>
11+
{vin => <VinNumberCard vin={vin} />}
12+
</List>
13+
);
14+
}
15+
}
16+
17+
VinNumbers.propTypes = {
18+
vinNumbers: PropTypes.array.isRequired,
19+
};

client/pages/VinNumbers/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
44
import Loader from '/client/components/Loader';
55
import {VinNumbers} from '/imports/api/vinNumbers/collection';
66
import AddVinForm from './AddVinForm';
7-
import VinNumberCard from './VinNumberCard';
7+
import VinNumbersList from './VinNumbersList';
88

99
class VinNumbersPage extends React.Component {
1010
renderVinNumbersList() {
@@ -13,9 +13,7 @@ class VinNumbersPage extends React.Component {
1313
return <Loader />;
1414
}
1515

16-
return vinNumbers.map(vin => (
17-
<VinNumberCard key={vin._id} vin={vin} />
18-
));
16+
return <VinNumbersList vinNumbers={vinNumbers} />;
1917
}
2018

2119
render() {

0 commit comments

Comments
 (0)