Add increment/decrement buttons to reps/weight - 1.148

Closes #164
This commit is contained in:
Brandon Presley 2023-08-14 13:29:50 +12:00
parent 79cde3a219
commit 331597e3ee
5 changed files with 174 additions and 75 deletions

View File

@ -9,7 +9,7 @@ import { format } from "date-fns";
import { useCallback, useRef, useState } from "react"; import { useCallback, useRef, useState } from "react";
import { NativeModules, TextInput, View } from "react-native"; import { NativeModules, TextInput, View } from "react-native";
import DocumentPicker from "react-native-document-picker"; import DocumentPicker from "react-native-document-picker";
import { Button, Card, TouchableRipple } from "react-native-paper"; import { Button, Card, IconButton, TouchableRipple } from "react-native-paper";
import AppInput from "./AppInput"; import AppInput from "./AppInput";
import ConfirmDialog from "./ConfirmDialog"; import ConfirmDialog from "./ConfirmDialog";
import { MARGIN, PADDING } from "./constants"; import { MARGIN, PADDING } from "./constants";
@ -155,34 +155,65 @@ export default function EditSet() {
onSubmitEditing={() => repsRef.current?.focus()} onSubmitEditing={() => repsRef.current?.focus()}
/> />
<AppInput <View style={{ flexDirection: "row" }}>
label="Reps" <AppInput
keyboardType="numeric" style={{
value={reps} flex: 1,
onChangeText={(newReps) => { marginBottom: MARGIN,
const fixed = fixNumeric(newReps); }}
setReps(fixed); label="Reps"
if (fixed.length !== newReps.length) toast("Reps must be a number"); keyboardType="numeric"
}} value={reps}
onSubmitEditing={() => weightRef.current?.focus()} onChangeText={(newReps) => {
selection={selection} const fixed = fixNumeric(newReps);
onSelectionChange={(e) => setSelection(e.nativeEvent.selection)} setReps(fixed);
innerRef={repsRef} if (fixed.length !== newReps.length)
/> toast("Reps must be a number");
}}
onSubmitEditing={() => weightRef.current?.focus()}
selection={selection}
onSelectionChange={(e) => setSelection(e.nativeEvent.selection)}
innerRef={repsRef}
/>
<IconButton
icon="add"
onPress={() => setReps((Number(reps) + 1).toString())}
/>
<IconButton
icon="remove"
onPress={() => setReps((Number(reps) - 1).toString())}
/>
</View>
<AppInput <View
label="Weight" style={{
keyboardType="numeric" flexDirection: "row",
value={weight} marginBottom: MARGIN,
onChangeText={(newWeight) => {
const fixed = fixNumeric(newWeight);
setWeight(fixed);
if (fixed.length !== newWeight.length)
toast("Weight must be a number");
}} }}
onSubmitEditing={handleSubmit} >
innerRef={weightRef} <AppInput
/> style={{ flex: 1 }}
label="Weight"
keyboardType="numeric"
value={weight}
onChangeText={(newWeight) => {
const fixed = fixNumeric(newWeight);
setWeight(fixed);
if (fixed.length !== newWeight.length)
toast("Weight must be a number");
}}
onSubmitEditing={handleSubmit}
innerRef={weightRef}
/>
<IconButton
icon="add"
onPress={() => setWeight((Number(weight) + 2.5).toString())}
/>
<IconButton
icon="remove"
onPress={() => setWeight((Number(weight) - 2.5).toString())}
/>
</View>
{settings.showUnit && ( {settings.showUnit && (
<AppInput <AppInput

View File

@ -7,7 +7,7 @@ import {
import { useCallback, useState } from "react"; import { useCallback, useState } from "react";
import { View } from "react-native"; import { View } from "react-native";
import DocumentPicker from "react-native-document-picker"; import DocumentPicker from "react-native-document-picker";
import { Button, Card, TouchableRipple } from "react-native-paper"; import { Button, Card, IconButton, TouchableRipple } from "react-native-paper";
import { In } from "typeorm"; import { In } from "typeorm";
import AppInput from "./AppInput"; import AppInput from "./AppInput";
import ConfirmDialog from "./ConfirmDialog"; import ConfirmDialog from "./ConfirmDialog";
@ -89,23 +89,57 @@ export default function EditSets() {
autoFocus={!name} autoFocus={!name}
/> />
<AppInput <View
label={`Reps: ${oldReps}`} style={{
keyboardType="numeric" flexDirection: "row",
value={reps} marginBottom: MARGIN,
onChangeText={setReps} }}
selection={selection} >
onSelectionChange={(e) => setSelection(e.nativeEvent.selection)} <AppInput
autoFocus={!!name} style={{
/> flex: 1,
}}
label={`Reps: ${oldReps}`}
keyboardType="numeric"
value={reps}
onChangeText={setReps}
selection={selection}
onSelectionChange={(e) => setSelection(e.nativeEvent.selection)}
autoFocus={!!name}
/>
<IconButton
icon="add"
onPress={() => setReps((Number(reps) + 1).toString())}
/>
<IconButton
icon="remove"
onPress={() => setReps((Number(reps) - 1).toString())}
/>
</View>
<AppInput <View
label={`Weights: ${weights}`} style={{
keyboardType="numeric" flexDirection: "row",
value={weight} marginBottom: MARGIN,
onChangeText={setWeight} }}
onSubmitEditing={handleSubmit} >
/> <AppInput
style={{ flex: 1 }}
label={`Weights: ${weights}`}
keyboardType="numeric"
value={weight}
onChangeText={setWeight}
onSubmitEditing={handleSubmit}
/>
<IconButton
icon="add"
onPress={() => setWeight((Number(weight) + 2.5).toString())}
/>
<IconButton
icon="remove"
onPress={() => setWeight((Number(weight) - 2.5).toString())}
/>
</View>
{settings.showUnit && ( {settings.showUnit && (
<AppInput <AppInput

View File

@ -10,7 +10,7 @@ import { FlatList, NativeModules, TextInput, View } from "react-native";
import { Button, IconButton, ProgressBar } from "react-native-paper"; import { Button, IconButton, ProgressBar } from "react-native-paper";
import AppInput from "./AppInput"; import AppInput from "./AppInput";
import { getBestSet } from "./best.service"; import { getBestSet } from "./best.service";
import { PADDING } from "./constants"; import { MARGIN, PADDING } from "./constants";
import CountMany from "./count-many"; import CountMany from "./count-many";
import { AppDataSource } from "./data-source"; import { AppDataSource } from "./data-source";
import { getNow, setRepo, settingsRepo } from "./db"; import { getNow, setRepo, settingsRepo } from "./db";
@ -126,35 +126,69 @@ export default function StartPlan() {
</StackHeader> </StackHeader>
<View style={{ padding: PADDING, flex: 1, flexDirection: "column" }}> <View style={{ padding: PADDING, flex: 1, flexDirection: "column" }}>
<View style={{ flex: 1 }}> <View style={{ flex: 1 }}>
<AppInput <View
label="Reps" style={{
keyboardType="numeric" flexDirection: "row",
value={reps} marginBottom: MARGIN,
onChangeText={(newReps) => {
const fixed = fixNumeric(newReps);
setReps(fixed);
if (fixed.length !== newReps.length)
toast("Reps must be a number");
}} }}
onSubmitEditing={() => weightRef.current?.focus()} >
selection={selection} <AppInput
onSelectionChange={(e) => setSelection(e.nativeEvent.selection)} label="Reps"
innerRef={repsRef} style={{ flex: 1 }}
/> keyboardType="numeric"
<AppInput value={reps}
label="Weight" onChangeText={(newReps) => {
keyboardType="numeric" const fixed = fixNumeric(newReps);
value={weight} setReps(fixed);
onChangeText={(newWeight) => { if (fixed.length !== newReps.length)
const fixed = fixNumeric(newWeight); toast("Reps must be a number");
setWeight(fixed); }}
if (fixed.length !== newWeight.length) onSubmitEditing={() => weightRef.current?.focus()}
toast("Weight must be a number"); selection={selection}
onSelectionChange={(e) => setSelection(e.nativeEvent.selection)}
innerRef={repsRef}
/>
<IconButton
icon="add"
onPress={() => setReps((Number(reps) + 1).toString())}
/>
<IconButton
icon="remove"
onPress={() => setReps((Number(reps) - 1).toString())}
/>
</View>
<View
style={{
flexDirection: "row",
marginBottom: MARGIN,
}} }}
onSubmitEditing={handleSubmit} >
innerRef={weightRef} <AppInput
blurOnSubmit label="Weight"
/> style={{ flex: 1 }}
keyboardType="numeric"
value={weight}
onChangeText={(newWeight) => {
const fixed = fixNumeric(newWeight);
setWeight(fixed);
if (fixed.length !== newWeight.length)
toast("Weight must be a number");
}}
onSubmitEditing={handleSubmit}
innerRef={weightRef}
blurOnSubmit
/>
<IconButton
icon="add"
onPress={() => setWeight((Number(weight) + 2.5).toString())}
/>
<IconButton
icon="remove"
onPress={() => setWeight((Number(weight) - 2.5).toString())}
/>
</View>
{settings?.showUnit && ( {settings?.showUnit && (
<AppInput <AppInput
autoCapitalize="none" autoCapitalize="none"

View File

@ -85,8 +85,8 @@ android {
applicationId "com.massive" applicationId "com.massive"
minSdkVersion rootProject.ext.minSdkVersion minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 36173 versionCode 36174
versionName "1.147" versionName "1.148"
} }
signingConfigs { signingConfigs {
release { release {

View File

@ -1,6 +1,6 @@
{ {
"name": "massive", "name": "massive",
"version": "1.147", "version": "1.148",
"private": true, "private": true,
"license": "GPL-3.0-only", "license": "GPL-3.0-only",
"scripts": { "scripts": {