@@ -6,12 +6,14 @@ import { GlobalStyles } from './styles';
66import Table from './components/Table' ;
77import Select from './components/Select' ;
88import DB from './models/DB' ;
9+ import Loader from './components/Loader' ;
910
1011type SQLiteExplorerProps = {
1112 params : DBParamsType ;
1213} ;
1314
1415const SQLiteExplorer = ( { params } : SQLiteExplorerProps ) => {
16+ const [ status , setStatus ] = useState < 'loading' | '' > ( '' ) ;
1517 const [ signatures , setSignatures ] = useState < TableSignature [ ] > ( [ ] ) ;
1618 const [ tableData , setTableData ] = useState < TableSignature | null > ( null ) ;
1719 const [ select , setSelect ] = useState ( '' ) ;
@@ -33,6 +35,8 @@ const SQLiteExplorer = ({ params }: SQLiteExplorerProps) => {
3335 const loadBase = async ( ) => {
3436 if ( ! DB ) return ;
3537
38+ setStatus ( 'loading' ) ;
39+
3640 try {
3741 await DB . open ( params ) ;
3842 setSignatures (
@@ -46,13 +50,19 @@ const SQLiteExplorer = ({ params }: SQLiteExplorerProps) => {
4650 'Не удалось открыть базу данных: ' + error . message
4751 ) ;
4852 }
53+
54+ setStatus ( '' ) ;
4955 } ;
5056
5157 const queryTableData = async ( signature : TableSignature ) => {
5258 if ( ! signature ) return ;
5359
60+ setStatus ( 'loading' ) ;
61+
5462 const signatureWithValues = await DB . insertValuesIntoSignature ( signature ) ;
5563 setTableData ( signatureWithValues ) ;
64+
65+ setStatus ( '' ) ;
5666 } ;
5767
5868 const onActionSuccess = async ( tableData : TableSignature ) => {
@@ -75,9 +85,11 @@ const SQLiteExplorer = ({ params }: SQLiteExplorerProps) => {
7585 />
7686 </ View >
7787
78- { ! ! tableData ? (
88+ { status === 'loading' && < Loader /> }
89+ { status !== 'loading' && ! ! tableData && (
7990 < Table tableData = { tableData } onActionSuccess = { onActionSuccess } />
80- ) : (
91+ ) }
92+ { status !== 'loading' && ! tableData && (
8193 < Text style = { styles . StatusText } > Empty</ Text >
8294 ) }
8395 </ View >
0 commit comments