parent
10edfba92b
commit
3993466b4d
@ -0,0 +1,13 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const apiClient = axios.create({
|
||||
baseURL: 'https://codefirst.iut.uca.fr/containers/Optifit-optifit-ef-api/api/v1/',
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
// ajoute ici les headers supplémentaires, ex. Auth
|
||||
},
|
||||
});
|
||||
|
||||
export default apiClient;
|
@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
export const EXERCICES = {
|
||||
GETALL: '/exercices',
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
import apiClient from "../client";
|
||||
import {EXERCICES} from "../endpoints";
|
||||
|
||||
export const getExercices = async () => {
|
||||
try {
|
||||
const response = await apiClient.get(EXERCICES.GETALL);
|
||||
return response.data.data;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw error;
|
||||
}
|
||||
};
|
@ -1,47 +1,54 @@
|
||||
import {FlatList, SafeAreaView, Text, View} from "react-native";
|
||||
import React from "react";
|
||||
import HeaderProfileComponent from "@/components/HeaderProfileComponent";
|
||||
import Screen from "@/components/ui/Screen";
|
||||
import WorkoutCardComponent from "@/components/WorkoutCardComponent";
|
||||
import {useSession} from "@/ctx";
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { FlatList, Text, TouchableOpacity, View } from 'react-native';
|
||||
import { getExercices } from "@/api/services/ExercicesServices";
|
||||
import { useRouter } from "expo-router";
|
||||
import { Workout } from "@/model/Workout";
|
||||
import LinearTimer from "react-native-linear-timer";
|
||||
import WorkoutCardComponent from "@/components/WorkoutCardComponent";
|
||||
|
||||
export default function ExercicesScreen() {
|
||||
const [text, onChangeText] = React.useState("");
|
||||
const exercise = [new Workout("Développé couché", 25,"8 Series Workout", 412, "assets/images/Sigma-2.png","Intense" ),
|
||||
new Workout("Curl halterné", 30, "8 Series Workout", 342, "assets/images/Sigma.jpg","Medium" ),
|
||||
new Workout("Tirage Vertival", 29, "8 Series Workout", 793, "assets/images/Sigma.jpg","Easy" )];
|
||||
|
||||
return (
|
||||
<View className="h-full p-2 mt-11">
|
||||
const [exercices, setExercices] = useState<Workout[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const data = await getExercices();
|
||||
setExercices(data);
|
||||
} catch (err: any) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
<FlatList
|
||||
ListHeaderComponent={
|
||||
<>
|
||||
<View className="">
|
||||
<HeaderProfileComponent/>
|
||||
</View>
|
||||
<View className="mt-4">
|
||||
<View className="flex-row justify-between items-center mb-4">
|
||||
<Text className="text-lg font-bold text-black">Séance du jour</Text>
|
||||
</View>
|
||||
</View>
|
||||
</>
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
if (loading) {
|
||||
return <Text className="text-white">Chargement...</Text>;
|
||||
}
|
||||
data={exercise}
|
||||
className="h-full"
|
||||
renderItem={({ item }: { item: Workout }) =>
|
||||
|
||||
<View className="mt-2 h-52">
|
||||
<WorkoutCardComponent exercise={item}/>
|
||||
</View>
|
||||
if (error) {
|
||||
return <Text className="text-red-500">Erreur : {error}</Text>;
|
||||
}
|
||||
/>
|
||||
|
||||
</View>
|
||||
|
||||
return (
|
||||
|
||||
<View className="p-4">
|
||||
<FlatList
|
||||
data={exercices}
|
||||
keyExtractor={(item) => item.id}
|
||||
renderItem={({ item }) => (
|
||||
<TouchableOpacity
|
||||
className="p-4 mb-2 bg-gray-800 rounded-lg"
|
||||
onPress={() => router.push({ pathname: "/WorkoutScreen", params: { workout: JSON.stringify(item) } })}
|
||||
>
|
||||
<WorkoutCardComponent exercise={item} background={"black"} />
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
export const useExercices = () => {
|
||||
const [exercices, setExercices] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
useEffect(() => {
|
||||
const fetchExercices = async () => {
|
||||
try {
|
||||
const response = await apiClient.get(EXERCICES.GETALL);
|
||||
setExercices(response.data);
|
||||
setLoading(false);
|
||||
} catch (error) {
|
||||
setError(error);
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
fetchExercices();
|
||||
}, []);
|
||||
return { exercices, loading, error };
|
||||
}
|
@ -1,43 +1,10 @@
|
||||
export class Workout {
|
||||
|
||||
private _name: string
|
||||
private _duration: number
|
||||
private _calories: number
|
||||
private _repetitions: string
|
||||
private _image: string
|
||||
private _level: string
|
||||
|
||||
|
||||
get name(): string {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
get duration(): number {
|
||||
return this._duration;
|
||||
}
|
||||
|
||||
get calories(): number {
|
||||
return this._calories;
|
||||
}
|
||||
|
||||
get repetitions(): string {
|
||||
return this._repetitions;
|
||||
}
|
||||
|
||||
get image(): string {
|
||||
return this._image;
|
||||
}
|
||||
|
||||
get level(): string {
|
||||
return this._level;
|
||||
}
|
||||
|
||||
constructor(name: string, duration: number, repetition: string, calories: number, image: string, level: string) {
|
||||
this._name = name;
|
||||
this._duration = duration;
|
||||
this._repetitions = repetition
|
||||
this._calories = calories;
|
||||
this._image = image;
|
||||
this._level = level;
|
||||
}
|
||||
export interface Workout {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
duration: number;
|
||||
image: string;
|
||||
video: string;
|
||||
nbSeries: number;
|
||||
nbRepetitions: number;
|
||||
}
|
Loading…
Reference in new issue