From be7f0cf1937dc89d0588bcbeae5f41fc662ae39c Mon Sep 17 00:00:00 2001 From: Bruno Lemos Date: Sat, 13 Oct 2018 21:15:10 -0300 Subject: [PATCH] Fix warning about duplicated key --- src/components/cards/EventCards.tsx | 11 ++--------- src/components/cards/NotificationCards.tsx | 16 +++------------- src/containers/EventCardsContainer.tsx | 5 ++++- src/containers/NotificationCardsContainer.tsx | 9 ++++----- 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/components/cards/EventCards.tsx b/src/components/cards/EventCards.tsx index 9acca508..2e3c3564 100644 --- a/src/components/cards/EventCards.tsx +++ b/src/components/cards/EventCards.tsx @@ -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 ( ) } - return ( - - ) + return } render() { diff --git a/src/components/cards/NotificationCards.tsx b/src/components/cards/NotificationCards.tsx index 37a13842..4dcdef0f 100644 --- a/src/components/cards/NotificationCards.tsx +++ b/src/components/cards/NotificationCards.tsx @@ -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 ( - - ) + return } - return ( - - ) + return } render() { diff --git a/src/containers/EventCardsContainer.tsx b/src/containers/EventCardsContainer.tsx index ac98956d..c86758a9 100644 --- a/src/containers/EventCardsContainer.tsx +++ b/src/containers/EventCardsContainer.tsx @@ -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 }) } diff --git a/src/containers/NotificationCardsContainer.tsx b/src/containers/NotificationCardsContainer.tsx index 8eec495d..5208d8d9 100644 --- a/src/containers/NotificationCardsContainer.tsx +++ b/src/containers/NotificationCardsContainer.tsx @@ -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) {