reorganizes the code, introduces preference slice

This commit is contained in:
ajaythapliyal
2023-02-18 00:58:04 +05:30
parent 350ccad077
commit cb50795ac1
14 changed files with 45 additions and 78 deletions

View File

@@ -1,48 +1,12 @@
import {
configureStore,
createSelector,
createSlice,
PayloadAction,
} from '@reduxjs/toolkit';
// import { configureStore, createSlice } from '@reduxjs/toolkit';
interface State {
isApiKeyModalOpen: boolean;
apiKey: string;
}
const initialState: State = {
isApiKeyModalOpen: false,
apiKey: '',
};
export const slice = createSlice({
name: 'app',
initialState,
reducers: {
toggleApiKeyModal: (state) => {
state.isApiKeyModalOpen = !state.isApiKeyModalOpen;
console.log('showApiKeyModal', state.isApiKeyModalOpen);
},
setApiKey: (state, action: PayloadAction<string>) => {
state.apiKey = action.payload;
console.log('setApiKey', action.payload);
},
},
});
export const { toggleApiKeyModal, setApiKey } = slice.actions;
import { configureStore } from '@reduxjs/toolkit';
import { prefSlice } from './preferences/preferenceSlice';
const store = configureStore({
reducer: {
app: slice.reducer,
preference: prefSlice.reducer,
},
});
type RootState = ReturnType<typeof store.getState>;
export const selectIsApiKeyModalOpen = (state: RootState) =>
state.app.isApiKeyModalOpen;
export const selectApiKey = (state: RootState) => state.app.apiKey;
export const selectApiKeyStatus = (state: RootState) => !!state.app.apiKey;
export default store;