Fix max number of sets for plan
Previously we were trying to get the max # of sets from our query on the number of sets completed for today. This meant if we hadn't completed any sets today, we would get no result for that workout.
This commit is contained in:
parent
f078ede58a
commit
3714db438e
|
@ -16,7 +16,7 @@ import MassiveInput from './MassiveInput';
|
||||||
import {useSnackbar} from './MassiveSnack';
|
import {useSnackbar} from './MassiveSnack';
|
||||||
import {PlanPageParams} from './plan-page-params';
|
import {PlanPageParams} from './plan-page-params';
|
||||||
import Set from './set';
|
import Set from './set';
|
||||||
import {addSet, countManyToday} from './set.service';
|
import {addSet, countManyToday, getDistinctSets} from './set.service';
|
||||||
import SetForm from './SetForm';
|
import SetForm from './SetForm';
|
||||||
import {useSettings} from './use-settings';
|
import {useSettings} from './use-settings';
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ export default function StartPlan() {
|
||||||
const [selected, setSelected] = useState(0);
|
const [selected, setSelected] = useState(0);
|
||||||
const {settings} = useSettings();
|
const {settings} = useSettings();
|
||||||
const [counts, setCounts] = useState<CountMany[]>();
|
const [counts, setCounts] = useState<CountMany[]>();
|
||||||
|
const [distinctSets, setDistinctSets] = useState<Set[]>();
|
||||||
const weightRef = useRef<TextInput>(null);
|
const weightRef = useRef<TextInput>(null);
|
||||||
const repsRef = useRef<TextInput>(null);
|
const repsRef = useRef<TextInput>(null);
|
||||||
const unitRef = useRef<TextInput>(null);
|
const unitRef = useRef<TextInput>(null);
|
||||||
|
@ -55,7 +56,16 @@ export default function StartPlan() {
|
||||||
headerRight: null,
|
headerRight: null,
|
||||||
title: params.plan.days.replace(/,/g, ', '),
|
title: params.plan.days.replace(/,/g, ', '),
|
||||||
});
|
});
|
||||||
countManyToday().then(setCounts);
|
countManyToday().then(newCounts => {
|
||||||
|
setCounts(newCounts);
|
||||||
|
console.log(`${StartPlan.name}.focus:`, {newCounts});
|
||||||
|
});
|
||||||
|
getDistinctSets({limit: 100, offset: 0, search: '%'}).then(
|
||||||
|
newDistinct => {
|
||||||
|
setDistinctSets(newDistinct);
|
||||||
|
console.log(`${StartPlan.name}.focus:`, {newDistinct});
|
||||||
|
},
|
||||||
|
);
|
||||||
}, [navigation, params]),
|
}, [navigation, params]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -115,10 +125,11 @@ export default function StartPlan() {
|
||||||
const getDescription = useCallback(
|
const getDescription = useCallback(
|
||||||
(countName: string) => {
|
(countName: string) => {
|
||||||
const count = counts?.find(c => c.name === countName);
|
const count = counts?.find(c => c.name === countName);
|
||||||
if (!count) return;
|
if (!distinctSets) return;
|
||||||
return `${count.total} / ${count.sets}`;
|
const distinct = distinctSets.find(d => d.name === countName);
|
||||||
|
return `${count?.total || 0} / ${distinct?.sets}`;
|
||||||
},
|
},
|
||||||
[counts],
|
[counts, distinctSets],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
export default interface CountMany {
|
export default interface CountMany {
|
||||||
name: string;
|
name: string;
|
||||||
total: number;
|
total: number;
|
||||||
sets: number;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ export const countToday = async (name: string): Promise<number> => {
|
||||||
|
|
||||||
export const countManyToday = async (): Promise<CountMany[]> => {
|
export const countManyToday = async (): Promise<CountMany[]> => {
|
||||||
const select = `
|
const select = `
|
||||||
SELECT COUNT(*) as total, name, sets FROM sets
|
SELECT COUNT(*) as total, name FROM sets
|
||||||
WHERE created LIKE strftime('%Y-%m-%d%%', 'now', 'localtime')
|
WHERE created LIKE strftime('%Y-%m-%d%%', 'now', 'localtime')
|
||||||
AND NOT hidden
|
AND NOT hidden
|
||||||
GROUP BY name
|
GROUP BY name
|
||||||
|
|
Loading…
Reference in New Issue
Block a user