Skip to content

Commit

Permalink
Merge pull request #322 from bounswe/TrainingProgramUpdated
Browse files Browse the repository at this point in the history
Training program updated
  • Loading branch information
hanazaq authored Dec 16, 2024
2 parents 31f7f5c + f3fae7a commit 58a3dc5
Show file tree
Hide file tree
Showing 12 changed files with 1,152 additions and 11 deletions.
14 changes: 14 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"react-redux": "^9.1.1",
"react-router-dom": "^6.28.0",
"react-select": "^5.8.0",
"react-toastify": "^10.0.6",
"sass": "^1.54.5",
"vite": "^3.0.9"
},
Expand Down
349 changes: 349 additions & 0 deletions frontend/src/components/Detailed_Ex_Modal.component.jsx

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions frontend/src/components/Detailed_Training_Modal.component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React from 'react';
import {
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalFooter,
ModalBody,
ModalCloseButton,
Button,
Table,
Thead,
Tbody,
Tr,
Th,
Td,
UnorderedList,
ListItem,
} from '@chakra-ui/react';
import { useNavigate } from '@tanstack/react-router';
import { LinkIcon } from '@chakra-ui/icons';

const Detailed_Training_Modal = ({ isOpen, onClose, data }) => {
const navigate = useNavigate();

const VisitTraining = (program_id) => {
navigate({
to: `/training?trainingId=${program_id}`,
});
};

return (
<Modal isOpen={isOpen} onClose={onClose}>
<ModalOverlay />
<ModalContent maxWidth="90%" width="60%">
<ModalHeader>{data.title} Detailed Description</ModalHeader>
<ModalCloseButton />
<ModalBody>
<Table variant="striped" width="100%">
<Thead>
<Tr>
<Th>Week</Th>
<Th>Workout</Th>
<Th>List of Exercises</Th>
</Tr>
</Thead>
<Tbody>
{data.weeks.map((week) =>
week.workouts.map((workout) => (
<Tr key={workout.id}>
<Td>Week {week.weekNumber}</Td>
<Td>{workout.name}</Td>
<Td>
<UnorderedList>
{workout.workoutExercises.map((exerciseob) => (
<ListItem key={exerciseob.id} textAlign="left">
{exerciseob.exercise.name}
</ListItem>
))}
</UnorderedList>
</Td>
</Tr>
))
)}
</Tbody>
</Table>
</ModalBody>
<ModalFooter>
<Button colorScheme="blue" mr={3} onClick={onClose}>
Close
</Button>
<Button
colorScheme="green"
onClick={() => VisitTraining(data.id)} // Pass a function reference
>
<LinkIcon className="w-4 h-4 mr-3" />
Visit Training Page
</Button>
</ModalFooter>
</ModalContent>
</Modal>
);
};

export default Detailed_Training_Modal;
167 changes: 167 additions & 0 deletions frontend/src/components/Detailed_Workout_Modal.component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import React from 'react';
import {
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalFooter,
ModalBody,
ModalCloseButton,
Button,
Table,
Thead,
Tbody,
Tr,
Th,
Td,
UnorderedList,
ListItem,
VStack,
HStack,
Tag,
TagLabel
} from '@chakra-ui/react';

