Skip to content

Commit 3d71ea0

Browse files
Merge pull request #259 from GetStream/CRNS-118/indicators
CRNS-118/Indicators
2 parents 1c75dc1 + d265890 commit 3d71ea0

File tree

3 files changed

+47
-71
lines changed

3 files changed

+47
-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: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,50 @@
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-
};
25-
26-
static defaultProps = {
27-
listType: 'default',
28-
};
21+
const LoadingIndicator = ({ listType = 'default', loadingText }) => {
22+
const { t } = useContext(TranslationContext);
23+
let indicatorText = '';
2924

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-
}
25+
switch (listType) {
26+
case 'channel':
27+
indicatorText = loadingText ? loadingText : t('Loading channels ...');
28+
break;
29+
case 'message':
30+
indicatorText = loadingText ? loadingText : t('Loading messages ...');
31+
break;
32+
case 'default':
33+
default:
34+
indicatorText = loadingText ? loadingText : t('Loading ...');
6235
}
63-
}
6436

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

0 commit comments

Comments
 (0)