Skip to content

Commit

Permalink
Merge pull request #6 from LeleDallas/feat/no-data
Browse files Browse the repository at this point in the history
feat: no data view
  • Loading branch information
LeleDallas authored Jul 9, 2024
2 parents b0561ae + 011ef40 commit 98805c3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
17 changes: 17 additions & 0 deletions __tests__/NoData.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { render } from "@testing-library/react-native";
import NoData from "../src/components/NoData";


describe('NoData', () => {
it('should render correctly', () => {
const { queryByTestId } = render(<NoData length={0} loading={false} />);
expect(queryByTestId('loading')).toBeNull();
});


it('should render nothing', () => {
const { queryByTestId } = render(<NoData length={1} loading={false} />);
expect(queryByTestId('loading')).toBeNull();
expect(queryByTestId('no-data')).toBeNull();
});
})
1 change: 1 addition & 0 deletions android/app/src/main/assets/images/spinner2.json

Large diffs are not rendered by default.

Binary file added assets/noData.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/components/NoData/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Image, Text, View } from "react-native";
import { globalStyle } from "../../styles";

type Props = {
length: number;
loading: boolean;
}

export default ({ length, loading }: Props) =>
length === 0 && !loading &&
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Image source={require('../../../assets/noData.png')} style={{ width: 200, height: 200, alignSelf: 'center' }} />
<Text style={globalStyle.text}>No data found</Text>
</View>

32 changes: 23 additions & 9 deletions src/components/Spinner/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import LottieView from "lottie-react-native";
import { View } from "react-native";
import { ActivityIndicator, Platform, View } from "react-native";
import { colors } from "../../styles";

export default () =>
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<LottieView
style={{ width: "100%", height: "100%" }}
source={require("../../../assets/spinner2.json")}
autoPlay
loop
/>
</View>
Platform.OS === "ios" ? (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<LottieView
style={{ width: "100%", height: "100%" }}
source={require("../../../assets/spinner2.json")}
autoPlay
loop
/>
</View>) : (
<View style={{
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
alignItems: 'center',
justifyContent: 'center'
}}>
<ActivityIndicator size={200} color={colors.buttonActive} />
</View>
);
4 changes: 3 additions & 1 deletion src/screens/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useState } from 'react';
import { TextInput, TouchableOpacity, View } from 'react-native';
import { Image, Text, TextInput, TouchableOpacity, View } from 'react-native';
import Octicons from 'react-native-vector-icons/Octicons';
import api from '../api';
import UserList from '../components/List/UserList';
import { colors, globalStyle } from '../styles';
import { User } from '../types/response';
import NoData from '../components/NoData';

export default () => {
const [name, setName] = useState('');
Expand Down Expand Up @@ -37,6 +38,7 @@ export default () => {
<Octicons name="search" color={colors.text} size={20} />
</TouchableOpacity>
</View>
<NoData length={data.length} loading={loading} />
<UserList users={data} loading={loading} />
</>
);
Expand Down

0 comments on commit 98805c3

Please sign in to comment.