const Detailed_Workout_Modal = ({ isOpen, onClose, data, weekNumber, workoutNumber }) => {
// Fetch the workout details for the specified week and workout number
const getWorkoutByNumber = (weekNumber, workoutNumber) => {
const week = data?.weeks?.find(week => week.weekNumber === weekNumber);
return week?.workouts?.find(workout => workout.workoutNumber === workoutNumber);
};

const current_workout = getWorkoutByNumber(weekNumber, workoutNumber);

if (!current_workout) {
return (
<Modal isOpen={isOpen} onClose={onClose} size="full">
<ModalOverlay />
<ModalContent>
<ModalHeader>Workout Details Not Found</ModalHeader>
<ModalCloseButton />
<ModalBody>
<p>No data available for the selected workout.</p>
</ModalBody>
<ModalFooter>
<Button colorScheme="blue" onClick={onClose}>
Close
</Button>
</ModalFooter>
</ModalContent>
</Modal>
);
}

return (
<Modal isOpen={isOpen} onClose={onClose} size="full">
<ModalOverlay />
<ModalContent>
<ModalHeader>{data.title} | Week {weekNumber} | Workout {workoutNumber} Detailed Description</ModalHeader>
<ModalCloseButton />
<ModalBody overflowX="auto">
<Table variant="striped" size="lg" width="100%">
<Thead>
<Tr>
<Th>Exercise Name</Th>
<Th>Exercise Gif</Th>
<Th>Instructions</Th>
<Th>Exercise Tags</Th>
</Tr>
</Thead>
<Tbody>
{current_workout.workoutExercises.map((ex) => {
const exerciseDetails = ex.exercise;

return (
<Tr key={ex.exerciseNumber}>
{/* Exercise Name */}
<Td>
<VStack align="start">
<strong>{exerciseDetails?.name || 'N/A'}</strong>
<span>Sets: {ex.sets}</span>
<span>Reps: {ex.repetitions}</span>
</VStack>
</Td>

{/* Exercise Gif */}
<Td>
{exerciseDetails?.gifUrl ? (
<img
src={exerciseDetails.gifUrl}
alt={exerciseDetails.name || 'Exercise Gif'}
style={{
width: '200px',
height: '200px',
objectFit: 'cover'
}}
/>
) : (
'No Image Available'
)}
</Td>

{/* Instructions */}
<Td>
<UnorderedList spacing={2}>
{exerciseDetails?.instructions?.length ? (
exerciseDetails.instructions.map((instruction, index) => (
<ListItem key={index}>{instruction}</ListItem>
))
) : (
<ListItem>No Instructions Available</ListItem>
)}
</UnorderedList>
</Td>

{/* Exercise Tags */}
<Td>
<VStack align="start" spacing={2}>
{exerciseDetails?.bodyPart && (
<HStack>
<Tag colorScheme="blue">
<TagLabel>Body Part: {exerciseDetails.bodyPart}</TagLabel>
</Tag>
</HStack>
)}
{exerciseDetails?.targetMuscle && (
<HStack>
<Tag colorScheme="green">
<TagLabel>Target Muscle: {exerciseDetails.targetMuscle}</TagLabel>
</Tag>
</HStack>
)}
{exerciseDetails?.equipment && (
<HStack>
<Tag colorScheme="purple">
<TagLabel>Equipment: {exerciseDetails.equipment}</TagLabel>
</Tag>
</HStack>
)}
{exerciseDetails?.secondaryMuscles?.length > 0 && (
<HStack>
<Tag colorScheme="orange">
<TagLabel>
Secondary Muscles: {exerciseDetails.secondaryMuscles.join(', ')}
</TagLabel>
</Tag>
</HStack>
)}
</VStack>
</Td>
</Tr>
);
})}
</Tbody>
</Table>
</ModalBody>

<ModalFooter>
<Button colorScheme="blue" mr={3} onClick={onClose}>
Close
</Button>
</ModalFooter>
</ModalContent>
</Modal>
);
};

export default Detailed_Workout_Modal;
10 changes: 8 additions & 2 deletions frontend/src/components/PostFeedCard.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { useSelector } from 'react-redux'
import { userSessionToken } from '../context/user'
import apiInstance from '../instance/apiInstance'
import { useColorModeValue } from '@chakra-ui/react'
import Detailed_Training_Modal from './Detailed_Training_Modal.component';

function PostFeedCard({ post }) {
const sessionToken = useSelector(userSessionToken)
Expand Down Expand Up @@ -327,7 +328,12 @@ function PostFeedCard({ post }) {
</Button>
</CardFooter>
</Card>

<Detailed_Training_Modal
isOpen={isOpen}
onClose={onClose}
data={post.trainingProgram}
/>
{/*
<Modal isOpen={isOpen} onClose={onClose} size="xl">
<ModalOverlay />
<ModalContent>
Expand Down Expand Up @@ -357,7 +363,7 @@ function PostFeedCard({ post }) {
</Accordion>
</ModalBody>
</ModalContent>
</Modal>
</Modal> */}
</>
)
}
Expand Down
19 changes: 18 additions & 1 deletion frontend/src/components/ProgramFeedCard.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
useToast,
Tooltip
} from '@chakra-ui/react'
import { ViewIcon } from '@chakra-ui/icons';
// import { useNavigate } from 'react-router-dom';
import { useNavigate } from '@tanstack/react-router'
import { useMutation, useQueryClient } from '@tanstack/react-query'
Expand All @@ -24,12 +25,15 @@ import apiInstance from '../instance/apiInstance'
import PlusIcon from '../icons/PlusIcon'
import { UserContext } from '../context/UserContext'
// import { router } from '../main.jsx';
import Detailed_Training_Modal from './Detailed_Training_Modal.component';
import { useDisclosure } from '@chakra-ui/react';


function ProgramFeedCard({
program
}) {

const { isOpen, onOpen, onClose } = useDisclosure();
const password = useSelector(userPassword)
const sessionToken = useSelector(userSessionToken)
const toast = useToast()
Expand Down Expand Up @@ -224,7 +228,7 @@ function ProgramFeedCard({
const handleStartPracticing = (program_id) => {
navigate(
{
to: `/program?programId=${program_id}`,
to: `/training?trainingId=${program_id}`,
}
)
}
Expand Down Expand Up @@ -313,6 +317,14 @@ function ProgramFeedCard({
</li>
))}
</Text> */}
<Button
onClick={onOpen}
colorScheme="gray"
variant="solid"
>
<ViewIcon className="w-4 h-4 mr-3" />
View Description
</Button>
</CardBody>


Expand Down Expand Up @@ -381,6 +393,11 @@ function ProgramFeedCard({
</Flex>
</CardFooter>
</Card>
<Detailed_Training_Modal
isOpen={isOpen}
onClose={onClose}
data={program}
/>
</>

)
Expand Down
Loading

0 comments on commit 58a3dc5

Please sign in to comment.