Commit 1ed7446d authored by Florent Chehab's avatar Florent Chehab

Saving and retreiving search ok

parent 985357c2
export const SAVE_MAIN_MAP_POSITION = 'SAVE_MAIN_MAP_POSITION'; export const SAVE_MAIN_MAP_POSITION = 'SAVE_MAIN_MAP_POSITION';
export const SAVE_SELECTED_UNIVERSITIES = 'SAVE_SELECTED_UNIVERSITIES'; export const SAVE_SELECTED_UNIVERSITIES = 'SAVE_SELECTED_UNIVERSITIES';
export const SAVE_SEARCH_CONFIG = 'SAVE_SEARCH_CONFIG';
import { import {
SAVE_SELECTED_UNIVERSITIES SAVE_SELECTED_UNIVERSITIES,
SAVE_SEARCH_CONFIG
} from "./action-types"; } from "./action-types";
...@@ -9,5 +10,11 @@ export function saveSelectedUniversities(new_selection) { ...@@ -9,5 +10,11 @@ export function saveSelectedUniversities(new_selection) {
type: SAVE_SELECTED_UNIVERSITIES, type: SAVE_SELECTED_UNIVERSITIES,
new_selection new_selection
}; };
}
export function saveSearchConfig(config) {
return {
type: SAVE_SEARCH_CONFIG,
config
};
} }
...@@ -58,10 +58,11 @@ renderSuggestion.propTypes = { ...@@ -58,10 +58,11 @@ renderSuggestion.propTypes = {
class DownshiftMultiple extends React.Component { class DownshiftMultiple extends React.Component {
state = { state = this.props.config;
inputValue: '',
selectedItems: [], componentDidMount() {
}; this.setState(this.props.config);
}
componentDidUpdate(prevProps, prevState, snapshot) { componentDidUpdate(prevProps, prevState, snapshot) {
if (this.state.selectedItems != prevState.selectedItems) { if (this.state.selectedItems != prevState.selectedItems) {
...@@ -69,6 +70,12 @@ class DownshiftMultiple extends React.Component { ...@@ -69,6 +70,12 @@ class DownshiftMultiple extends React.Component {
} }
} }
componentWillUnmount() {
if (this.props.onComponentUnmount) {
this.props.onComponentUnmount(this.state)
}
}
getSuggestions(value) { getSuggestions(value) {
const { options } = this.props; const { options } = this.props;
...@@ -208,7 +215,8 @@ DownshiftMultiple.defaultProps = { ...@@ -208,7 +215,8 @@ DownshiftMultiple.defaultProps = {
{ label: 'Item 4', id: 4 }, { label: 'Item 4', id: 4 },
], ],
field_label: "label", field_label: "label",
field_placeholder: "placeholder" field_placeholder: "placeholder",
config: { selectedItems: [], inputValue: '' }
}; };
const styles = theme => ({ const styles = theme => ({
......
...@@ -4,7 +4,7 @@ import DownshiftMultiple from './DownshiftMultiple'; ...@@ -4,7 +4,7 @@ import DownshiftMultiple from './DownshiftMultiple';
import MyComponent from '../MyComponent' import MyComponent from '../MyComponent'
import { connect } from "react-redux"; import { connect } from "react-redux";
import _ from 'underscore'; import _ from 'underscore';
import { saveSelectedUniversities } from '../../actions/selectedUniversities'; import { saveSelectedUniversities, saveSearchConfig } from '../../actions/search';
import { import {
universitiesFetchData, universitiesFetchData,
...@@ -14,16 +14,6 @@ import { ...@@ -14,16 +14,6 @@ import {
} from '../../generated/actions'; } from '../../generated/actions';
class Search extends MyComponent { class Search extends MyComponent {
constructor() {
super();
this.state = {
leaflet_instance: null
};
}
componentWillUnmount() {
}
joinCampus(campus) { joinCampus(campus) {
const { universities, countries, cities } = this.getAllFetchedData(); const { universities, countries, cities } = this.getAllFetchedData();
...@@ -34,6 +24,9 @@ class Search extends MyComponent { ...@@ -34,6 +24,9 @@ class Search extends MyComponent {
return res; return res;
} }
saveContriesFilterConfig(state) {
this.props.saveConfig({ contriesFilter: state })
}
// getUnivFromCampus(campus) { // getUnivFromCampus(campus) {
// const { universities } = this.props; // const { universities } = this.props;
// return universities[campus.univ] // return universities[campus.univ]
...@@ -80,7 +73,12 @@ class Search extends MyComponent { ...@@ -80,7 +73,12 @@ class Search extends MyComponent {
(c) => { return { id: c.iso_alpha2_code, label: c.name } }) (c) => { return { id: c.iso_alpha2_code, label: c.name } })
return ( 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) => { ...@@ -92,7 +90,8 @@ const mapStateToProps = (state) => {
universities: state.universities, universities: state.universities,
mainCampuses: state.mainCampuses, mainCampuses: state.mainCampuses,
cities: state.cities, cities: state.cities,
countries: state.countries countries: state.countries,
contriesFilterConfig: state.app.search.contriesFilter
}; };
}; };
...@@ -105,6 +104,7 @@ const mapDispatchToProps = (dispatch) => { ...@@ -105,6 +104,7 @@ const mapDispatchToProps = (dispatch) => {
countries: () => dispatch(countriesFetchData()) countries: () => dispatch(countriesFetchData())
}, },
saveSelection: (selectedUniversities) => dispatch(saveSelectedUniversities(selectedUniversities)), saveSelection: (selectedUniversities) => dispatch(saveSelectedUniversities(selectedUniversities)),
saveConfig: (config) => dispatch(saveSearchConfig(config))
}; };
}; };
......
...@@ -10,12 +10,14 @@ import { ...@@ -10,12 +10,14 @@ import {
citiesReducers, citiesReducers,
} from '../generated/combinedReducers'; } from '../generated/combinedReducers';
import { saveMainMapPosition } from './map' import { saveMainMapPosition } from './map';
import { saveSelectedUniversities } from './selectedUniversities' import { saveSelectedUniversities } from './search';
import { saveSearchConfig } from './search';
const appReducers = combineReducers({ const appReducers = combineReducers({
mainMap: saveMainMapPosition, mainMap: saveMainMapPosition,
selectedUniversities: saveSelectedUniversities selectedUniversities: saveSelectedUniversities,
search: saveSearchConfig,
}) })
const rootReducer = combineReducers({ const rootReducer = combineReducers({
......
import { SAVE_SELECTED_UNIVERSITIES } from '../actions/action-types' import { SAVE_SELECTED_UNIVERSITIES, SAVE_SEARCH_CONFIG } from '../actions/action-types'
export function saveSelectedUniversities(state = [], action) { export function saveSelectedUniversities(state = [], action) {
switch (action.type) { switch (action.type) {
...@@ -11,3 +11,14 @@ export function saveSelectedUniversities(state = [], action) { ...@@ -11,3 +11,14 @@ export function saveSelectedUniversities(state = [], action) {
return state; 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;
}
}
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