Skip to content

Commit 943974b

Browse files
committed
Add error handling and render author's initial name
1 parent 1d83c5e commit 943974b

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/Components/Commit/CommitList.js

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { ActivityIndicator, Dimensions, FlatList, Platform, View } from 'react-native';
3-
import { Avatar, ListItem } from 'react-native-elements';
3+
import { Avatar, ListItem, Text } from 'react-native-elements';
44
import { compose } from 'redux';
55
import fetch from 'fetch-hoc';
66

@@ -25,15 +25,20 @@ const leftElementStyle = {
2525
class CommitList extends React.PureComponent {
2626
keyExtractor = (item) => item.sha
2727

28-
renderLeftElement = (item) => (
29-
<View style={leftElementStyle}>
30-
<Avatar
31-
source={{ uri: item.author.avatar_url }}
32-
size='medium'
33-
rounded
34-
/>
35-
</View>
36-
)
28+
renderLeftElement = (item) => {
29+
const initials = item.commit.author.name.match(/\b\w/g) || [];
30+
31+
return (
32+
<View style={leftElementStyle}>
33+
<Avatar
34+
title={((initials.shift() || '') + (initials.pop() || ''))}
35+
source={{ uri: (item.author && item.author.avatar_url) || undefined }}
36+
size='medium'
37+
rounded
38+
/>
39+
</View>
40+
);
41+
}
3742

3843
renderItem = ({ item }) => (
3944
<ListItem
@@ -48,6 +53,12 @@ class CommitList extends React.PureComponent {
4853
renderContent = () => (
4954
this.props.loading ?
5055
<ActivityIndicator color='#87ceeb' /> :
56+
this.renderFlatList()
57+
)
58+
59+
renderFlatList = () => (
60+
this.props.error ?
61+
<Text h4>Error: {this.props.data.message || 'Something went wrong 😕'}</Text> :
5162
<FlatList
5263
keyExtractor={this.keyExtractor}
5364
data={this.props.data}

0 commit comments

Comments
 (0)