searchCity(state, action){
if (action.payload.length !== 0) {
let result = Object.entries(state.cities).filter(el => {
let isEmpty = Object.keys(el[1]).some(city => city.toLowerCase().includes(action.payload.toLowerCase().trimEnd()))
if (isEmpty) {
Object.values(el[1]).map(el => {
if (el.name.toLowerCase().includes(action.payload.toLowerCase().trimEnd())) {
el.isQueryItem = true
} else {
el.isQueryItem = false
}
})
return el
}
})
state.filter_cities = result.reduce((newObj, item) => {
newObj[item[0]] = item[1];
return newObj;
}, {});
} else {
let result = Object.entries(state.cities).filter(el => {
Object.values(el[1]).map(el => {
el.isQueryItem = false
})
return el
})
state.filter_cities = result.reduce((newObj, item) => {
newObj[item[0]] = item[1];
return newObj;
}, {});
}
}
},