WIP General Search.

This commit is contained in:
elforjani3
2020-04-13 21:30:26 +02:00
9 changed files with 99 additions and 86 deletions

View File

@@ -1,5 +1,19 @@
import t from 'store/types';
export function openSearch(result) {
return {
type: t.OPEN_SEARCH,
result,
};
}
export function closeSearch(result) {
return {
type: t.ClOSE_SEARCH,
result,
};
}
export function generalSearch(name, result) {
return {
type: t.SEARCH_SUCCESS,

View File

@@ -2,32 +2,14 @@ import t from 'store/types';
import { createReducer } from '@reduxjs/toolkit';
const initialState = {
searches: {},
searchTitle: 'Title',
isOpen: false,
};
export default createReducer(initialState, {
[t.SEARCH_SUCCESS]: (state, action) => {
const _result = {};
action.searches.forEach((search) => {
_result[search.id] = search;
});
state.searches = {
...state.searches,
..._result,
};
[t.OPEN_SEARCH]: (state, action) => {
state.isOpen = true;
},
[t.CLOSE_SEARCH]: (state, action) => {
state.isOpen = false;
},
});
// return state = action.result;
// if (typeof state === 'undefined') {
// return initialState;
// }
// state.search[action.name] = {
// isOpen: true,
// payload: action.payload || {},
// };

View File

@@ -1,5 +1,5 @@
export default {
SEARCH_SUCCESS: 'SEARCH_SUCCESS',
SEARCH_FAILURE: 'SEARCH_FAILURE',
SEARCH_REQUEST: 'SEARCH_REQUEST',
SEARCH_SUCCESS:'SEARCH_SUCCESS',
OPEN_SEARCH: 'OPEN_SEARCH',
CLOSE_SEARCH: 'CLOSE_SEARCH',
};