Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Julien Jerphanion
Rex Dri
Commits
91250689
Commit
91250689
authored
Aug 23, 2018
by
Florent Chehab
Browse files
FetchedAt added
parent
430e4e66
Changes
4
Hide whitespace changes
Inline
Side-by-side
frontend/src/actions/universities.js
View file @
91250689
...
...
@@ -32,7 +32,8 @@ export function universitiesFetchDataSuccess(universities) {
return
{
type
:
UNIVERSITIES_FETCH_DATA_SUCCESS
,
universities
universities
,
universitiesFetchedAt
:
Date
.
now
()
};
}
...
...
frontend/src/components/UnivMap.js
View file @
91250689
...
...
@@ -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
))
};
};
...
...
frontend/src/reducers/index.js
View file @
91250689
import
{
combineReducers
}
from
'
redux
'
;
import
{
universities
,
universities
Fetched
,
universitiesHasError
,
universitiesIsLoading
,
universitiesInvalidated
...
...
@@ -8,7 +8,7 @@ import {
const
rootReducer
=
combineReducers
({
universities
,
universities
Fetched
,
universitiesHasError
,
universitiesIsLoading
,
universitiesInvalidated
...
...
frontend/src/reducers/universities.js
View file @
91250689
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
universities
Fetched
(
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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment