Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/ApiContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getUserInfo } from './User';
import { acceptFriendRequest } from './Friends';
import { ExpectedExercise, getExercisePlan, Plan } from './Workouts'
import { WorkoutTypeType } from './Workouts';
import { getExercise, exerciseType } from './Exercise'
import { getExercise, ExerciseType } from './Exercise'


export interface ApiContextType {
Expand All @@ -17,7 +17,7 @@ export interface ApiContextType {
updateUserData: () => Promise<String | null>;
userData: UserType | null;
exercisePlan: Plan | null;
exercises:Array<exerciseType>
exercises:Array<ExerciseType>
}


Expand All @@ -28,7 +28,7 @@ export const ApiProvider = ({ children }: { children: ReactNode }) => {
const [loggedIn, setLoggedIn] = useState<boolean>(false);
const [userData, setUserData] = useState<UserType | null>(null);
const [exercisePlan, setExercisePlan] = useState<Plan| null>(null);
const [exercises, setExercises] = useState<Array<exerciseType>>([]);
const [exercises, setExercises] = useState<Array<ExerciseType>>([]);



Expand Down
14 changes: 8 additions & 6 deletions api/Exercise.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { router } from 'expo-router';
import { ApiContextType } from './ApiContext';
import { workout_category } from './Workouts';
import { ExpectedExercise } from './Workouts';


export function string_to_date(input: string): Date | undefined {
// Parse the input string into a Date object
const date = new Date(input);
Expand All @@ -18,7 +20,7 @@ export function string_to_date(input: string): Date | undefined {
return date;
}

export interface exerciseType{
export interface ExerciseType{
start: Date | undefined,
workout_type: WorkoutTypeType
end: Date | undefined,
Expand Down Expand Up @@ -58,7 +60,7 @@ export interface WorkoutTypeType {
category: workout_category;
}

export const getNextExercises = (plan_data: Plan | null, ex_data: exerciseType[]): ExpectedExercise[] => {
export const getNextExercises = (plan_data: Plan | null, ex_data: ExerciseType[]): ExpectedExercise[] => {
console.log("plan data doesn't exist?");
if (!plan_data) {
return [];
Expand Down Expand Up @@ -232,10 +234,10 @@ export const getExercise = async(token:string) =>{
return [];
}
const data = await response.json();
let return_list:exerciseType[] = []
let return_list:ExerciseType[] = []
for (let i=0;i<data.ex.length;i++){
let ex =data.ex[i];
let return_item:exerciseType = {
let return_item:ExerciseType = {
start:string_to_date(ex.start),
end:string_to_date(ex.end),
workout_type:{
Expand Down Expand Up @@ -273,10 +275,10 @@ export const startExerciseDirect = async(token:string,exp:ExpectedExercise) =>{
return null;
}
const data = await response.json();
let return_list:exerciseType[] = []
let return_list:ExerciseType[] = []
for (let i=0;i<data.ex.length;i++){
let ex =data.ex[i];
let return_item:exerciseType = {
let return_item:ExerciseType = {
start:string_to_date(ex.start),
end:string_to_date(ex.end),
workout_type:{
Expand Down
10 changes: 5 additions & 5 deletions api/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { router } from 'expo-router';
import React, { createContext, useContext, ReactNode, useState } from 'react';

import { ApiContextType } from './ApiContext';
import { expectedExercise, workoutTypeType } from './Workouts';
import { exerciseType, string_to_date } from './Exercise';
import { ExpectedExercise, WorkoutTypeType } from './Workouts';
import { ExerciseType, string_to_date } from './Exercise';


export interface feedType extends exerciseType{
export interface FeedType extends ExerciseType{
user:string,
}

Expand All @@ -30,10 +30,10 @@ export const getFriendFeed = async(token:string) =>{
}
const data = await response.json();

let ret:feedType[] = []
let ret:FeedType[] = []
for (let i=0;i<data.length;i++){
let ex =data[i];
let return_item:feedType = {
let return_item:FeedType = {
start:string_to_date(ex.start),
end:string_to_date(ex.end),
workout_type:{
Expand Down
118 changes: 55 additions & 63 deletions app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import Ionicons from '@expo/vector-icons/Ionicons';
import { Redirect, router, Stack, useRootNavigationState } from 'expo-router';
import { Tabs } from 'expo-router/tabs';
import React, { DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_FORM_ACTIONS, useEffect, useState } from 'react';
import { Modal,Text, TextInput, TouchableOpacity, View } from 'react-native';
import { Modal,Text, TouchableOpacity, View } from 'react-native';
import { useApiContext } from '../../api/ApiContext';
import { useTheme } from '../utility/ThemeContext';
import { StyleSheet } from 'react-native';
import { endExercise, exerciseType, getNextExercises,startExerciseDirect } from '../../api/Exercise';
import { endExercise, ExerciseType, getNextExercises,startExerciseDirect } from '../../api/Exercise';
import { UserType } from '../../api/User';
import { ExpectedExercise, Plan } from '../../api/Workouts';
import { styles } from '../utility/style';
Expand Down Expand Up @@ -107,17 +107,17 @@ export default () => {
});
return(
<TouchableOpacity onPress={() => onPress_func(expect_ex)} style={style.button}>
<Text style={style.buttonText}>{expect_ex.name+ "for "+returnNumberAsTime(expect_ex.time)}</Text>
<Text style={style.buttonText}>{expect_ex.name+ " for "+returnNumberAsTime(expect_ex.time)}</Text>
</TouchableOpacity>
)
}



function returnButtonSelector(user:UserType|null, plan:Plan|null){
if(user?.isWorking){
if(user?.isWorking) {
return (
<View style={{top: -30}}>
<View style={{top: -30}}>
<CountdownCircleTimer
isPlaying
duration={duration}
Expand All @@ -129,39 +129,35 @@ export default () => {
setisPlaying(false);
return { } // repeat animation in 1.5 seconds
}}

>
{({ remainingTime }) => (
<TouchableOpacity
style={styles1.countdownTimer}
onPress={async () => {
await endExercise(authToken);
await updateUserData();
}}
>

style={styles1.countdownTimer}
onPress={async () => {
await endExercise(authToken);
await updateUserData();
}}
>
<Ionicons name="checkmark-done-circle-outline" size={40} color="blue" />


</TouchableOpacity>
</TouchableOpacity>
)}
</CountdownCircleTimer>
</View>
</View>
);
}
if(workoutOptions.length > 0){
return(
<TouchableOpacity style={styles1.button} onPress={()=>{
if(workoutOptions.length > 0){
setWrkSlctVisible(true);
}
}}>

<Ionicons name="bicycle" size={40} color="#fff" />
</TouchableOpacity>
)

if(workoutOptions.length > 0) {
return (
<TouchableOpacity
style={styles1.button}
onPress={() => {if(workoutOptions.length > 0) setWrkSlctVisible(true)}}
>
<Ionicons name="bicycle" size={40} color="#fff" />
</TouchableOpacity>
)
}
return(

return (

<TouchableOpacity style={styles1.button}>

Expand All @@ -175,20 +171,20 @@ export default () => {
return (
<>
<Modal
animationType="fade"
transparent={true}
visible={wrkSlct}
onRequestClose={() => setWrkSlctVisible(false)}
>
<View style={styles.modalContainer}>
<View style={styles.modalContent}>
{workoutOptions.map((val,idx)=>{return renderExcerciseSelector(val)})}
<TouchableOpacity onPress={() => setWrkSlctVisible(false)} style={styles.closeButton}>
<Ionicons name="close" size={20} /> {/* Close icon */}
</TouchableOpacity>
</View>
</View>
</Modal>
animationType="fade"
transparent={true}
visible={wrkSlct}
onRequestClose={() => setWrkSlctVisible(false)}
>
<View style={styles.modalContainer}>
<View style={styles.modalContent}>
{workoutOptions.map((val,idx)=>{return renderExcerciseSelector(val)})}
<TouchableOpacity onPress={() => setWrkSlctVisible(false)} style={styles.closeButton}>
<Ionicons name="close" size={20} /> {/* Close icon */}
</TouchableOpacity>
</View>
</View>
</Modal>
<Tabs screenOptions={({ route }) => ({
tabBarIcon: ({ focused, color, size }) => {
let iconName;
Expand All @@ -208,27 +204,23 @@ export default () => {
},
tabBarActiveTintColor: theme.colors.primary,
tabBarInactiveTintColor: 'gray',
})
}
>
})}>


{ /*Order of tabs*/ }
<Tabs.Screen name="home" options={{title: "Home"}}/>
<Tabs.Screen name="workout" options={{title: "Workout"}}/>
<Tabs.Screen name="feed" options={{title: "Feed"}}/>
<Tabs.Screen
name="exercise"
options={{
tabBarButton: () => (returnButtonSelector(userData,exercisePlan)
),
}}
/>
<Tabs.Screen name="friends" options={{title: "Friends"}}/>
<Tabs.Screen name="profile" options={{title: "Profile"}}/>
<Tabs.Screen name="plan" options={{title: "Plan"}}/>

</Tabs>
{ /*Order of tabs*/ }
<Tabs.Screen name="home" options={{title: "Home"}}/>
<Tabs.Screen name="workout" options={{title: "Workout"}}/>
<Tabs.Screen name="feed" options={{title: "Feed"}}/>
<Tabs.Screen
name="exercise"
options={{
tabBarButton: () => (returnButtonSelector(userData,exercisePlan))
}}
/>
<Tabs.Screen name="friends" options={{title: "Friends"}}/>
<Tabs.Screen name="profile" options={{title: "Profile"}}/>
<Tabs.Screen name="plan" options={{title: "Plan"}}/>

</Tabs>
</>
);
}
Expand Down
6 changes: 3 additions & 3 deletions app/(tabs)/feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import React, { useState, useEffect } from 'react';
import { Text, StyleSheet, View, FlatList } from 'react-native';
import { useApiContext } from '../../api/ApiContext';
import { defaultPageTheme } from '../utility/style';
import { feedType, getFriendFeed } from '../../api/Feed';
import { FeedType, getFriendFeed } from '../../api/Feed';
import { workout_category } from '../../api/Workouts';

export default function FriendsPage() {
const { authToken } = useApiContext();
const [friendFeed, setFriendFeed] = useState<feedType[]>([]);
const [friendFeed, setFriendFeed] = useState<FeedType[]>([]);

useEffect(() => {
const fetchFeed = async () => {
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function FriendsPage() {
}
};

const renderFeedItem = ({item}:{item:feedType}) => {
const renderFeedItem = ({item}:{item:FeedType}) => {
console.log("END TIME", item.end.toISOString());
console.log(item.expectedTime);
const actualDuration = (item.end && item.start) ? Math.floor((item.end.getTime() - item.start.getTime()) / 1000) : 0;
Expand Down
4 changes: 2 additions & 2 deletions app/(tabs)/friends.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export default function FriendsPage() {
placeholder='Friend Name'
value={friendName}
onChangeText={setFriendName}
secure={false}
style = {styles.input}
//secureTextEntry={false}
//style = {styles.input}
/>
<Button
onPress={async () => {let xd = await sendFriendRequest(authToken,friendName);await updateUserData();setErrorMessage(xd)}}
Expand Down
Loading