Commit 91250689 authored by Florent Chehab's avatar Florent Chehab
Browse files

FetchedAt added

parent 430e4e66
Pipeline #26478 failed with stages
in 1 minute and 26 seconds
......@@ -32,7 +32,8 @@ export function universitiesFetchDataSuccess(universities) {
return {
type: UNIVERSITIES_FETCH_DATA_SUCCESS,
universities
universities,
universitiesFetchedAt: Date.now()
};
}
......
......@@ -2,7 +2,10 @@ import React, { Component } from 'react';
import { connect } from "react-redux";
import { Map, TileLayer, Marker, Popup, LayersControl, FeatureGroup, Circle, LayerGroup } from 'react-leaflet';
// import MarkerClusterGroup from 'react-leaflet-markercluster';
import { universitiesFetchData } from '../actions/universities';
import {
universitiesFetchData,
universitiesInvalidated
} from '../actions/universities';
class UnivMap extends Component {
......@@ -11,6 +14,8 @@ class UnivMap extends Component {
}
componentDidUpdate(){
// TODO ajouter expire date
if (this.props.invalidated){
this.props.fetchData('http://127.0.0.1:8000/api/university');
}
......@@ -81,8 +86,10 @@ class UnivMap extends Component {
const mapStateToProps = (state) => {
console.log("ici", state)
return {
universities: state.universities,
universities: state.universitiesFetched.universities,
fetchedAt: state.universitiesFetched.fetchedAt,
hasError: state.universitiesHasError,
isLoading: state.universitiesIsLoading,
invalidated: state.universitiesInvalidated
......@@ -91,7 +98,8 @@ const mapStateToProps = (state) => {
const mapDispatchToProps = (dispatch) => {
return {
fetchData: (url) => dispatch(universitiesFetchData(url))
fetchData: (url) => dispatch(universitiesFetchData(url)),
invalidate: () => dispatch(universitiesInvalidated(true))
};
};
......
import { combineReducers } from 'redux';
import {
universities,
universitiesFetched,
universitiesHasError,
universitiesIsLoading,
universitiesInvalidated
......@@ -8,7 +8,7 @@ import {
const rootReducer = combineReducers({
universities,
universitiesFetched,
universitiesHasError,
universitiesIsLoading,
universitiesInvalidated
......
import {
UNIVERSITIES_HAS_ERROR,
UNIVERSITIES_IS_LOADING,
UNIVERSITIES_HAS_ERROR,
UNIVERSITIES_IS_LOADING,
UNIVERSITIES_FETCH_DATA_SUCCESS,
UNIVERSITIES_INVALIDATED
} from "../constants/action-types";
......@@ -36,10 +36,14 @@ export function universitiesInvalidated(state = false, action) {
}
}
export function universities(state = [], action) {
export function universitiesFetched(state = { universities: [], universitiesFetchedAt: null }, action) {
switch (action.type) {
case UNIVERSITIES_FETCH_DATA_SUCCESS:
return action.universities;
return {
universities: action.universities,
fetchedAt: action.universitiesFetchedAt
}
default:
return 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