Fix image on new set prediction

This commit is contained in:
Brandon Presley 2022-10-02 19:07:52 +13:00
parent ba3ed2a272
commit 93878f14e4
3 changed files with 17 additions and 10 deletions

View File

@ -46,13 +46,15 @@ export default function SetList() {
let workout = todaysWorkouts[0]; let workout = todaysWorkouts[0];
let best = await getBestSet(workout); let best = await getBestSet(workout);
let [{image}] = await getSets({search: best.name, limit: 1, offset: 0}); let [{image}] = await getSets({search: best.name, limit: 1, offset: 0});
console.log(`${SetList.name}.predict:`, {workout, best}); console.log(`${SetList.name}.predict:`, {workout, best, image});
if (!todaysSet || !todaysWorkouts.includes(todaysSet.name)) if (!todaysSet || !todaysWorkouts.includes(todaysSet.name))
return setSet({...best, image}); return setSet({...best, image});
let _count = await countToday(todaysSet.name); let _count = await countToday(todaysSet.name);
console.log(`${SetList.name}.predict:`, {_count}); console.log(`${SetList.name}.predict:`, {_count});
workout = todaysSet.name; workout = todaysSet.name;
best = await getBestSet(workout); best = await getBestSet(workout);
[{image}] = await getSets({search: best.name, limit: 1, offset: 0});
console.log(`${SetList.name}.predict:`, {workout, best, image});
const index = todaysWorkouts.indexOf(todaysSet.name) + 1; const index = todaysWorkouts.indexOf(todaysSet.name) + 1;
if (_count >= Number(best.sets)) { if (_count >= Number(best.sets)) {
best = await getBestSet(todaysWorkouts[index]); best = await getBestSet(todaysWorkouts[index]);
@ -66,13 +68,18 @@ export default function SetList() {
const refresh = useCallback(async () => { const refresh = useCallback(async () => {
predict(); predict();
const newSets = await getSets({search: `%${search}%`, limit, offset: 0}); const newSets = await getSets({
search: `%${search}%`,
limit,
offset: 0,
format: settings.date || '%Y-%m-%d %H:%M',
});
console.log(`${SetList.name}.refresh:`, {first: newSets[0]}); console.log(`${SetList.name}.refresh:`, {first: newSets[0]});
if (newSets.length === 0) return setSets([]); if (newSets.length === 0) return setSets([]);
setSets(newSets); setSets(newSets);
setOffset(0); setOffset(0);
setEnd(false); setEnd(false);
}, [search, predict]); }, [search, predict, settings.date]);
useFocusEffect( useFocusEffect(
useCallback(() => { useCallback(() => {

View File

@ -29,8 +29,8 @@ export default function SettingsPage() {
const [showUnit, setShowUnit] = useState(!!settings.showUnit); const [showUnit, setShowUnit] = useState(!!settings.showUnit);
const [workouts, setWorkouts] = useState(!!settings.workouts); const [workouts, setWorkouts] = useState(!!settings.workouts);
const [steps, setSteps] = useState(!!settings.steps); const [steps, setSteps] = useState(!!settings.steps);
const [date, setDate] = useState('%Y-%m-%d %H:%M'); const [date, setDate] = useState(settings.date || '%Y-%m-%d %H:%M');
const [showDate, setShowDate] = useState(false); const [showDate, setShowDate] = useState(!!settings.showDate);
const {color, setColor} = useContext(CustomTheme); const {color, setColor} = useContext(CustomTheme);
const {toast} = useContext(SnackbarContext); const {toast} = useContext(SnackbarContext);
@ -211,7 +211,7 @@ export default function SettingsPage() {
)} )}
{'date format'.includes(search.toLowerCase()) && ( {'date format'.includes(search.toLowerCase()) && (
<Picker <Picker
style={{color}} style={{color, marginTop: -10}}
dropdownIconColor={color} dropdownIconColor={color}
selectedValue={date} selectedValue={date}
onValueChange={value => setDate(value)}> onValueChange={value => setDate(value)}>
@ -223,7 +223,7 @@ export default function SettingsPage() {
value="%Y-%m-%d" value="%Y-%m-%d"
label="Format date as 1990-12-24 (YYYY-MM-dd)" label="Format date as 1990-12-24 (YYYY-MM-dd)"
/> />
<Picker.Item value="%m-%d" label="Format date as 12-24 (MM-dd)" /> <Picker.Item value="%d/%m" label="Format date as 24/12 (dd/MM)" />
</Picker> </Picker>
)} )}
{'alarm sound'.includes(search.toLowerCase()) && ( {'alarm sound'.includes(search.toLowerCase()) && (

View File

@ -1,6 +1,5 @@
import {db} from './db'; import {db} from './db';
import Set from './set'; import Set from './set';
import {settings} from './settings.service';
export const updateSet = async (value: Set) => { export const updateSet = async (value: Set) => {
const update = ` const update = `
@ -60,20 +59,21 @@ interface PageParams {
search: string; search: string;
limit: number; limit: number;
offset: number; offset: number;
format?: string;
} }
export const getSets = async ({ export const getSets = async ({
search, search,
limit, limit,
offset, offset,
format,
}: PageParams): Promise<Set[]> => { }: PageParams): Promise<Set[]> => {
const format = settings.date || '%Y-%m-%d %H:%M';
const select = ` const select = `
SELECT id, name, reps, weight, sets, minutes, seconds, SELECT id, name, reps, weight, sets, minutes, seconds,
STRFTIME(?, created) as created, unit, image, steps STRFTIME(?, created) as created, unit, image, steps
FROM sets FROM sets
WHERE name LIKE ? AND NOT hidden WHERE name LIKE ? AND NOT hidden
ORDER BY created DESC ORDER BY STRFTIME('%Y-%m-%d %H:%M', created) DESC
LIMIT ? OFFSET ? LIMIT ? OFFSET ?
`; `;
const [result] = await db.executeSql(select, [ const [result] = await db.executeSql(select, [