Skip to content

Commit

Permalink
fin
Browse files Browse the repository at this point in the history
Co-authored-by: pabloangusto <[email protected]>
Co-authored-by: josemifd20 <[email protected]>
  • Loading branch information
Arejula11 committed Dec 18, 2023
1 parent 86d731d commit 0b83672
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 44 deletions.
2 changes: 1 addition & 1 deletion docker/web/src/Components/Feed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const Feed = () => {
<h4>Ejercicios:</h4>
{training.sets.map(set => {
const exerciseName = set.exercise.name;
console.log(set.exercise.name)
//console.log(set.exercise.name)
if (!uniqueExerciseNames.includes(exerciseName) && uniqueExerciseNames.length < 5) {
uniqueExerciseNames.push(exerciseName);

Expand Down
10 changes: 5 additions & 5 deletions docker/web/src/Components/Historial.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ const Historial = () => {

}

const segundosATiempo = (segundos) => {
const horas = Math.floor(segundos / 3600);
const minutos = Math.floor((segundos % 3600) / 60);
const minutosATiempo = (minutos) => {
const horas = Math.floor( minutos / 60);
//console.log(horas, minutos)
if(horas == 0){
return`${minutos}m`
}else{
return `${horas}h ${minutos}m`;
return `${horas}h ${Math.floor(minutos % 60)}m`;
}

}
Expand Down Expand Up @@ -79,7 +79,7 @@ const Historial = () => {
<div className='info-rectangle'>
<h3>{training.name}</h3>
<ReactTimeAgo date={Date.parse(training.created_at)} locale='es-ES' className='date-rectangle'/>
<label>{segundosATiempo(training.duration)}</label>
<label>{minutosATiempo(training.duration)}</label>
</div>
<div className='separator'></div>
<div className='exercises-rectangle'>
Expand Down
37 changes: 26 additions & 11 deletions docker/web/src/Components/PageListFriends.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { NavLink, useNavigate } from "react-router-dom"
const PageListFriends = () => {

const navigate = useNavigate()
const [reload, setReload] = useState(true);

const[friends, setFriends] = useState([])
const getFriendList = async() => {
const request = await fetch(Global.url+'friend/friends', {
Expand All @@ -31,7 +33,8 @@ const PageListFriends = () => {

useEffect(() => {
getFriendList()
}, [])
setReload(true)
}, [reload])

const eliminarAmigo = async (idAmigo) => {
try {
Expand All @@ -42,7 +45,9 @@ const PageListFriends = () => {
"Authorization": localStorage.getItem("token")
}
})
window.location.reload()
// window.location.reload()
search(busqueda)
setReload(false)
} catch (error) {
console.error("No se pudo eliminar el amigo: ", error)
}
Expand Down Expand Up @@ -97,7 +102,9 @@ const PageListFriends = () => {
friend: idFriend
})
})
window.location.reload()
// window.location.reload()
search(busqueda)
setReload(false)
} catch (error) {
console.error("Error al añadir el amigo: ", error)
}
Expand All @@ -112,7 +119,9 @@ const PageListFriends = () => {
"Authorization": localStorage.getItem("token")
},
})
window.location.reload()
// window.location.reload()
search(busqueda)
setReload(false)
} catch (error) {
console.error("Error al añadir el amigo: ", error)
}
Expand All @@ -138,7 +147,10 @@ const PageListFriends = () => {
onChange={(e) => search(e.target.value)}
/>
</form>
{showFriends ?
{ reload ?
<>

{showFriends ?
<div className="list-friends">
{ friends.length === 0 ? (
<p style={{
Expand Down Expand Up @@ -166,14 +178,14 @@ const PageListFriends = () => {
</div>
:
<div className="list-friends">
{ searchResults.length === 0 ?
{ reload && searchResults.length === 0 ?
<p style={{
fontWeight: "bold",
marginLeft: "37%"}}>
No hay resultados para su búsqueda
</p>
:
searchResults.usersRequested && searchResults.usersRequested.map((friend, index) => {
reload && searchResults.usersRequested && searchResults.usersRequested.map((friend, index) => {
return(
<div className='user-not-friend' key={index}>
<div className="foto-friend">
Expand All @@ -191,7 +203,7 @@ const PageListFriends = () => {
</div>
)
})}
{searchResults.usersRequesting && searchResults.usersRequesting.map((friend, index) => {
{reload && searchResults.usersRequesting && searchResults.usersRequesting.map((friend, index) => {
return(
<div className='user-not-friend' key={index}>
<div className="foto-friend">
Expand All @@ -209,7 +221,7 @@ const PageListFriends = () => {
</div>
)
})}
{searchResults.users && searchResults.users.map((friend, index) => {
{reload && searchResults.users && searchResults.users.map((friend, index) => {
return(
<div className='user-not-friend' key={index}>
<div className="foto-friend">
Expand All @@ -228,9 +240,12 @@ const PageListFriends = () => {
)
})}
</div>
}

}</>
: null

}


</div>
</div>
</div>
Expand Down
13 changes: 9 additions & 4 deletions docker/web/src/Components/PageListRequests.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { NavLink } from "react-router-dom"

const PageListRequests = () => {

const [reload, setReload] = useState(true);

const[friends, setFriends] = useState([])
const getFriendList = async() => {
const request = await fetch(Global.url+'user/searchRequests', {
Expand All @@ -34,7 +36,8 @@ const PageListRequests = () => {

useEffect(() => {
getFriendList()
}, [])
setReload(true)
}, [reload])

const eliminarAmigo = async (idAmigo) => {
try {
Expand All @@ -45,7 +48,8 @@ const PageListRequests = () => {
"Authorization": localStorage.getItem("token")
}
})
window.location.reload()
// window.location.reload()
setReload(false)
} catch (error) {
console.error("No se pudo eliminar el amigo: ", error)
}
Expand All @@ -62,7 +66,8 @@ const PageListRequests = () => {
"Authorization": localStorage.getItem("token")
},
})
window.location.reload()
// window.location.reload()
setReload(false)
} catch (error) {
console.error("Error al añadir el amigo: ", error)
}
Expand All @@ -79,7 +84,7 @@ const PageListRequests = () => {
<div className="principal-list">

<div className="list-friends">
{ friends.usersRequesting && friends.usersRequesting.length > 0 ? (
{ reload && friends.usersRequesting && friends.usersRequesting.length > 0 ? (
friends.usersRequesting.map((friend, index) => {

return(
Expand Down
3 changes: 2 additions & 1 deletion docker/web/src/Components/PageRegister.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Button} from "@nextui-org/react";

const PageRegister = () => {


const [num, setNum] = useState(1)
const {form, changed} = useForm({})
const navigate = useNavigate()
Expand Down Expand Up @@ -164,7 +165,7 @@ const PageRegister = () => {
form={form}
changed={changed}/>

<NavLink to="/login"><Button style={{"margin":"8px"}} color="warning">Atras</Button></NavLink>
<Button onClick={()=> navigate("/login")} style={{"margin":"8px"}} color="warning">Atras</Button>
<Button color="warning" style={{"margin":"8px"}} onClick={() => from1to2()}>Siguiente</Button>
</div>

Expand Down
15 changes: 11 additions & 4 deletions docker/web/src/Components/PageShowTraining.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import { NavLink, useNavigate, useParams } from "react-router-dom"
import { Global } from "../helpers/Global"
import { useEffect, useState } from "react"
import ReactTimeAgo from "react-time-ago"
import useAuth from "../hooks/useAuth"



const PageShowTraining = () => {
const PageShowTraining = ({user}) => {
const navigate = useNavigate()
const params = useParams()
const id = params.id
const [sets, setSets] = useState([]);
const {auth} = useAuth()

const [name , setName] = useState("")
const date = new Date()
Expand Down Expand Up @@ -50,7 +52,6 @@ const PageShowTraining = () => {
setSets(data.training.sets)
setDuration(data.training.created_at)
setNick(data.training.user.nick)

}

const deleteTraining = async() =>{
Expand Down Expand Up @@ -86,8 +87,14 @@ const PageShowTraining = () => {
<label>@{nick}</label>
<ReactTimeAgo date={Date.parse(duration)} locale='es-ES' className='date-rectangle'/>
</div>
<button className="deleteButton" onClick={deleteTraining} style={style1}>Eliminar entrenamiento</button>
{eliminado === true ? <h1 style={style3}>ERROR: No se ha eliminado el entrenamiento</h1>: <h1></h1>}
{ auth.nick === nick ? (
<div className="deleteButtonPlace">
<button className="deleteButton" onClick={deleteTraining} style={style1}>Eliminar entrenamiento</button>
{eliminado === true ? <h1 style={style3}>ERROR: No se ha eliminado el entrenamiento</h1>: <h1></h1>}
</div>
) : (
null
)}
</div>

<div className="addTraining">
Expand Down
38 changes: 25 additions & 13 deletions docker/web/src/Components/PageStat.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


import React from 'react'
import React, { useEffect, useState } from 'react'
import "../css/PageStats.css"
import { NavLink } from 'react-router-dom'
import { useParams } from 'react-router-dom'
Expand All @@ -11,12 +11,16 @@ import Stat4 from './Stat4'
import Stat1 from './Stat1'
import Stat2 from './Stat2'
import Stat3 from './Stat3'
// import { useHistory } from 'react-router-dom';


const PageStat = () => {


// const history = useHistory();
const params = useParams()
const num = params.num
const [reload, setReload] = useState(true);


//const StatComponent = React.lazy(() => import(/* @vite-ignore */`./Stat${num}`));
const {auth} = useAuth()
Expand All @@ -38,7 +42,7 @@ const PageStat = () => {
if (valorInput.length >= 3) {
e.preventDefault();
}
//console.log(valorInput)

if(num==4){
if(e.target.name == "hours" && ((valorInput>2) || (valorInput == 2 && codigoTecla>52) || (valorInput.length >= 2))){
e.preventDefault()
Expand All @@ -53,10 +57,10 @@ const PageStat = () => {
const saveInfo = async(event) => {
event.preventDefault()
let value
//console.log(num)

if(num == 4){
value = parseInt(event.target.hours.value)*60+parseInt(event.target.minutes.value)
//console.log(value)

}else{
value = event.target.newMetrica.value;
if (parseInt(value, 10) > 999) {
Expand Down Expand Up @@ -90,8 +94,9 @@ const PageStat = () => {

})
const data = await request.json()
//console.log(data.status)
setTimeout(()=>{window.location.reload()}, 100)

// setTimeout(()=>{window.location.reload()}, 100) //cambiar y mirar con useEfect
setReload(false)
}

const eliminateLast = async() => {
Expand Down Expand Up @@ -119,22 +124,29 @@ const PageStat = () => {

})
const data = await request.json()
//console.log(data.status)
setTimeout(()=>{window.location.reload()}, 100)
}

// setTimeout(()=>{window.location.reload()}, 100)
// setTimeout(history.push(history.location.pathname), 100)
setReload(false)
}

useEffect(() => {

setReload(true)

}, [reload]);

return (
<div className={"page"}>
<NavLink to={-1}><ImCross size="35px" className='cancelar-stat' color='#fba92c'/></NavLink>

<div className='principal-stat1'>
<div className='stat1'>
<React.Suspense>
{num == 1 && <Stat1 />}
{num == 1 && reload && <Stat1 />}
{num == 2 && <Stat2 />}
{num == 3 && <Stat3 />}
{num == 4 && <Stat4 />}
{num == 4 && reload && <Stat4 />}
</React.Suspense>
</div>
{num == 1 &&
Expand All @@ -152,7 +164,7 @@ const PageStat = () => {
<form className='newMetrica' onSubmit={(e) => saveInfo(e)}>
<div className='time-hm-metrica'>
<input type='number' placeholder="horas" name="hours" min="0" max="24" onKeyDown={validarNumero} ></input>
<input type='number' placeholder="mins" name="minutes" min="1" max="60" onKeyDown={validarNumero} ></input>
<input type='number' placeholder="mins" name="minutes" min="0" max="60" onKeyDown={validarNumero} ></input>
</div>
<label>Objetivo: 8h</label>
<input type='submit' value="INTRODUCIR MÉTRICA"></input>
Expand Down
2 changes: 1 addition & 1 deletion docker/web/src/Components/Stat4.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const Stat4 = () => {
<div className="stat">
{ error ?
<div className="stat4">
<p style={{color: '#fba92c', fontWeight: 'bold'}}>Pinche para añadir nuevas estadísticas de su "Sueño" </p>
<p style={{color: '#fba92c', fontWeight: 'bold'}}>Pulse para añadir nuevas estadísticas de su "Sueño" </p>
</div>
:
<ReactApexChart className="stat4" options={state.options} series={state.series} type="radialBar" width="86%"/>
Expand Down
Loading

0 comments on commit 0b83672

Please sign in to comment.