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
Rex Dri
Rex Dri
Commits
430e4e66
Commit
430e4e66
authored
Aug 23, 2018
by
Florent Chehab
Browse files
Invalidated data added
parent
6aa128a8
Changes
5
Hide whitespace changes
Inline
Side-by-side
frontend/src/actions/universities.js
View file @
430e4e66
import
{
UNIVERSITIES_HAS_ERROR
,
UNIVERSITIES_IS_LOADING
,
UNIVERSITIES_FETCH_DATA_SUCCESS
}
from
"
../constants/action-types
"
;
import
{
UNIVERSITIES_HAS_ERROR
,
UNIVERSITIES_IS_LOADING
,
UNIVERSITIES_FETCH_DATA_SUCCESS
,
UNIVERSITIES_INVALIDATED
}
from
"
../constants/action-types
"
;
export
function
universitiesHasError
(
bool
)
{
return
{
...
...
@@ -14,7 +20,16 @@ export function universitiesIsLoading(bool) {
};
}
export
function
universitiesInvalidated
(
bool
)
{
return
{
type
:
UNIVERSITIES_INVALIDATED
,
invalidated
:
bool
};
}
export
function
universitiesFetchDataSuccess
(
universities
)
{
universitiesInvalidated
(
false
)
return
{
type
:
UNIVERSITIES_FETCH_DATA_SUCCESS
,
universities
...
...
@@ -37,7 +52,10 @@ export function universitiesFetchData(url) {
return
response
;
})
.
then
((
response
)
=>
response
.
json
())
.
then
((
universities
)
=>
dispatch
(
universitiesFetchDataSuccess
(
universities
)))
.
then
((
universities
)
=>
{
dispatch
(
universitiesInvalidated
(
false
));
dispatch
(
universitiesFetchDataSuccess
(
universities
));
})
.
catch
(()
=>
dispatch
(
universitiesHasError
(
true
)));
};
}
\ No newline at end of file
frontend/src/components/UnivMap.js
View file @
430e4e66
...
...
@@ -10,12 +10,18 @@ class UnivMap extends Component {
this
.
props
.
fetchData
(
'
http://127.0.0.1:8000/api/university
'
);
}
componentDidUpdate
(){
if
(
this
.
props
.
invalidated
){
this
.
props
.
fetchData
(
'
http://127.0.0.1:8000/api/university
'
);
}
}
render
()
{
if
(
this
.
props
.
hasError
)
{
return
<
p
>
Sorry
!
There
was
an
error
loading
the
items
<
/p>
;
}
if
(
this
.
props
.
isLoading
)
{
if
(
this
.
props
.
isLoading
||
this
.
props
.
invalidated
)
{
return
<
p
>
Loading
…
<
/p>
;
}
...
...
@@ -67,8 +73,6 @@ class UnivMap extends Component {
<
/Marker
>
))
}
<
/Map
>
);
...
...
@@ -80,7 +84,8 @@ const mapStateToProps = (state) => {
return
{
universities
:
state
.
universities
,
hasError
:
state
.
universitiesHasError
,
isLoading
:
state
.
universitiesIsLoading
isLoading
:
state
.
universitiesIsLoading
,
invalidated
:
state
.
universitiesInvalidated
};
};
...
...
frontend/src/constants/action-types.js
View file @
430e4e66
export
const
UNIVERSITIES_HAS_ERROR
=
'
UNIVERSITIES_HAS_ERROR
'
export
const
UNIVERSITIES_IS_LOADING
=
'
UNIVERSITIES_IS_LOADING
'
export
const
UNIVERSITIES_FETCH_DATA_SUCCESS
=
'
UNIVERSITIES_FETCH_DATA_SUCCESS
'
export
const
UNIVERSITIES_INVALIDATED
=
'
UNIVERSITIES_INVALIDATED
'
frontend/src/reducers/index.js
View file @
430e4e66
import
{
combineReducers
}
from
'
redux
'
;
import
{
universities
,
universitiesHasError
,
universitiesIsLoading
}
from
'
./universities
'
;
import
{
universities
,
universitiesHasError
,
universitiesIsLoading
,
universitiesInvalidated
}
from
'
./universities
'
;
const
rootReducer
=
combineReducers
({
universities
,
universitiesHasError
,
universitiesIsLoading
universitiesIsLoading
,
universitiesInvalidated
})
export
default
rootReducer
...
...
frontend/src/reducers/universities.js
View file @
430e4e66
import
{
UNIVERSITIES_HAS_ERROR
,
UNIVERSITIES_IS_LOADING
,
UNIVERSITIES_FETCH_DATA_SUCCESS
}
from
"
../constants/action-types
"
;
import
{
UNIVERSITIES_HAS_ERROR
,
UNIVERSITIES_IS_LOADING
,
UNIVERSITIES_FETCH_DATA_SUCCESS
,
UNIVERSITIES_INVALIDATED
}
from
"
../constants/action-types
"
;
export
function
universitiesHasError
(
state
=
false
,
action
)
{
...
...
@@ -21,6 +26,16 @@ export function universitiesIsLoading(state = false, action) {
}
}
export
function
universitiesInvalidated
(
state
=
false
,
action
)
{
switch
(
action
.
type
)
{
case
UNIVERSITIES_INVALIDATED
:
return
action
.
invalidated
;
default
:
return
state
;
}
}
export
function
universities
(
state
=
[],
action
)
{
switch
(
action
.
type
)
{
case
UNIVERSITIES_FETCH_DATA_SUCCESS
:
...
...
Write
Preview
Supports
Markdown
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