Fix warning about duplicated key

This commit is contained in:
Bruno Lemos
2018-10-13 21:15:10 -03:00
parent 7d58f9482e
commit be7f0cf193
4 changed files with 13 additions and 28 deletions

View File

@@ -22,27 +22,20 @@ export default class EventCards extends PureComponent<
EventCardsState
> {
keyExtractor(event: IEnhancedGitHubEvent) {
return `${event.id}`
return `event-card-${event.id}`
}
renderItem = ({ item: event }: { item: IEnhancedGitHubEvent }) => {
if (this.props.swipeable) {
return (
<SwipeableEventCard
key={`event-card-${event.id}`}
event={event}
repoIsKnown={this.props.repoIsKnown}
/>
)
}
return (
<EventCard
key={`event-card-${event.id}`}
event={event}
repoIsKnown={this.props.repoIsKnown}
/>
)
return <EventCard event={event} repoIsKnown={this.props.repoIsKnown} />
}
render() {

View File

@@ -21,25 +21,15 @@ export default class NotificationCards extends PureComponent<
NotificationCardsState
> {
keyExtractor(notification: IGitHubNotification) {
return `${notification.id}`
return `notification-card-${notification.id}`
}
renderItem = ({ item: notification }: { item: IGitHubNotification }) => {
if (this.props.swipeable) {
return (
<SwipeableNotificationCard
key={`notification-card-${notification.id}`}
notification={notification}
/>
)
return <SwipeableNotificationCard notification={notification} />
}
return (
<NotificationCard
key={`notification-card-${notification.id}`}
notification={notification}
/>
)
return <NotificationCard notification={notification} />
}
render() {

View File

@@ -62,7 +62,10 @@ export default class EventCardsContainer extends PureComponent<
)
const events: IGitHubEvent[] = await response.json()
if (Array.isArray(events)) {
const orderedEvents = _.orderBy(events, ['updated_at'], ['desc'])
const orderedEvents = _(events)
.uniqBy('id')
.orderBy(['updated_at'], ['desc'])
.value()
const mergedEvents = mergeSimilarEvent(orderedEvents)
this.setState({ events: mergedEvents })
}

View File

@@ -60,11 +60,10 @@ export default class NotificationCardsContainer extends PureComponent<
const notifications: IGitHubNotification[] = await response.json()
if (Array.isArray(notifications)) {
this.setState({
notifications: _.orderBy(
notifications,
['unread', 'updated_at'],
['desc', 'desc'],
),
notifications: _(notifications)
.uniqBy('id')
.orderBy(['unread', 'updated_at'], ['desc', 'desc'])
.value(),
})
}
} catch (error) {