Skip to content

Commit 4724722

Browse files
author
Dan Carbonell
committed
refactor Indicators
1 parent 8ffa733 commit 4724722

File tree

3 files changed

+52
-71
lines changed

3 files changed

+52
-71
lines changed

src/components/Indicators/EmptyStateIndicator.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@ import React from 'react';
22
import { Text } from 'react-native';
33

44
const EmptyStateIndicator = ({ listType }) => {
5-
let Indicator;
65
switch (listType) {
76
case 'channel':
8-
Indicator = <Text>You have no channels currently</Text>;
9-
break;
7+
return <Text>You have no channels currently</Text>;
108
case 'message':
11-
Indicator = null;
12-
break;
9+
return null;
1310
default:
14-
Indicator = <Text>No items exist</Text>;
15-
break;
11+
return <Text>No items exist</Text>;
1612
}
17-
18-
return Indicator;
1913
};
2014

2115
export default EmptyStateIndicator;
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import React from 'react';
1+
import React, { useContext } from 'react';
22
import styled from '@stream-io/styled-components';
33
import PropTypes from 'prop-types';
4-
import { withTranslationContext } from '../../context';
4+
5+
import { TranslationContext } from '../../context';
56

67
const Container = styled.TouchableOpacity`
8+
align-items: center;
79
height: 100%;
810
justify-content: center;
9-
align-items: center;
1011
${({ theme }) => theme.loadingErrorIndicator.container.css}
1112
`;
1213

1314
const ErrorText = styled.Text`
14-
margin-top: 20px;
1515
font-size: 14px;
1616
font-weight: 600;
17+
margin-top: 20px;
1718
${({ theme }) => theme.loadingErrorIndicator.errorText.css}
1819
`;
1920

@@ -23,11 +24,12 @@ const RetryText = styled.Text`
2324
${({ theme }) => theme.loadingErrorIndicator.retryText.css}
2425
`;
2526

26-
const LoadingErrorIndicator = ({ listType, retry, t }) => {
27-
let Loader;
27+
const LoadingErrorIndicator = ({ listType, retry }) => {
28+
const { t } = useContext(TranslationContext);
29+
2830
switch (listType) {
2931
case 'channel':
30-
Loader = (
32+
return (
3133
<Container
3234
onPress={() => {
3335
retry && retry();
@@ -37,26 +39,21 @@ const LoadingErrorIndicator = ({ listType, retry, t }) => {
3739
<RetryText></RetryText>
3840
</Container>
3941
);
40-
break;
4142
case 'message':
42-
Loader = (
43+
return (
4344
<Container>
4445
<ErrorText>
4546
{t('Error loading messages for this channel ...')}
4647
</ErrorText>
4748
</Container>
4849
);
49-
break;
5050
default:
51-
Loader = (
51+
return (
5252
<Container>
5353
<ErrorText>{t('Error loading')}</ErrorText>
5454
</Container>
5555
);
56-
break;
5756
}
58-
59-
return Loader;
6057
};
6158

6259
LoadingErrorIndicator.propTypes = {
@@ -65,4 +62,4 @@ LoadingErrorIndicator.propTypes = {
6562
retry: PropTypes.func,
6663
};
6764

68-
export default withTranslationContext(LoadingErrorIndicator);
65+
export default LoadingErrorIndicator;
Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,55 @@
1-
import React from 'react';
1+
import React, { useContext } from 'react';
22
import styled from '@stream-io/styled-components';
33
import PropTypes from 'prop-types';
4+
5+
import { TranslationContext } from '../../context';
46
import { Spinner } from '../Spinner';
5-
import { withTranslationContext } from '../../context';
67

78
const Container = styled.View`
9+
align-items: center;
810
height: 100%;
911
justify-content: center;
10-
align-items: center;
1112
${({ theme }) => theme.loadingIndicator.container.css}
1213
`;
1314
const LoadingText = styled.Text`
14-
margin-top: 20px;
1515
font-size: 14px;
1616
font-weight: 600;
17+
margin-top: 20px;
1718
${({ theme }) => theme.loadingIndicator.loadingText.css}
1819
`;
1920

20-
class LoadingIndicator extends React.PureComponent {
21-
static propTypes = {
22-
listType: PropTypes.oneOf(['channel', 'message', 'default']),
23-
loadingText: PropTypes.string,
24-
};
21+
const LoadingIndicator = (props) => {
22+
const { listType, loadingText } = props;
23+
const { t } = useContext(TranslationContext);
24+
let indicatorText = '';
2525

26-
static defaultProps = {
27-
listType: 'default',
28-
};
29-
30-
render() {
31-
const { t, listType, loadingText } = this.props;
32-
switch (listType) {
33-
case 'channel':
34-
return (
35-
<Container>
36-
<Spinner />
37-
<LoadingText>
38-
{loadingText ? loadingText : t('Loading channels ...')}
39-
</LoadingText>
40-
</Container>
41-
);
42-
case 'message':
43-
return (
44-
<Container>
45-
<Spinner />
46-
<LoadingText>
47-
{loadingText ? loadingText : t('Loading messages ...')}
48-
</LoadingText>
49-
</Container>
50-
);
51-
case 'default':
52-
default:
53-
return (
54-
<Container>
55-
<Spinner />
56-
<LoadingText>
57-
{loadingText ? loadingText : t('Loading ...')}
58-
</LoadingText>
59-
</Container>
60-
);
61-
}
26+
switch (listType) {
27+
case 'channel':
28+
indicatorText = loadingText ? loadingText : t('Loading channels ...');
29+
break;
30+
case 'message':
31+
indicatorText = loadingText ? loadingText : t('Loading messages ...');
32+
break;
33+
case 'default':
34+
default:
35+
indicatorText = loadingText ? loadingText : t('Loading ...');
6236
}
63-
}
6437

65-
export default withTranslationContext(LoadingIndicator);
38+
return (
39+
<Container>
40+
<Spinner />
41+
<LoadingText>{indicatorText}</LoadingText>
42+
</Container>
43+
);
44+
};
45+
46+
LoadingIndicator.propTypes = {
47+
listType: PropTypes.oneOf(['channel', 'message', 'default']),
48+
loadingText: PropTypes.string,
49+
};
50+
51+
LoadingIndicator.defaultProps = {
52+
listType: 'default',
53+
};
54+
55+
export default LoadingIndicator;

0 commit comments

Comments
 (0)