diff --git a/EditPlan.tsx b/EditPlan.tsx
index 9ddb9bb..30357b0 100644
--- a/EditPlan.tsx
+++ b/EditPlan.tsx
@@ -4,8 +4,14 @@ import {
useNavigation,
useRoute,
} from "@react-navigation/native";
-import { useCallback, useEffect, useState } from "react";
-import { FlatList, Pressable, StyleSheet, View } from "react-native";
+import React, { useCallback, useEffect, useState } from "react";
+import {
+ FlatList,
+ Pressable,
+ ScrollView,
+ StyleSheet,
+ View,
+} from "react-native";
import { IconButton, Switch as PaperSwitch, Text } from "react-native-paper";
import AppInput from "./AppInput";
import { StackParams } from "./AppStack";
@@ -95,10 +101,11 @@ export default function EditPlan() {
/>
);
- const renderExercise = (name: string, index: number) => (
+ const renderExercise = (name: string, index: number, movable: boolean) => (
toggleExercise(!exercises.includes(name), name)}
style={{ flexDirection: "row", alignItems: "center" }}
+ key={name}
>
toggleExercise(value, name)}
/>
{name}
- moveUp(index)}
- />
- moveDown(index)} />
+ {movable && (
+ <>
+ moveUp(index)}
+ />
+ moveDown(index)} />
+ >
+ )}
);
const moveDown = (from: number) => {
- if (from === names.length - 1) return;
+ if (from === exercises.length - 1) return;
const to = from + 1;
- const newNames = [...names];
- const copy = newNames[from];
- newNames[from] = newNames[to];
- newNames[to] = copy;
- const newExercises = newNames.filter((name) => exercises.includes(name));
+ const newExercises = [...exercises];
+ const copy = newExercises[from];
+ newExercises[from] = newExercises[to];
+ newExercises[to] = copy;
setExercises(newExercises);
- setNames(newNames);
};
const moveUp = (from: number) => {
if (from === 0) return;
const to = from - 1;
- const newNames = [...names];
- const copy = newNames[from];
- newNames[from] = newNames[to];
- newNames[to] = copy;
- const newExercises = newNames.filter((name) => exercises.includes(name));
+ const newExercises = [...exercises];
+ const copy = newExercises[from];
+ newExercises[from] = newExercises[to];
+ newExercises[to] = copy;
setExercises(newExercises);
- setNames(newNames);
};
return (
@@ -163,7 +170,7 @@ export default function EditPlan() {
/>
)}
-
+
renderDay(day))}
Exercises
- {names !== undefined && (
- No exercises yet}
- renderItem={({ item, index }) => renderExercise(item, index)}
- keyExtractor={(item) => item}
- style={{
- flex: 1,
- }}
- />
+ {exercises.map((exercise, index) =>
+ renderExercise(exercise, index, true)
)}
-
+ {names !== undefined &&
+ names
+ .filter((name) => !exercises.includes(name))
+ .map((name, index) => renderExercise(name, index, false))}
+
+