Commit 1c36a574 authored by Jiawen Lyu's avatar Jiawen Lyu

componentdidupdate

parent db14fca6
......@@ -18,7 +18,7 @@ class App extends Component {
super(props)
const storage = new LocalStorageManager()
storage.set("logins", ["lyujiawe", "jbarthel"])
storage.set("logins", ["lyujiawe", "jbarthel", "yuruoshu"])
let logins = storage.logins()
......
import React from 'react'
export default WrappedComponent => {
return class extends React.Component {
constructor(props) {
......@@ -10,7 +13,8 @@ export default WrappedComponent => {
data: []
};
}
componentDidMount() {
handleFetchPromises = () => {
const fetchPromises = this.props.logins.map(login => {
return fetch(`https://webapplis.utc.fr/Edt_ent_rest/myedt/result/?login=${login}`)
.then(res => res.json())
......@@ -26,7 +30,6 @@ export default WrappedComponent => {
(results) => {
let allDatas = []
results.map(result => result.map(elem => allDatas.push(elem)))
console.log(results[0])
this.setState({
data: allDatas,
isLoaded: true
......@@ -41,6 +44,15 @@ export default WrappedComponent => {
)
}
componentDidMount() {
this.handleFetchPromises()
}
componentDidUpdate(prevProps) {
if (prevProps.logins !== this.props.logins) {
this.handleFetchPromises();
}
}
render() {
const { error, isLoaded, data, login } = this.state
......
......@@ -103,7 +103,6 @@ const extractUvDateInfo = (uvs) => {
const withUVs = WrappedComponent => props => {
const { data } = props;
const uvs = extractUvDateInfo(data)
console.log("data: ", data)
console.log("uvs: ", uvs)
return <WrappedComponent events={uvs} {...props} />;
......
......@@ -68,6 +68,7 @@ export default class Scheduler extends Component {
this.initSchedulerEvents();
const { events, logins } = this.props;
console.log("logins in scheduler:", logins)
scheduler.init(this.schedulerContainer, new Date(2020, 5, 10));
scheduler.clearAll();
scheduler.parse(events);
......@@ -78,8 +79,10 @@ export default class Scheduler extends Component {
return this.props.timeFormatState !== nextProps.timeFormatState;
}
componentDidUpdate() {
scheduler.render();
componentDidUpdate(prevProps) {
if (prevProps.logins !== this.props.logins) {
scheduler.render();
}
}
setTimeFormat(state) {
......
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