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

Saving and retreiving search ok

parent 985357c2
Pipeline #26888 passed with stages
in 2 minutes and 23 seconds
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';
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
};
}
......@@ -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 => ({
......
......@@ -4,7 +4,7 @@ import DownshiftMultiple from './DownshiftMultiple';
import MyComponent from '../MyComponent'
import { connect } from "react-redux";
import _ from 'underscore';
import { saveSelectedUniversities } from '../../actions/selectedUniversities';
import { saveSelectedUniversities, saveSearchConfig } from '../../actions/search';
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))
};
};
......
......@@ -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({
......
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;
}
}
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