parent
c18072bdc0
commit
9ab07c0114
72
EditPlan.tsx
72
EditPlan.tsx
|
@ -4,8 +4,14 @@ import {
|
||||||
useNavigation,
|
useNavigation,
|
||||||
useRoute,
|
useRoute,
|
||||||
} from "@react-navigation/native";
|
} from "@react-navigation/native";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
import { FlatList, Pressable, StyleSheet, View } from "react-native";
|
import {
|
||||||
|
FlatList,
|
||||||
|
Pressable,
|
||||||
|
ScrollView,
|
||||||
|
StyleSheet,
|
||||||
|
View,
|
||||||
|
} from "react-native";
|
||||||
import { IconButton, Switch as PaperSwitch, Text } from "react-native-paper";
|
import { IconButton, Switch as PaperSwitch, Text } from "react-native-paper";
|
||||||
import AppInput from "./AppInput";
|
import AppInput from "./AppInput";
|
||||||
import { StackParams } from "./AppStack";
|
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) => (
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={() => toggleExercise(!exercises.includes(name), name)}
|
onPress={() => toggleExercise(!exercises.includes(name), name)}
|
||||||
style={{ flexDirection: "row", alignItems: "center" }}
|
style={{ flexDirection: "row", alignItems: "center" }}
|
||||||
|
key={name}
|
||||||
>
|
>
|
||||||
<PaperSwitch
|
<PaperSwitch
|
||||||
value={exercises.includes(name)}
|
value={exercises.includes(name)}
|
||||||
|
@ -106,37 +113,37 @@ export default function EditPlan() {
|
||||||
onValueChange={(value) => toggleExercise(value, name)}
|
onValueChange={(value) => toggleExercise(value, name)}
|
||||||
/>
|
/>
|
||||||
<Text>{name}</Text>
|
<Text>{name}</Text>
|
||||||
<IconButton
|
{movable && (
|
||||||
icon="arrow-up"
|
<>
|
||||||
style={{ marginLeft: "auto" }}
|
<IconButton
|
||||||
onPressIn={() => moveUp(index)}
|
icon="arrow-up"
|
||||||
/>
|
style={{ marginLeft: "auto" }}
|
||||||
<IconButton icon="arrow-down" onPressIn={() => moveDown(index)} />
|
onPressIn={() => moveUp(index)}
|
||||||
|
/>
|
||||||
|
<IconButton icon="arrow-down" onPressIn={() => moveDown(index)} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
);
|
);
|
||||||
|
|
||||||
const moveDown = (from: number) => {
|
const moveDown = (from: number) => {
|
||||||
if (from === names.length - 1) return;
|
if (from === exercises.length - 1) return;
|
||||||
const to = from + 1;
|
const to = from + 1;
|
||||||
const newNames = [...names];
|
const newExercises = [...exercises];
|
||||||
const copy = newNames[from];
|
const copy = newExercises[from];
|
||||||
newNames[from] = newNames[to];
|
newExercises[from] = newExercises[to];
|
||||||
newNames[to] = copy;
|
newExercises[to] = copy;
|
||||||
const newExercises = newNames.filter((name) => exercises.includes(name));
|
|
||||||
setExercises(newExercises);
|
setExercises(newExercises);
|
||||||
setNames(newNames);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const moveUp = (from: number) => {
|
const moveUp = (from: number) => {
|
||||||
if (from === 0) return;
|
if (from === 0) return;
|
||||||
const to = from - 1;
|
const to = from - 1;
|
||||||
const newNames = [...names];
|
const newExercises = [...exercises];
|
||||||
const copy = newNames[from];
|
const copy = newExercises[from];
|
||||||
newNames[from] = newNames[to];
|
newExercises[from] = newExercises[to];
|
||||||
newNames[to] = copy;
|
newExercises[to] = copy;
|
||||||
const newExercises = newNames.filter((name) => exercises.includes(name));
|
|
||||||
setExercises(newExercises);
|
setExercises(newExercises);
|
||||||
setNames(newNames);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -163,7 +170,7 @@ export default function EditPlan() {
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</StackHeader>
|
</StackHeader>
|
||||||
<View style={{ padding: PADDING, flex: 1 }}>
|
<ScrollView style={{ padding: PADDING, flex: 1 }}>
|
||||||
<AppInput
|
<AppInput
|
||||||
label="Title"
|
label="Title"
|
||||||
value={title}
|
value={title}
|
||||||
|
@ -175,18 +182,15 @@ export default function EditPlan() {
|
||||||
{DAYS.map((day) => renderDay(day))}
|
{DAYS.map((day) => renderDay(day))}
|
||||||
|
|
||||||
<Text style={[styles.title, { marginTop: MARGIN }]}>Exercises</Text>
|
<Text style={[styles.title, { marginTop: MARGIN }]}>Exercises</Text>
|
||||||
{names !== undefined && (
|
{exercises.map((exercise, index) =>
|
||||||
<FlatList
|
renderExercise(exercise, index, true)
|
||||||
data={names}
|
|
||||||
ListEmptyComponent={<Text>No exercises yet</Text>}
|
|
||||||
renderItem={({ item, index }) => renderExercise(item, index)}
|
|
||||||
keyExtractor={(item) => item}
|
|
||||||
style={{
|
|
||||||
flex: 1,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</View>
|
{names !== undefined &&
|
||||||
|
names
|
||||||
|
.filter((name) => !exercises.includes(name))
|
||||||
|
.map((name, index) => renderExercise(name, index, false))}
|
||||||
|
<View style={{ marginBottom: MARGIN }}></View>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
<PrimaryButton
|
<PrimaryButton
|
||||||
disabled={exercises.length === 0 && days.length === 0}
|
disabled={exercises.length === 0 && days.length === 0}
|
||||||
|
|
|
@ -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 36221
|
versionCode 36222
|
||||||
versionName "2.6"
|
versionName "2.7"
|
||||||
}
|
}
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
release {
|
release {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "massive",
|
"name": "massive",
|
||||||
"version": "2.6",
|
"version": "2.7",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "GPL-3.0-only",
|
"license": "GPL-3.0-only",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in New Issue