Skip to content
GitLab
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
1ed7446d
Commit
1ed7446d
authored
Sep 03, 2018
by
Florent Chehab
Browse files
Saving and retreiving search ok
parent
985357c2
Changes
6
Hide whitespace changes
Inline
Side-by-side
frontend/src/actions/action-types.js
View file @
1ed7446d
export
const
SAVE_MAIN_MAP_POSITION
=
'
SAVE_MAIN_MAP_POSITION
'
;
export
const
SAVE_SELECTED_UNIVERSITIES
=
'
SAVE_SELECTED_UNIVERSITIES
'
;
export
const
SAVE_SEARCH_CONFIG
=
'
SAVE_SEARCH_CONFIG
'
;
frontend/src/actions/se
lectedUniversities
.js
→
frontend/src/actions/se
arch
.js
View file @
1ed7446d
import
{
SAVE_SELECTED_UNIVERSITIES
SAVE_SELECTED_UNIVERSITIES
,
SAVE_SEARCH_CONFIG
}
from
"
./action-types
"
;
...
...
@@ -9,5 +10,11 @@ export function saveSelectedUniversities(new_selection) {
type
:
SAVE_SELECTED_UNIVERSITIES
,
new_selection
};
}
export
function
saveSearchConfig
(
config
)
{
return
{
type
:
SAVE_SEARCH_CONFIG
,
config
};
}
frontend/src/components/search/DownshiftMultiple.js
View file @
1ed7446d
...
...
@@ -58,10 +58,11 @@ renderSuggestion.propTypes = {
class
DownshiftMultiple
extends
React
.
Component
{
state
=
{
inputValue
:
''
,
selectedItems
:
[],
};
state
=
this
.
props
.
config
;
componentDidMount
()
{
this
.
setState
(
this
.
props
.
config
);
}
componentDidUpdate
(
prevProps
,
prevState
,
snapshot
)
{
if
(
this
.
state
.
selectedItems
!=
prevState
.
selectedItems
)
{
...
...
@@ -69,6 +70,12 @@ class DownshiftMultiple extends React.Component {
}
}
componentWillUnmount
()
{
if
(
this
.
props
.
onComponentUnmount
)
{
this
.
props
.
onComponentUnmount
(
this
.
state
)
}
}
getSuggestions
(
value
)
{
const
{
options
}
=
this
.
props
;
...
...
@@ -208,7 +215,8 @@ DownshiftMultiple.defaultProps = {
{
label
:
'
Item 4
'
,
id
:
4
},
],
field_label
:
"
label
"
,
field_placeholder
:
"
placeholder
"
field_placeholder
:
"
placeholder
"
,
config
:
{
selectedItems
:
[],
inputValue
:
''
}
};
const
styles
=
theme
=>
({
...
...
frontend/src/components/search/Search.js
View file @
1ed7446d
...
...
@@ -4,7 +4,7 @@ import DownshiftMultiple from './DownshiftMultiple';
import
MyComponent
from
'
../MyComponent
'
import
{
connect
}
from
"
react-redux
"
;
import
_
from
'
underscore
'
;
import
{
saveSelectedUniversities
}
from
'
../../actions/se
lectedUniversities
'
;
import
{
saveSelectedUniversities
,
saveSearchConfig
}
from
'
../../actions/se
arch
'
;
import
{
universitiesFetchData
,
...
...
@@ -14,16 +14,6 @@ import {
}
from
'
../../generated/actions
'
;
class
Search
extends
MyComponent
{
constructor
()
{
super
();
this
.
state
=
{
leaflet_instance
:
null
};
}
componentWillUnmount
()
{
}
joinCampus
(
campus
)
{
const
{
universities
,
countries
,
cities
}
=
this
.
getAllFetchedData
();
...
...
@@ -34,6 +24,9 @@ class Search extends MyComponent {
return
res
;
}
saveContriesFilterConfig
(
state
)
{
this
.
props
.
saveConfig
({
contriesFilter
:
state
})
}
// getUnivFromCampus(campus) {
// const { universities } = this.props;
// return universities[campus.univ]
...
...
@@ -80,7 +73,12 @@ class Search extends MyComponent {
(
c
)
=>
{
return
{
id
:
c
.
iso_alpha2_code
,
label
:
c
.
name
}
})
return
(
<
DownshiftMultiple
options
=
{
options
}
onChange
=
{(
selection
)
=>
this
.
updateSelectedUniversities
(
selection
)}
/
>
<
DownshiftMultiple
options
=
{
options
}
onChange
=
{(
selection
)
=>
this
.
updateSelectedUniversities
(
selection
)}
onComponentUnmount
=
{(
state
)
=>
this
.
saveContriesFilterConfig
(
state
)}
config
=
{
this
.
props
.
contriesFilterConfig
}
/
>
);
}
}
...
...
@@ -92,7 +90,8 @@ const mapStateToProps = (state) => {
universities
:
state
.
universities
,
mainCampuses
:
state
.
mainCampuses
,
cities
:
state
.
cities
,
countries
:
state
.
countries
countries
:
state
.
countries
,
contriesFilterConfig
:
state
.
app
.
search
.
contriesFilter
};
};
...
...
@@ -105,6 +104,7 @@ const mapDispatchToProps = (dispatch) => {
countries
:
()
=>
dispatch
(
countriesFetchData
())
},
saveSelection
:
(
selectedUniversities
)
=>
dispatch
(
saveSelectedUniversities
(
selectedUniversities
)),
saveConfig
:
(
config
)
=>
dispatch
(
saveSearchConfig
(
config
))
};
};
...
...
frontend/src/reducers/index.js
View file @
1ed7446d
...
...
@@ -10,12 +10,14 @@ import {
citiesReducers
,
}
from
'
../generated/combinedReducers
'
;
import
{
saveMainMapPosition
}
from
'
./map
'
import
{
saveSelectedUniversities
}
from
'
./selectedUniversities
'
import
{
saveMainMapPosition
}
from
'
./map
'
;
import
{
saveSelectedUniversities
}
from
'
./search
'
;
import
{
saveSearchConfig
}
from
'
./search
'
;
const
appReducers
=
combineReducers
({
mainMap
:
saveMainMapPosition
,
selectedUniversities
:
saveSelectedUniversities
selectedUniversities
:
saveSelectedUniversities
,
search
:
saveSearchConfig
,
})
const
rootReducer
=
combineReducers
({
...
...
frontend/src/reducers/se
lectedUniversities
.js
→
frontend/src/reducers/se
arch
.js
View file @
1ed7446d
import
{
SAVE_SELECTED_UNIVERSITIES
}
from
'
../actions/action-types
'
import
{
SAVE_SELECTED_UNIVERSITIES
,
SAVE_SEARCH_CONFIG
}
from
'
../actions/action-types
'
export
function
saveSelectedUniversities
(
state
=
[],
action
)
{
switch
(
action
.
type
)
{
...
...
@@ -11,3 +11,14 @@ export function saveSelectedUniversities(state = [], action) {
return
state
;
}
}
export
function
saveSearchConfig
(
state
=
{
contriesFilter
:
{
selectedItems
:
[],
inputValue
:
''
}
},
action
)
{
switch
(
action
.
type
)
{
case
SAVE_SEARCH_CONFIG
:
return
Object
.
assign
(
state
,
action
.
config
)
default
:
return
state
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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