LibreChat/client/src/store/searchSlice.js

32 lines
662 B
JavaScript
Raw Normal View History

import { createSlice } from '@reduxjs/toolkit';
const initialState = {
2023-03-21 19:31:57 -04:00
searchEnabled: false,
search: false,
query: '',
};
const currentSlice = createSlice({
name: 'search',
initialState,
reducers: {
setSearchState: (state, action) => {
2023-03-21 19:31:57 -04:00
state.searchEnabled = action.payload;
},
setQuery: (state, action) => {
const q = action.payload;
state.query = q;
if (q === '') {
state.search = false;
} else if (q?.length > 0 && !state.search) {
state.search = true;
}
},
}
});
export const { setSearchState, setQuery } = currentSlice.actions;
export default currentSlice.reducer;