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