Massive/App.tsx

68 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-07-08 03:51:19 +00:00
import AsyncStorage from '@react-native-async-storage/async-storage';
import {createDrawerNavigator} from '@react-navigation/drawer';
2022-06-30 06:50:52 +00:00
import {
2022-07-03 01:50:01 +00:00
DarkTheme,
DefaultTheme,
NavigationContainer,
} from '@react-navigation/native';
import React, {useEffect, useState} from 'react';
2022-07-05 12:06:16 +00:00
import {StatusBar, useColorScheme} from 'react-native';
import {
DarkTheme as DarkThemePaper,
DefaultTheme as DefaultThemePaper,
Provider,
} from 'react-native-paper';
import {SQLiteDatabase} from 'react-native-sqlite-storage';
import Ionicon from 'react-native-vector-icons/Ionicons';
2022-07-08 03:51:19 +00:00
import {createPlans, createSets, getDb} from './db';
2022-07-15 04:34:06 +00:00
import Routes from './Routes';
2022-07-03 01:50:01 +00:00
2022-07-15 04:34:06 +00:00
export const Drawer = createDrawerNavigator<DrawerParamList>();
export type DrawerParamList = {
2022-07-03 01:50:01 +00:00
Home: {};
Settings: {};
Best: {};
2022-07-11 00:28:30 +00:00
Plans: {};
2022-07-03 01:50:01 +00:00
};
export const DatabaseContext = React.createContext<SQLiteDatabase>({} as any);
2022-06-30 06:50:52 +00:00
2022-07-08 03:51:19 +00:00
const {getItem, setItem} = AsyncStorage;
2022-07-01 01:42:42 +00:00
const App = () => {
const [db, setDb] = useState<SQLiteDatabase | null>(null);
2022-07-01 01:42:42 +00:00
const dark = useColorScheme() === 'dark';
2022-07-03 01:50:01 +00:00
useEffect(() => {
2022-07-09 01:27:19 +00:00
const init = async () => {
const gotDb = await getDb();
await gotDb.executeSql(createPlans);
await gotDb.executeSql(createSets);
setDb(gotDb);
const minutes = await getItem('minutes');
if (minutes === null) await setItem('minutes', '3');
const seconds = await getItem('seconds');
if (seconds === null) await setItem('seconds', '30');
const alarmEnabled = await getItem('alarmEnabled');
if (alarmEnabled === null) await setItem('alarmEnabled', 'false');
2022-07-10 05:53:38 +00:00
if (!(await getItem('predictiveSets')))
await setItem('predictiveSets', 'true');
if (!(await getItem('maxSets'))) await setItem('maxSets', '3');
2022-07-09 01:27:19 +00:00
};
init();
2022-07-03 01:50:01 +00:00
}, []);
2022-06-30 06:50:52 +00:00
return (
<Provider
theme={dark ? DarkThemePaper : DefaultThemePaper}
settings={{icon: props => <Ionicon {...props} />}}>
<NavigationContainer theme={dark ? DarkTheme : DefaultTheme}>
<StatusBar barStyle={dark ? 'light-content' : 'dark-content'} />
2022-07-15 04:34:06 +00:00
<Routes db={db} />
</NavigationContainer>
</Provider>
2022-06-30 06:50:52 +00:00
);
};
export default App;