Get max reps given max weight for best page
This commit is contained in:
parent
60bfb9664f
commit
d8ae1cc838
35
BestPage.tsx
35
BestPage.tsx
|
@ -10,16 +10,33 @@ export default function BestPage() {
|
||||||
const [refreshing, setRefresing] = useState(false);
|
const [refreshing, setRefresing] = useState(false);
|
||||||
const db = useContext(DatabaseContext);
|
const db = useContext(DatabaseContext);
|
||||||
|
|
||||||
const refresh = async () => {
|
const bestWeight = `
|
||||||
const [result] = await db.executeSql(
|
SELECT name, reps, unit, MAX(weight) AS weight
|
||||||
`SELECT name, MAX(reps) as reps, unit, MAX(weight) AS weight
|
|
||||||
FROM sets
|
FROM sets
|
||||||
WHERE name LIKE ?
|
WHERE name LIKE ?
|
||||||
GROUP BY name;`,
|
GROUP BY name;
|
||||||
[`%${search}%`],
|
`;
|
||||||
);
|
|
||||||
if (!result) return setExercises([]);
|
const bestReps = `
|
||||||
setExercises(result.rows.raw());
|
SELECT name, MAX(reps) as reps, unit, weight
|
||||||
|
FROM sets
|
||||||
|
WHERE name = ?
|
||||||
|
AND weight = ?
|
||||||
|
GROUP BY name;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const refresh = async () => {
|
||||||
|
const [weight] = await db.executeSql(bestWeight, [`%${search}%`]);
|
||||||
|
if (!weight) return setExercises([]);
|
||||||
|
let newExercises: Exercise[] = [];
|
||||||
|
for (let i = 0; i < weight.rows.length; i++) {
|
||||||
|
const [reps] = await db.executeSql(bestReps, [
|
||||||
|
weight.rows.item(i).name,
|
||||||
|
weight.rows.item(i).weight,
|
||||||
|
]);
|
||||||
|
newExercises = newExercises.concat(reps.rows.raw());
|
||||||
|
}
|
||||||
|
setExercises(newExercises);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -30,7 +47,7 @@ export default function BestPage() {
|
||||||
<List.Item
|
<List.Item
|
||||||
key={item.name}
|
key={item.name}
|
||||||
title={item.name}
|
title={item.name}
|
||||||
description={`Best: ${item.reps} x ${item.weight}${item.unit}`}
|
description={`${item.reps} x ${item.weight}${item.unit}`}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user