Skip to content

Commit 2b6d4e4

Browse files
committed
feat: improve exercise set
## Explanation Show the progress in the current exercise so it's easier to keep track.
1 parent 35108f6 commit 2b6d4e4

File tree

2 files changed

+61
-23
lines changed

2 files changed

+61
-23
lines changed

src/app/(app)/current-plan/exercise/[id].tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ export default function ExercisePlanScreen() {
283283
>
284284
<Card>
285285
<ExerciseSet
286+
index={finishedItemToEdit!}
286287
set={planItem.finishedSets[finishedItemToEdit!]!}
288+
total={planItem.sets.length}
287289
onSetChange={handleEditFinishedSet}
288290
stepSize={stepSize}
289291
/>
@@ -344,6 +346,8 @@ export default function ExercisePlanScreen() {
344346
<Layout style={{ flexGrow: 1, justifyContent: "center" }}>
345347
{planItem.openSets.length > 0 && (
346348
<ExerciseSet
349+
index={planItem.currentSetIndex ?? 0}
350+
total={planItem.sets.length}
347351
stepSize={stepSize}
348352
set={planItem.openSets[0]!}
349353
onSetChange={handleEditCurrentSet}

src/components/exercise-set.tsx

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,55 @@ import {
99
} from "@/api/types";
1010
import { space } from "@/styles";
1111

12+
const superscripts = "⁰¹²³⁴⁵⁶⁷⁸⁹".split("");
13+
const subscripts = "₀₁₂₃₄₅₆₇₈₉".split("");
14+
15+
function numberToScript(number: number, scripts: string[]) {
16+
return number
17+
.toString(10)
18+
.split("")
19+
.map((digit) => {
20+
const index = 9 - ("9".charCodeAt(0) - digit.charCodeAt(0));
21+
return scripts[index];
22+
})
23+
.join("");
24+
}
25+
26+
function numbersToFraction(numerator: number, denominator: number) {
27+
const numeratorAsString = numberToScript(numerator, superscripts);
28+
const denominatorAsString = numberToScript(denominator, subscripts);
29+
return `${numeratorAsString}\u2044${denominatorAsString}`;
30+
}
31+
1232
interface ExerciseSetProps {
33+
index: number;
34+
total: number;
1335
set: PlanItemSet;
1436
stepSize: number;
1537
onSetChange: (set: PlanItemSet) => void;
1638
}
1739

18-
export function ExerciseSet(props: ExerciseSetProps) {
40+
export function ExerciseSet({ index, total, ...props }: ExerciseSetProps) {
41+
return (
42+
<Layout
43+
style={{
44+
width: "100%",
45+
flexDirection: "row",
46+
justifyContent: "space-around",
47+
alignItems: "center",
48+
}}
49+
>
50+
<Text style={{ fontSize: space[5], fontWeight: "bold" }}>
51+
{numbersToFraction(index + 1, total)}
52+
</Text>
53+
<ConcreteExerciseSet {...props} />
54+
</Layout>
55+
);
56+
}
57+
58+
function ConcreteExerciseSet(
59+
props: Pick<ExerciseSetProps, "set" | "stepSize" | "onSetChange">,
60+
) {
1961
if (isPlanItemSetOfType("REPETITIONS", props.set)) {
2062
return <RepetitionsSet {...props} set={props.set} />;
2163
} else if (isPlanItemSetOfType("TIME", props.set)) {
@@ -28,7 +70,6 @@ export function ExerciseSet(props: ExerciseSetProps) {
2870

2971
interface PlanItemRepetitionsSetProps {
3072
set: PlanItemRepetitionsSet;
31-
stepSize: number;
3273
onSetChange: (set: PlanItemRepetitionsSet) => void;
3374
}
3475

@@ -42,7 +83,7 @@ function RepetitionsSet({ set, onSetChange }: PlanItemRepetitionsSetProps) {
4283
gap: space[3],
4384
}}
4485
>
45-
<Text style={{ opacity: 0, fontSize: 24 }}>WDH</Text>
86+
<Text style={{ opacity: 0, fontSize: space[5] }}>WDH</Text>
4687
<ValueControls
4788
defaultValue={set.repetitions ?? 0}
4889
onIncrease={() =>
@@ -55,14 +96,13 @@ function RepetitionsSet({ set, onSetChange }: PlanItemRepetitionsSetProps) {
5596
onSetChange({ ...set, repetitions: Math.round(repetitions) })
5697
}
5798
/>
58-
<Text style={{ fontSize: 24 }}>WDH</Text>
99+
<Text style={{ fontSize: space[5] }}>WDH</Text>
59100
</Layout>
60101
);
61102
}
62103

63104
interface PlanItemTimeSetProps {
64105
set: PlanItemTimeSet;
65-
stepSize: number;
66106
onSetChange: (set: PlanItemTimeSet) => void;
67107
}
68108

@@ -76,14 +116,14 @@ function TimeSet({ set, onSetChange }: PlanItemTimeSetProps) {
76116
gap: space[3],
77117
}}
78118
>
79-
<Text style={{ opacity: 0, fontSize: 24 }}>Sekunden</Text>
119+
<Text style={{ opacity: 0, fontSize: space[5] }}>Sekunden</Text>
80120
<ValueControls
81121
defaultValue={set.time ?? 0}
82122
onIncrease={() => onSetChange({ ...set, time: set.time + 1 })}
83123
onDecrease={() => onSetChange({ ...set, time: set.time - 1 })}
84124
onSet={(time) => onSetChange({ ...set, time: Math.round(time) })}
85125
/>
86-
<Text style={{ fontSize: 24 }}>Sekunden</Text>
126+
<Text style={{ fontSize: space[5] }}>Sekunden</Text>
87127
</Layout>
88128
);
89129
}
@@ -95,21 +135,15 @@ interface PlanItemWeightSetProps {
95135
}
96136
function WeightSet({ set, stepSize, onSetChange }: PlanItemWeightSetProps) {
97137
return (
98-
<Layout
99-
style={{
100-
width: "100%",
101-
flexDirection: "row",
102-
justifyContent: "space-around",
103-
}}
104-
>
138+
<>
105139
<Layout
106140
style={{
107141
flexDirection: "row",
108142
alignItems: "center",
109143
gap: space[3],
110144
}}
111145
>
112-
<Text style={{ opacity: 0, fontSize: 24 }}>KG</Text>
146+
<Text style={{ opacity: 0, fontSize: space[5] }}>KG</Text>
113147
<ValueControls
114148
defaultValue={set.repetitions ?? 0}
115149
onIncrease={() =>
@@ -122,7 +156,7 @@ function WeightSet({ set, stepSize, onSetChange }: PlanItemWeightSetProps) {
122156
onSetChange({ ...set, repetitions: Math.round(repetitions) })
123157
}
124158
/>
125-
<Text style={{ opacity: 0, fontSize: 24 }}>KG</Text>
159+
<Text style={{ opacity: 0, fontSize: space[5] }}>KG</Text>
126160
</Layout>
127161
<Layout
128162
style={{
@@ -131,7 +165,7 @@ function WeightSet({ set, stepSize, onSetChange }: PlanItemWeightSetProps) {
131165
gap: space[3],
132166
}}
133167
>
134-
<Text style={{ opacity: 0, fontSize: 24 }}>KG</Text>
168+
<Text style={{ opacity: 0, fontSize: space[5] }}>KG</Text>
135169
<ValueControls
136170
defaultValue={set.weight ?? 0}
137171
onIncrease={() =>
@@ -142,9 +176,9 @@ function WeightSet({ set, stepSize, onSetChange }: PlanItemWeightSetProps) {
142176
}
143177
onSet={(weight) => onSetChange({ ...set, weight })}
144178
/>
145-
<Text style={{ fontSize: 24 }}>KG</Text>
179+
<Text style={{ fontSize: space[5] }}>KG</Text>
146180
</Layout>
147-
</Layout>
181+
</>
148182
);
149183
}
150184

@@ -170,21 +204,21 @@ function ValueControls({
170204
>
171205
<Icon
172206
fill="white"
173-
style={{ height: space[10], width: space[10] }}
207+
style={{ height: space[9], width: space[9] }}
174208
name="chevron-up-outline"
175209
onPress={onIncrease}
176210
/>
177211
<Input
178-
style={{ width: 100 }}
212+
style={{ minWidth: 96 }}
179213
keyboardType="decimal-pad"
180214
defaultValue={defaultValue.toString()}
181215
size="large"
182-
textStyle={{ fontSize: 24, textAlign: "center" }}
216+
textStyle={{ fontSize: space[5], textAlign: "center" }}
183217
onEndEditing={(event) => onSet(parseFloat(event.nativeEvent.text))}
184218
/>
185219
<Icon
186220
fill="white"
187-
style={{ height: space[10], width: space[10] }}
221+
style={{ height: space[9], width: space[9] }}
188222
name="chevron-down-outline"
189223
onPress={onDecrease}
190224
/>

0 commit comments

Comments
 (0)