diff --git a/src/components/Loading.jsx b/src/components/Loading.jsx index 97f5f98..d1bb6cb 100644 --- a/src/components/Loading.jsx +++ b/src/components/Loading.jsx @@ -1,7 +1,12 @@ +import { bool } from 'prop-types'; import React from 'react'; import { View, StyleSheet, ActivityIndicator } from 'react-native'; -function Loading() { +function Loading(props) { + const { isLoading } = props; + if (!isLoading) { + return null; + } return ( @@ -10,6 +15,12 @@ function Loading() { ); } +Loading.propTypes = { + isLoading: bool, +}; +Loading.defaultProps = { + isLoading: false, +}; const styles = StyleSheet.create({ container: { position: 'absolute', diff --git a/src/screens/MemoListScreen.jsx b/src/screens/MemoListScreen.jsx index 6543142..7be1572 100644 --- a/src/screens/MemoListScreen.jsx +++ b/src/screens/MemoListScreen.jsx @@ -10,6 +10,7 @@ import Loading from '../components/Loading'; function MemoListScreen(props) { const { navigation } = props; const [memos, setMemos] = useState([]); + const [isLoading, setIsLoading] = useState(false); useEffect(() => { navigation.setOptions({ // eslint-disable-next-line react/no-unstable-nested-components @@ -21,6 +22,7 @@ function MemoListScreen(props) { const { currentUser } = firebase.auth(); let unscribe = () => {}; if (currentUser) { + setIsLoading(true); const ref = db .collection(`users/${currentUser.uid}/memos`) .orderBy('updatedAt', 'desc'); @@ -36,9 +38,11 @@ function MemoListScreen(props) { }); }); setMemos(userMemos); + setIsLoading(false); }, (error) => { console.log(error); + setIsLoading(false); Alert.alert('データの読み込みに失敗しました'); } ); @@ -48,6 +52,7 @@ function MemoListScreen(props) { if (memos.length === 0) { return ( + 最初のメモを作成しよう!