You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1023 B
48 lines
1023 B
import {createSlice} from "@reduxjs/toolkit";
|
|
import {HYDRATE} from "next-redux-wrapper";
|
|
|
|
import {AppState} from "./store";
|
|
|
|
export interface BlogSearchState {
|
|
results: object[];
|
|
}
|
|
|
|
// Initial state
|
|
const initialState: BlogSearchState = {
|
|
results: [],
|
|
};
|
|
|
|
// Actual Slice
|
|
// @ts-ignore
|
|
export const blogSearchSlice = createSlice({
|
|
name: "blogSearch",
|
|
initialState,
|
|
reducers: {
|
|
|
|
// Action to set the authentication status
|
|
setBlogSearchState(state, action) {
|
|
// @ts-ignore
|
|
state.results = action.payload;
|
|
},
|
|
|
|
// Special reducer for hydrating the state. Special case for next-redux-wrapper
|
|
extraReducers: {
|
|
// @ts-ignore
|
|
[HYDRATE]: (state, action) => {
|
|
return {
|
|
...state,
|
|
// @ts-ignore
|
|
...action.payload.blogSearch,
|
|
};
|
|
},
|
|
},
|
|
|
|
},
|
|
});
|
|
|
|
export const {setBlogSearchState} = blogSearchSlice.actions;
|
|
|
|
export const selectBlogSearchState = (state: AppState) => state.blogSearch;
|
|
|
|
export default blogSearchSlice.reducer;
|