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, { useEffect, useState } from 'react';
|
||||||
import React from "react";
|
import { FlatList, Text, TouchableOpacity, View } from 'react-native';
|
||||||
import HeaderProfileComponent from "@/components/HeaderProfileComponent";
|
import { getExercices } from "@/api/services/ExercicesServices";
|
||||||
import Screen from "@/components/ui/Screen";
|
import { useRouter } from "expo-router";
|
||||||
|
import { Workout } from "@/model/Workout";
|
||||||
import WorkoutCardComponent from "@/components/WorkoutCardComponent";
|
import WorkoutCardComponent from "@/components/WorkoutCardComponent";
|
||||||
import {useSession} from "@/ctx";
|
|
||||||
import {Workout} from "@/model/Workout";
|
|
||||||
import LinearTimer from "react-native-linear-timer";
|
|
||||||
|
|
||||||
export default function ExercicesScreen() {
|
export default function ExercicesScreen() {
|
||||||
const [text, onChangeText] = React.useState("");
|
const [exercices, setExercices] = useState<Workout[]>([]);
|
||||||
const exercise = [new Workout("Développé couché", 25,"8 Series Workout", 412, "assets/images/Sigma-2.png","Intense" ),
|
const [loading, setLoading] = useState(true);
|
||||||
new Workout("Curl halterné", 30, "8 Series Workout", 342, "assets/images/Sigma.jpg","Medium" ),
|
const [error, setError] = useState(null);
|
||||||
new Workout("Tirage Vertival", 29, "8 Series Workout", 793, "assets/images/Sigma.jpg","Easy" )];
|
const router = useRouter();
|
||||||
|
|
||||||
return (
|
useEffect(() => {
|
||||||
<View className="h-full p-2 mt-11">
|
const fetchData = async () => {
|
||||||
|
try {
|
||||||
<FlatList
|
const data = await getExercices();
|
||||||
ListHeaderComponent={
|
setExercices(data);
|
||||||
<>
|
} catch (err: any) {
|
||||||
<View className="">
|
setError(err.message);
|
||||||
<HeaderProfileComponent/>
|
} finally {
|
||||||
</View>
|
setLoading(false);
|
||||||
<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>
|
|
||||||
</>
|
|
||||||
|
|
||||||
}
|
}
|
||||||
data={exercise}
|
};
|
||||||
className="h-full"
|
|
||||||
renderItem={({ item }: { item: Workout }) =>
|
|
||||||
|
|
||||||
<View className="mt-2 h-52">
|
fetchData();
|
||||||
<WorkoutCardComponent exercise={item}/>
|
}, []);
|
||||||
</View>
|
|
||||||
}
|
if (loading) {
|
||||||
/>
|
return <Text className="text-white">Chargement...</Text>;
|
||||||
|
}
|
||||||
|
|
||||||
</View>
|
if (error) {
|
||||||
|
return <Text className="text-red-500">Erreur : {error}</Text>;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
export interface Workout {
|
||||||
|
id: string;
|
||||||
private _name: string
|
name: string;
|
||||||
private _duration: number
|
description: string;
|
||||||
private _calories: number
|
duration: number;
|
||||||
private _repetitions: string
|
image: string;
|
||||||
private _image: string
|
video: string;
|
||||||
private _level: string
|
nbSeries: number;
|
||||||
|
nbRepetitions: number;
|
||||||
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in new issue