Skip to content

Commit

Permalink
prevent error when goalLogs is undefined or empty in GoalItem
Browse files Browse the repository at this point in the history
  • Loading branch information
mika-em committed Oct 16, 2024
1 parent 534258f commit f810664
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/(tabs)/goals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default function GoalsPage() {
<Text className="text-center">No goals found for this date.</Text>
)}
renderItem={({ item }) => (
<GoalItem goal={item.goal} goalLog={item.goalLog} />
<GoalItem goal={item.goal} goalLogs={item.goalLogs} />
)}
keyExtractor={(item) => item.goal._id.toString()}
/>
Expand All @@ -198,14 +198,14 @@ export default function GoalsPage() {

interface GoalItemProps {
goal: Doc<"goals">;
goalLog: Doc<"goalLogs">;
goalLogs: Doc<"goalLogs">[];
}

function GoalItem({ goal, goalLogs }: GoalItemProps) {
const router = useRouter();

// Get the latest log (or some other logic for selecting a log)
const latestLog = goalLogs[goalLogs.length - 1]; // Assuming you want the most recent log
const latestLog = goalLogs && goalLogs.length > 0 ? goalLogs[goalLogs.length - 1] : null;

const allowedUnits = [
"steps",
Expand All @@ -230,6 +230,10 @@ function GoalItem({ goal, goalLogs }: GoalItemProps) {
"miles",
];

if (!latestLog) {
return null;
}

const handleLogPress = (e: any) => {

Check warning on line 237 in app/(tabs)/goals.tsx

View workflow job for this annotation

GitHub Actions / npm run lint

Unexpected any. Specify a different type
e.stopPropagation(); // Prevent parent navigation

Expand Down

0 comments on commit f810664

Please sign in to comment.