Fix rest timers for newly edited Workouts
Previously if you were to add a new workout, then add a set for that workout immediately afterwards, the rest timers would be the default 3:30. Now, they are the actual value set when creating the workout.
This commit is contained in:
parent
4ba86be8af
commit
b95024abe0
19
EditSet.tsx
19
EditSet.tsx
|
@ -11,9 +11,8 @@ import {PADDING} from './constants';
|
||||||
import {HomePageParams} from './home-page-params';
|
import {HomePageParams} from './home-page-params';
|
||||||
import {useSnackbar} from './MassiveSnack';
|
import {useSnackbar} from './MassiveSnack';
|
||||||
import Set from './set';
|
import Set from './set';
|
||||||
import {addSet, updateSet} from './set.service';
|
import {addSet, getSet, updateSet} from './set.service';
|
||||||
import SetForm from './SetForm';
|
import SetForm from './SetForm';
|
||||||
import {getSettings, updateSettings} from './settings.service';
|
|
||||||
import {useSettings} from './use-settings';
|
import {useSettings} from './use-settings';
|
||||||
|
|
||||||
export default function EditSet() {
|
export default function EditSet() {
|
||||||
|
@ -21,7 +20,7 @@ export default function EditSet() {
|
||||||
const {set} = params;
|
const {set} = params;
|
||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
const {toast} = useSnackbar();
|
const {toast} = useSnackbar();
|
||||||
const {settings, setSettings} = useSettings();
|
const {settings} = useSettings();
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
|
@ -39,21 +38,17 @@ export default function EditSet() {
|
||||||
);
|
);
|
||||||
|
|
||||||
const startTimer = useCallback(
|
const startTimer = useCallback(
|
||||||
async (value: Set) => {
|
async (name: string) => {
|
||||||
if (!settings.alarm) return;
|
if (!settings.alarm) return;
|
||||||
const milliseconds =
|
const {minutes, seconds} = await getSet(name);
|
||||||
Number(value.minutes) * 60 * 1000 + Number(value.seconds) * 1000;
|
const milliseconds = (minutes ?? 3) * 60 * 1000 + (seconds ?? 0) * 1000;
|
||||||
NativeModules.AlarmModule.timer(
|
NativeModules.AlarmModule.timer(
|
||||||
milliseconds,
|
milliseconds,
|
||||||
!!settings.vibrate,
|
!!settings.vibrate,
|
||||||
settings.sound,
|
settings.sound,
|
||||||
);
|
);
|
||||||
const next = new Date();
|
|
||||||
next.setTime(next.getTime() + milliseconds);
|
|
||||||
await updateSettings({...settings, nextAlarm: next.toISOString()});
|
|
||||||
setSettings(await getSettings());
|
|
||||||
},
|
},
|
||||||
[settings, setSettings],
|
[settings],
|
||||||
);
|
);
|
||||||
|
|
||||||
const update = useCallback(
|
const update = useCallback(
|
||||||
|
@ -68,7 +63,7 @@ export default function EditSet() {
|
||||||
const add = useCallback(
|
const add = useCallback(
|
||||||
async (value: Set) => {
|
async (value: Set) => {
|
||||||
console.log(`${EditSet.name}.add`, {set: value});
|
console.log(`${EditSet.name}.add`, {set: value});
|
||||||
startTimer(value);
|
startTimer(value.name);
|
||||||
await addSet(value);
|
await addSet(value);
|
||||||
if (!settings.notify) return navigation.goBack();
|
if (!settings.notify) return navigation.goBack();
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -63,6 +63,17 @@ interface PageParams {
|
||||||
format?: string;
|
format?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getSet = async (name: string): Promise<Set> => {
|
||||||
|
const select = `
|
||||||
|
SELECT *
|
||||||
|
FROM sets
|
||||||
|
WHERE name = ?
|
||||||
|
LIMIT 1
|
||||||
|
`;
|
||||||
|
const [result] = await db.executeSql(select, [name]);
|
||||||
|
return result.rows.item(0);
|
||||||
|
};
|
||||||
|
|
||||||
export const getSets = async ({
|
export const getSets = async ({
|
||||||
search,
|
search,
|
||||||
limit,
|
limit,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user