Fix linting errors
This commit is contained in:
parent
a06b9e7ee5
commit
dbb3dc2eb3
3
App.tsx
3
App.tsx
|
@ -36,6 +36,7 @@ const App = () => {
|
||||||
const [db, setDb] = useState<SQLiteDatabase | null>(null);
|
const [db, setDb] = useState<SQLiteDatabase | null>(null);
|
||||||
const dark = useColorScheme() === 'dark';
|
const dark = useColorScheme() === 'dark';
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
const gotDb = await getDb();
|
const gotDb = await getDb();
|
||||||
await gotDb.executeSql(createPlans);
|
await gotDb.executeSql(createPlans);
|
||||||
|
@ -48,8 +49,6 @@ const App = () => {
|
||||||
const alarmEnabled = await getItem('alarmEnabled');
|
const alarmEnabled = await getItem('alarmEnabled');
|
||||||
if (alarmEnabled === null) await setItem('alarmEnabled', 'false');
|
if (alarmEnabled === null) await setItem('alarmEnabled', 'false');
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
init();
|
init();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, {useContext, useEffect, useState} from 'react';
|
import React, {useCallback, useContext, useEffect, useState} from 'react';
|
||||||
import {FlatList, StyleSheet, View} from 'react-native';
|
import {FlatList, StyleSheet, View} from 'react-native';
|
||||||
import {List, Searchbar} from 'react-native-paper';
|
import {List, Searchbar} from 'react-native-paper';
|
||||||
import {DatabaseContext} from './App';
|
import {DatabaseContext} from './App';
|
||||||
|
@ -12,6 +12,7 @@ export default function BestPage() {
|
||||||
const [best, setBest] = useState<Best>();
|
const [best, setBest] = useState<Best>();
|
||||||
const db = useContext(DatabaseContext);
|
const db = useContext(DatabaseContext);
|
||||||
|
|
||||||
|
const refresh = useCallback(async () => {
|
||||||
const bestWeight = `
|
const bestWeight = `
|
||||||
SELECT name, reps, unit, MAX(weight) AS weight
|
SELECT name, reps, unit, MAX(weight) AS weight
|
||||||
FROM sets
|
FROM sets
|
||||||
|
@ -27,7 +28,6 @@ export default function BestPage() {
|
||||||
GROUP BY name;
|
GROUP BY name;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const refresh = async () => {
|
|
||||||
const [weight] = await db.executeSql(bestWeight, [`%${search}%`]);
|
const [weight] = await db.executeSql(bestWeight, [`%${search}%`]);
|
||||||
if (!weight) return setBests([]);
|
if (!weight) return setBests([]);
|
||||||
let newBest: Best[] = [];
|
let newBest: Best[] = [];
|
||||||
|
@ -39,7 +39,7 @@ export default function BestPage() {
|
||||||
newBest = newBest.concat(reps.rows.raw());
|
newBest = newBest.concat(reps.rows.raw());
|
||||||
}
|
}
|
||||||
setBests(newBest);
|
setBests(newBest);
|
||||||
};
|
}, [search]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refresh();
|
refresh();
|
||||||
|
|
|
@ -28,16 +28,17 @@ export default function EditPlan({
|
||||||
const [names, setNames] = useState<string[]>([]);
|
const [names, setNames] = useState<string[]>([]);
|
||||||
const db = useContext(DatabaseContext);
|
const db = useContext(DatabaseContext);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
const refresh = async () => {
|
const refresh = async () => {
|
||||||
const [namesResult] = await db.executeSql('SELECT DISTINCT name FROM sets');
|
const [namesResult] = await db.executeSql(
|
||||||
|
'SELECT DISTINCT name FROM sets',
|
||||||
|
);
|
||||||
if (!namesResult.rows.length) return setNames([]);
|
if (!namesResult.rows.length) return setNames([]);
|
||||||
setNames(namesResult.rows.raw().map(({name}) => name));
|
setNames(namesResult.rows.raw().map(({name}) => name));
|
||||||
if (!plan) return;
|
if (!plan) return;
|
||||||
setDays(plan.days.split(','));
|
setDays(plan.days.split(','));
|
||||||
setWorkouts(plan.workouts.split(','));
|
setWorkouts(plan.workouts.split(','));
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
refresh();
|
refresh();
|
||||||
}, [plan]);
|
}, [plan]);
|
||||||
|
|
||||||
|
|
27
HomePage.tsx
27
HomePage.tsx
|
@ -1,5 +1,5 @@
|
||||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||||
import React, {useContext, useEffect, useState} from 'react';
|
import React, {useCallback, useContext, useEffect, useState} from 'react';
|
||||||
import {FlatList, NativeModules, StyleSheet, View} from 'react-native';
|
import {FlatList, NativeModules, StyleSheet, View} from 'react-native';
|
||||||
import {List, Searchbar} from 'react-native-paper';
|
import {List, Searchbar} from 'react-native-paper';
|
||||||
import {DatabaseContext} from './App';
|
import {DatabaseContext} from './App';
|
||||||
|
@ -25,23 +25,14 @@ export default function HomePage() {
|
||||||
ORDER BY created DESC
|
ORDER BY created DESC
|
||||||
LIMIT ? OFFSET ?
|
LIMIT ? OFFSET ?
|
||||||
`;
|
`;
|
||||||
const getSets = ({
|
|
||||||
search,
|
|
||||||
limit,
|
|
||||||
offset,
|
|
||||||
}: {
|
|
||||||
search: string;
|
|
||||||
limit: number;
|
|
||||||
offset: number;
|
|
||||||
}) => db.executeSql(selectSets, [`%${search}%`, limit, offset]);
|
|
||||||
|
|
||||||
const refresh = async () => {
|
const refresh = useCallback(async () => {
|
||||||
const [result] = await getSets({search, limit, offset: 0});
|
const [result] = await db.executeSql(selectSets, [`%${search}%`, limit, 0]);
|
||||||
if (!result) return setSets([]);
|
if (!result) return setSets([]);
|
||||||
setSets(result.rows.raw());
|
setSets(result.rows.raw());
|
||||||
setOffset(0);
|
setOffset(0);
|
||||||
setEnd(false);
|
setEnd(false);
|
||||||
};
|
}, [search]);
|
||||||
|
|
||||||
const refreshLoader = async () => {
|
const refreshLoader = async () => {
|
||||||
setRefresing(true);
|
setRefresing(true);
|
||||||
|
@ -66,19 +57,19 @@ export default function HomePage() {
|
||||||
NativeModules.AlarmModule.timer(milliseconds);
|
NativeModules.AlarmModule.timer(milliseconds);
|
||||||
};
|
};
|
||||||
|
|
||||||
const next = async () => {
|
const next = useCallback(async () => {
|
||||||
if (end) return;
|
if (end) return;
|
||||||
setRefresing(true);
|
setRefresing(true);
|
||||||
const newOffset = offset + limit;
|
const newOffset = offset + limit;
|
||||||
const [result] = await getSets({search, limit, offset: newOffset}).finally(
|
const [result] = await db
|
||||||
() => setRefresing(false),
|
.executeSql(selectSets, [`%${search}%`, limit, newOffset])
|
||||||
);
|
.finally(() => setRefresing(false));
|
||||||
if (result.rows.length === 0) return setEnd(true);
|
if (result.rows.length === 0) return setEnd(true);
|
||||||
if (!sets) return;
|
if (!sets) return;
|
||||||
setSets([...sets, ...result.rows.raw()]);
|
setSets([...sets, ...result.rows.raw()]);
|
||||||
if (result.rows.length < limit) return setEnd(true);
|
if (result.rows.length < limit) return setEnd(true);
|
||||||
setOffset(newOffset);
|
setOffset(newOffset);
|
||||||
};
|
}, [search, end]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
|
|
17
PlanPage.tsx
17
PlanPage.tsx
|
@ -1,4 +1,4 @@
|
||||||
import React, {useContext, useEffect, useState} from 'react';
|
import React, {useCallback, useContext, useEffect, useState} from 'react';
|
||||||
import {FlatList, StyleSheet, View} from 'react-native';
|
import {FlatList, StyleSheet, View} from 'react-native';
|
||||||
import {List, Searchbar} from 'react-native-paper';
|
import {List, Searchbar} from 'react-native-paper';
|
||||||
import {DatabaseContext} from './App';
|
import {DatabaseContext} from './App';
|
||||||
|
@ -14,21 +14,20 @@ export default function PlanPage() {
|
||||||
const [plan, setPlan] = useState<Plan>();
|
const [plan, setPlan] = useState<Plan>();
|
||||||
const db = useContext(DatabaseContext);
|
const db = useContext(DatabaseContext);
|
||||||
|
|
||||||
|
const refresh = useCallback(async () => {
|
||||||
const selectPlans = `
|
const selectPlans = `
|
||||||
SELECT * from plans
|
SELECT * from plans
|
||||||
WHERE days LIKE ? OR workouts LIKE ?
|
WHERE days LIKE ? OR workouts LIKE ?
|
||||||
`;
|
`;
|
||||||
const getPlans = ({search}: {search: string}) =>
|
const getPlans = ({s}: {s: string}) =>
|
||||||
db.executeSql(selectPlans, [`%${search}%`, `%${search}%`]);
|
db.executeSql(selectPlans, [`%${s}%`, `%${s}%`]);
|
||||||
|
const [plansResult] = await getPlans({s: search});
|
||||||
const refresh = async () => {
|
|
||||||
const [plansResult] = await getPlans({search});
|
|
||||||
setPlans(plansResult.rows.raw());
|
setPlans(plansResult.rows.raw());
|
||||||
};
|
}, [search, db]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refresh();
|
refresh();
|
||||||
}, [search]);
|
}, [search, refresh]);
|
||||||
|
|
||||||
const renderItem = ({item}: {item: Plan}) => (
|
const renderItem = ({item}: {item: Plan}) => (
|
||||||
<PlanItem item={item} key={item.id} setPlan={setPlan} onRemove={refresh} />
|
<PlanItem item={item} key={item.id} setPlan={setPlan} onRemove={refresh} />
|
||||||
|
|
|
@ -65,9 +65,9 @@ export default function SettingsPage() {
|
||||||
value={seconds}
|
value={seconds}
|
||||||
keyboardType="numeric"
|
keyboardType="numeric"
|
||||||
placeholder="30"
|
placeholder="30"
|
||||||
onChangeText={seconds => {
|
onChangeText={s => {
|
||||||
setSeconds(seconds);
|
setSeconds(s);
|
||||||
setItem('seconds', seconds);
|
setItem('seconds', s);
|
||||||
}}
|
}}
|
||||||
style={styles.text}
|
style={styles.text}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -34,7 +34,7 @@ export default function ViewBest({
|
||||||
setUnit(result.rows.item(0).unit);
|
setUnit(result.rows.item(0).unit);
|
||||||
};
|
};
|
||||||
refresh();
|
refresh();
|
||||||
}, [best]);
|
}, [best, db]);
|
||||||
|
|
||||||
const contentInset = {top: 20, bottom: 20};
|
const contentInset = {top: 20, bottom: 20};
|
||||||
|
|
||||||
|
@ -65,7 +65,10 @@ export default function ViewBest({
|
||||||
</View>
|
</View>
|
||||||
</Dialog.Content>
|
</Dialog.Content>
|
||||||
<Dialog.Actions>
|
<Dialog.Actions>
|
||||||
<Button icon="close" onPress={() => setBest(undefined)}>
|
<Button
|
||||||
|
mode="contained"
|
||||||
|
icon="close"
|
||||||
|
onPress={() => setBest(undefined)}>
|
||||||
Close
|
Close
|
||||||
</Button>
|
</Button>
|
||||||
</Dialog.Actions>
|
</Dialog.Actions>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user