Commit 7f0bff54 authored by Jiawen Lyu's avatar Jiawen Lyu

add extractUvDateInfo

parent 22a11aaa
import React, { Component } from "react"; import React, { Component } from "react";
import Scheduler from "./components/Scheduler"; import Scheduler from "./components/Scheduler";
import Toolbar from "./components/Toolbar"; // import Toolbar from "./components/Toolbar";
import MessageArea from "./components/MessageArea"; import MessageArea from "./components/MessageArea";
import "./App.css"; import "./App.css";
...@@ -10,26 +10,43 @@ const data = [ ...@@ -10,26 +10,43 @@ const data = [
start_date: "2020-06-10 6:00", start_date: "2020-06-10 6:00",
end_date: "2020-06-10 8:00", end_date: "2020-06-10 8:00",
text: "C SR03", text: "C SR03",
id: 1, id: 1
}, },
{ {
start_date: "2020-06-10 8:15", start_date: "2020-06-10 8:15",
end_date: "2020-06-10 10:15", end_date: "2020-06-10 10:15",
text: "TD SR03", text: "TD SR03",
id: 2, id: 2
}, },
{ {
start_date: "2020-06-13 10:00", start_date: "2020-06-13 10:00",
end_date: "2020-06-13 18:00", end_date: "2020-06-13 18:00",
text: "Event 2", text: "Event 2",
id: 3, id: 3
}, },
]; ];
const semestreP20 = {
start_date: "2020-02-24",
end_date: "2020-06-27"
}
const extractUvDateInfo = uvs => uvs.map(uv => ({
start_date: uv.begin,
end_date: uv.end,
day: uv.day,
text: uv.uv,
id: uvs.indexOf(uv)
}))
class App extends Component { class App extends Component {
state = { state = {
currentTimeFormatState: true, currentTimeFormatState: true,
messages: [], messages: [],
error: null,
isLoaded: false,
uvs: []
}; };
addMessage(message) { addMessage(message) {
const maxLogLength = 5; const maxLogLength = 5;
...@@ -48,20 +65,48 @@ class App extends Component { ...@@ -48,20 +65,48 @@ class App extends Component {
this.addMessage(message); this.addMessage(message);
}; };
componentDidMount() {
fetch('https://cors-anywhere.herokuapp.com/https://webapplis.utc.fr/Edt_ent_rest/myedt/result/?login=jbarthel')
.then(res => res.json())
.then(
(result) => {
this.setState({
isLoaded: true,
uvs: result
});
},
// Remarque : il est important de traiter les erreurs ici
// au lieu d'utiliser un bloc catch(), pour ne pas passer à la trappe
// des exceptions provenant de réels bugs du composant.
(error) => {
this.setState({
isLoaded: true,
error
});
}
)
}
render() { render() {
const { currentTimeFormatState, messages } = this.state; const { currentTimeFormatState, messages, error, isLoaded, uvs } = this.state;
return ( const data = extractUvDateInfo(uvs)
<div> if (error) {
<div className="scheduler-container"> return <div>Erreur : {error.message}</div>;
<Scheduler } else if (!isLoaded) {
events={data} return <div>Chargement</div>;
timeFormatState={currentTimeFormatState} } else {
onDataUpdated={this.logDataUpdate} return (
/> <div>
</div> <div className="scheduler-container">
<MessageArea messages={messages} /> <Scheduler
</div> events={data}
); timeFormatState={currentTimeFormatState}
onDataUpdated={this.logDataUpdate}
/>
</div>
<MessageArea messages={messages} />
</div >
);
}
} }
} }
export default App; export default App;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment