Files
DocsGPT/frontend/src/preferences/preferenceSlice.ts
TaylorS15 dea949f772 Moved Doc type to selectDocsApi
Moved /api/docs.ts to /preference/selectDocsApi.ts
Added all source docs to redux
2023-02-20 14:22:11 -05:00

47 lines
1.3 KiB
TypeScript

import { createSlice } from '@reduxjs/toolkit';
import { Doc } from './selectDocsApi';
import store from '../store';
interface Preference {
apiKey: string;
selectedDocs: Doc | null;
sourceDocs: Doc[] | null;
}
const initialState: Preference = {
apiKey: '',
selectedDocs: null,
sourceDocs: null,
};
export const prefSlice = createSlice({
name: 'preference',
initialState,
reducers: {
setApiKey: (state, action) => {
state.apiKey = action.payload;
},
setSelectedDocs: (state, action) => {
state.selectedDocs = action.payload;
console.log('setSelectedDocs', state.selectedDocs);
},
setSourceDocs: (state, action) => {
state.sourceDocs = action.payload;
console.log('setSourceDocs', state.sourceDocs);
},
},
});
export const { setApiKey, setSelectedDocs, setSourceDocs } = prefSlice.actions;
export default prefSlice.reducer;
type RootState = ReturnType<typeof store.getState>;
export const selectApiKey = (state: RootState) => state.preference.apiKey;
export const selectApiKeyStatus = (state: RootState) =>
!!state.preference.apiKey;
export const selectSelectedDocsStatus = (state: RootState) =>
!!state.preference.selectedDocs;
export const selectSourceDocs = (state: RootState) =>
state.preference.sourceDocs;