From 6774868dfc7b5f067422afa7376fde55294f704f Mon Sep 17 00:00:00 2001 From: Kristoffer Juelsen Date: Thu, 7 Apr 2022 16:41:09 +0200 Subject: [PATCH] Date Picker functional --- src/client/src/TournamentCreator.js | 18 ++++++------- src/client/src/TournamentManager.js | 41 ++++++++++------------------- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/client/src/TournamentCreator.js b/src/client/src/TournamentCreator.js index 4acc3b5..850be68 100644 --- a/src/client/src/TournamentCreator.js +++ b/src/client/src/TournamentCreator.js @@ -75,12 +75,15 @@ function TournamentForm(props) { setMaxTeamsExponent(event.target.value); } + const [startTime, setStartTime] = React.useState([new Date(), null]); + const [endTime, setEndTime] = React.useState([new Date(), null]); + function submitTournament(event) { event.preventDefault(); console.log(maxTeamsExponent) let maxTeams = Math.pow(2, maxTeamsExponent); - let startTime = new Date(document.getElementById("startDatePicker").value).toUTCString(); - let endTime = new Date(document.getElementById("endDatePicker").value).toUTCString(); + let startTime = new Date(startTime).toUTCString(); + let endTime = new Date(endTime).toUTCString(); postTournament( props.showError, document.getElementById("nameInput").value, @@ -101,9 +104,6 @@ function TournamentForm(props) { { value: 7, label: "128",} ]; - const [startValue, setStartValue] = React.useState(new Date()); - const [endValue, setEndValue] = React.useState(new Date()); - return ( <>
@@ -121,9 +121,9 @@ function TournamentForm(props) { mask="____-__-__ __:__" format="yyyy-MM-dd HH:mm" inputFormat="yyyy-MM-dd HH:mm" - value={startValue} + value={startTime} onChange={(newValue) => { - setStartValue(newValue); + setStartTime(newValue); console.log(new Date(newValue).toUTCString()); }} renderInput={(params) => } @@ -137,9 +137,9 @@ function TournamentForm(props) { mask="____-__-__ __:__" format="yyyy-MM-dd HH:mm" inputFormat="yyyy-MM-dd HH:mm" - value={endValue} + value={endTime} onChange={(newValue) => { - setEndValue(newValue); + setEndTime(newValue); console.log(new Date(newValue).toUTCString()); }} renderInput={(params) => } diff --git a/src/client/src/TournamentManager.js b/src/client/src/TournamentManager.js index a249ce5..e7be1ef 100644 --- a/src/client/src/TournamentManager.js +++ b/src/client/src/TournamentManager.js @@ -101,7 +101,12 @@ let deleteTournament = tournamentId => event => { }) .catch((error) => showError(error)); } + function ManageTournament(props) { + + const [startTime, setStartTime] = React.useState([new Date(),null]); + const [endTime, setEndTime] = React.useState([new Date(),null]); + React.useEffect(() => { fetch( process.env.REACT_APP_API_URL + `/tournament/${props.tournamentId}` @@ -111,18 +116,14 @@ function ManageTournament(props) { if (data.status !== "OK") { showError(data.data); } + document.getElementById("editName").value = data.data.name; document.getElementById("editDesc").value = data.data.description; - document.getElementById("editStartDate").value = data.data.startTime.slice(0, 16); - document.getElementById("editEndDate").value = data.data.endTime.slice(0, 16); - console.log(data.data.endTime); - console.log(data.data.endTime.slice(0, 16)); + setStartTime(data.data.startTime.slice(0, 16)); + setEndTime(data.data.endTime.slice(0, 16)); }) .catch((err) => showError(err)); - }, []); - - const [startValue, setStartValue] = React.useState(); - const [endValue, setEndValue] = React.useState(); + }, [endTime, props.tournamentId, startTime]); return ( <> @@ -132,32 +133,18 @@ function ManageTournament(props) { - { - setStartValue(newValue); + setStartTime(newValue); console.log(new Date(newValue).toUTCString()); }} renderInput={(params) => } /> - { - setEndValue(newValue); + setEndTime(newValue); console.log(new Date(newValue).toUTCString()); }} renderInput={(params) => } @@ -169,7 +156,7 @@ function ManageTournament(props) { +