diff --git a/Alarm.tsx b/Alarm.tsx index ea9408b..abc0c77 100644 --- a/Alarm.tsx +++ b/Alarm.tsx @@ -1,86 +1,59 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; import React, {useEffect, useState} from 'react'; -import {Button, Modal, StyleSheet, Text, View} from 'react-native'; -import BackgroundTimer from 'react-native-background-timer'; +import {StyleSheet, Text} from 'react-native'; +import {Button, Modal, Portal} from 'react-native-paper'; -export default function Alarm({onClose}: {onClose: () => void}) { +export default function Alarm() { + const [show, setShow] = useState(false); const [seconds, setSeconds] = useState(0); const [minutes, setMinutes] = useState(0); let intervalId: number; useEffect(() => { - AsyncStorage.getItem('nextAlarm').then(async next => { + intervalId = setInterval(async () => { + const next = await AsyncStorage.getItem('nextAlarm'); if (!next) return; const ms = new Date(next).getTime() - new Date().getTime(); if (ms <= 0) return; let secondsLeft = ms / 1000; - console.log({secondsLeft}); + secondsLeft--; + if (secondsLeft <= 0) return clearInterval(intervalId); setSeconds(Math.floor(secondsLeft % 60)); setMinutes(Math.floor(secondsLeft / 60)); - - intervalId = setInterval(() => { - console.log({seconds, secondsLeft}); - secondsLeft--; - if (secondsLeft <= 0) return clearInterval(intervalId); - setSeconds(Math.floor(secondsLeft % 60)); - setMinutes(Math.floor(secondsLeft / 60)); - }, 1000); - }); + }, 1000); return () => clearInterval(intervalId); }, []); - const stop = () => { - BackgroundTimer.clearInterval(intervalId); - onClose(); - }; - return ( - - - Rest - - {minutes}:{seconds} - - - - + + + + ); } const styles = StyleSheet.create({ - timer: { - marginBottom: 20, - }, - title: { - fontSize: 20, + center: { + alignItems: 'center', + alignSelf: 'center', marginBottom: 10, }, - modal: { - margin: 20, - backgroundColor: '#20232a', - padding: 20, - shadowColor: '#000', - shadowOffset: { - width: 0, - height: 2, - }, - shadowOpacity: 0.25, - shadowRadius: 4, - elevation: 5, - alignItems: 'center', - }, - button: { - marginRight: 10, + title: { + fontSize: 18, }, }); diff --git a/App.tsx b/App.tsx index 63565fa..2c91f24 100644 --- a/App.tsx +++ b/App.tsx @@ -1,5 +1,5 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; -import {createBottomTabNavigator} from '@react-navigation/bottom-tabs'; +import {createMaterialTopTabNavigator} from '@react-navigation/material-top-tabs'; import { DarkTheme, DefaultTheme, @@ -11,14 +11,12 @@ import {setupSchema} from './db'; import Exercises from './Exercises'; import Home from './Home'; import Settings from './Settings'; -import Ionicons from 'react-native-vector-icons/Ionicons'; -const Tab = createBottomTabNavigator(); +const Tab = createMaterialTopTabNavigator(); export type RootStackParamList = { Home: {}; - Exercises: {}; Settings: {}; - Alarm: {}; + Exercises: {}; }; setupSchema(); @@ -35,22 +33,7 @@ const App = () => { return ( - ({ - tabBarIcon: ({focused, color, size}) => { - let icon = ''; - - if (route.name === 'Home') icon = focused ? 'home' : 'home-outline'; - else if (route.name === 'Settings') - icon = focused ? 'settings' : 'settings-outline'; - else if (route.name === 'Exercises') - icon = focused ? 'barbell' : 'barbell-outline'; - // You can return any component that you like here! - return ; - }, - tabBarActiveTintColor: 'tomato', - tabBarInactiveTintColor: 'gray', - })}> + diff --git a/EditSet.tsx b/EditSet.tsx index cb40d66..9a24cdb 100644 --- a/EditSet.tsx +++ b/EditSet.tsx @@ -1,8 +1,8 @@ import React, {useEffect, useRef, useState} from 'react'; -import {Modal, StyleSheet, Text, TextInput, View} from 'react-native'; -import {Button} from 'react-native-paper'; +import {StyleSheet, Text, View} from 'react-native'; +import {Button, Modal, Portal, TextInput} from 'react-native-paper'; import {getDb} from './db'; -import Set from './Set'; +import Set from './set'; export default function EditSet({ id, @@ -21,9 +21,9 @@ export default function EditSet({ const [reps, setReps] = useState(''); const [weight, setWeight] = useState(''); const [unit, setUnit] = useState(''); - const weightRef = useRef(null); - const repsRef = useRef(null); - const unitRef = useRef(null); + const weightRef = useRef(null); + const repsRef = useRef(null); + const unitRef = useRef(null); useEffect(() => { if (!id) return; @@ -66,39 +66,42 @@ export default function EditSet({ }; return ( - - setShow(false)}> - + <> + + setShow(false)}> Add a set weightRef.current?.focus()} - /> - repsRef.current?.focus()} - ref={weightRef} /> unitRef.current?.focus()} + onSubmitEditing={() => weightRef.current?.focus()} /> + - - + + + - + ); } const styles = StyleSheet.create({ + modal: { + height: '100%', + backgroundColor: 'black', + padding: 20, + }, + text: { + marginBottom: 10, + }, bottom: { flexDirection: 'row', }, title: { fontSize: 20, - }, - modal: { - margin: 20, - backgroundColor: '#20232a', - padding: 20, - shadowColor: '#000', - shadowOffset: { - width: 0, - height: 2, - }, - shadowOpacity: 0.25, - shadowRadius: 4, - elevation: 5, + marginBottom: 10, }, }); diff --git a/Exercises.tsx b/Exercises.tsx index 8a160b0..395678a 100644 --- a/Exercises.tsx +++ b/Exercises.tsx @@ -1,15 +1,61 @@ import {NativeStackScreenProps} from '@react-navigation/native-stack'; -import {Button, Text, View} from 'react-native'; +import React, {useEffect, useState} from 'react'; +import {FlatList, StyleSheet, View} from 'react-native'; +import {List, TextInput} from 'react-native-paper'; import {RootStackParamList} from './App'; -import React from 'react'; +import {getDb} from './db'; +import Exercise from './exercise'; export default function Exercises({ navigation, }: NativeStackScreenProps) { + const [exercises, setExercises] = useState([]); + const [refreshing, setRefreshing] = useState(false); + const [search, setSearch] = useState(''); + + const refresh = async () => { + setRefreshing(true); + const db = await getDb(); + const [result] = await db.executeSql( + `SELECT name, reps, unit, MAX(weight) AS weight + FROM sets + WHERE name LIKE ? + GROUP BY name;`, + [`%${search}%`], + ); + setRefreshing(false); + if (!result) return setExercises([]); + setExercises(result.rows.raw()); + }; + + useEffect(() => navigation.addListener('focus', refresh), [navigation]); + useEffect(() => { + refresh(); + }, [search]); + + const renderItem = ({item}: {item: Exercise}) => ( + + ); + return ( - - Pull ups - 1 rep - - - - - - - - + + - {showTimer && } ); } @@ -150,25 +126,12 @@ const styles = StyleSheet.create({ name: { fontSize: 18, }, - button: { - marginRight: 10, - }, container: { flex: 1, - paddingLeft: 20, - paddingRight: 20, + padding: 10, }, bottom: { alignSelf: 'center', - marginBottom: 10, flexDirection: 'row', }, - set: { - marginBottom: 10, - fontSize: 18, - shadowColor: 'red', - shadowRadius: 10, - shadowOffset: {width: 2, height: 40}, - shadowOpacity: 8, - }, }); diff --git a/Settings.tsx b/Settings.tsx index 9fd0ab0..bea8504 100644 --- a/Settings.tsx +++ b/Settings.tsx @@ -1,8 +1,8 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; import {NativeStackScreenProps} from '@react-navigation/native-stack'; import React, {useEffect, useState} from 'react'; -import {StyleSheet, Switch, Text, TextInput, View} from 'react-native'; -import {Button} from 'react-native-paper'; +import {StyleSheet, Text, View} from 'react-native'; +import {Button, Switch, TextInput} from 'react-native-paper'; import {RootStackParamList} from './App'; import {getDb} from './db'; @@ -34,27 +34,27 @@ export default function Settings({ return ( - Rest minutes - Rest seconds - Alarm enabled? + Alarm enabled? - @@ -63,7 +63,6 @@ export default function Settings({ const styles = StyleSheet.create({ container: { - flex: 1, padding: 10, }, }); diff --git a/exercise.ts b/exercise.ts new file mode 100644 index 0000000..a735d59 --- /dev/null +++ b/exercise.ts @@ -0,0 +1,6 @@ +export default interface Exercise { + name: string; + reps: number; + weight: number; + unit: string; +} diff --git a/index.js b/index.js index 18fd677..73afab3 100644 --- a/index.js +++ b/index.js @@ -21,10 +21,6 @@ export default function Main() { AppRegistry.registerComponent(appName, () => Main); PushNotification.configure({ - onRegister: function (token) { - console.log('TOKEN:', token); - }, - onNotification: function (notification) { console.log('NOTIFICATION:', notification); }, diff --git a/Set.ts b/set.ts similarity index 100% rename from Set.ts rename to set.ts