From ed01fb3a68eeb0020eb629d156ca83b3f9349d3e Mon Sep 17 00:00:00 2001
From: Christian Lentfort <1284808+clentfort@users.noreply.github.com>
Date: Mon, 29 Jan 2024 11:39:30 +0100
Subject: [PATCH] fix: correctly handle type on plan items
---
src/api/types.ts | 3 +-
src/app/(app)/current-plan/[id].tsx | 105 +++----------------
src/app/(app)/current-plan/exercise/[id].tsx | 6 +-
src/app/(app)/plan/[id].tsx | 52 +--------
src/components/plan-items.tsx | 101 ++++++++++++++++++
5 files changed, 120 insertions(+), 147 deletions(-)
create mode 100644 src/components/plan-items.tsx
diff --git a/src/api/types.ts b/src/api/types.ts
index a2a51bc..bbe9ecd 100644
--- a/src/api/types.ts
+++ b/src/api/types.ts
@@ -74,12 +74,13 @@ export interface PlanItem extends ParseObject {
exercise: ParsePointer<"Exercise", Exercise>;
finishedSets: PlanItemSet[];
history: PlanItemSetHistory[];
+ name?: string;
note: string;
openSets: PlanItemSet[];
plan: ParsePointer<"Plan", Plan>;
position: number;
sets: PlanItemSet[];
- type: string;
+ type: "TEXT" | "EXERCISE";
}
interface UserExtended extends ParseObject {
diff --git a/src/app/(app)/current-plan/[id].tsx b/src/app/(app)/current-plan/[id].tsx
index f95e913..121903f 100644
--- a/src/app/(app)/current-plan/[id].tsx
+++ b/src/app/(app)/current-plan/[id].tsx
@@ -1,24 +1,15 @@
-import {
- Button,
- Card,
- List,
- ListItem,
- ProgressBar,
- Text,
- useTheme,
-} from "@ui-kitten/components";
+import { Button, ProgressBar, Text } from "@ui-kitten/components";
import { router, useLocalSearchParams } from "expo-router";
import React from "react";
-import { Alert, Image, View } from "react-native";
+import { Alert } from "react-native";
-import { PlanItem as PlanItemType } from "@/api/types";
+import { PlanItem } from "@/api/types";
import useObject from "@/api/use-object";
import useObjects from "@/api/use-objects";
import useUpdateObject from "@/api/use-update-object";
import PageLayout from "@/components/page-layout";
+import PlanItems from "@/components/plan-items";
import useAsyncStorage from "@/hooks/use-async-storage";
-import { PartiallyResolvedPointer } from "@/parse-client/pointer";
-import { space } from "@/styles";
export default function PlanScreen() {
const planId = useLocalSearchParams<{ id: string }>().id!;
@@ -43,8 +34,9 @@ export default function PlanScreen() {
return Loading;
}
+ const exercises = planItems.results.filter(({ type }) => type === "EXERCISE");
const done = new Set(
- planItems.results
+ exercises
.filter((item) => item.openSets.length === 0)
.map((item) => item.objectId),
);
@@ -63,7 +55,7 @@ export default function PlanScreen() {
};
const handleEndSession = () => {
- if (done.size < planItems.results.length) {
+ if (done.size < exercises.length) {
Alert.alert(
"Training beenden?",
`Du hast erst ${done.size} von ${planItems.results.length} Übungen absolviert. Training wirklich beenden?`,
@@ -74,6 +66,10 @@ export default function PlanScreen() {
}
};
+ const handleItemPress = (item: PlanItem) => {
+ router.push(`/current-plan/exercise/${item.objectId}`);
+ };
+
return (
- {
- return ;
- }}
- />
+