(shared conv) centralised into redux state

This commit is contained in:
ManishMadan2882
2024-07-26 15:19:38 +05:30
parent 052669a0b0
commit 8276b6c9a9
3 changed files with 105 additions and 21 deletions

View File

@@ -0,0 +1,66 @@
import { createSlice } from '@reduxjs/toolkit';
import type { PayloadAction } from '@reduxjs/toolkit';
import store from '../store';
import { Query, Status } from '../conversation/conversationModels';
interface SharedConversationsType {
queries: Query[];
apiKey?: string;
identifier: string | null;
status: Status;
date?: string;
title?: string;
}
const initialState: SharedConversationsType = {
queries: [],
identifier: null,
status: 'idle',
};
export const sharedConversationSlice = createSlice({
name: 'sharedConversation',
initialState,
reducers: {
setStatus(state, action: PayloadAction<Status>) {
state.status = action.payload;
},
setIdentifier(state, action: PayloadAction<string>) {
state.identifier = action.payload;
},
setFetchedData(
state,
action: PayloadAction<{
queries: Query[];
title: string;
date: string;
identifier: string;
}>,
) {
const { queries, title, identifier, date } = action.payload;
state.queries = queries;
state.title = title;
state.date = date;
state.identifier = identifier;
},
setClientApiKey(state, action: PayloadAction<string>) {
state.apiKey = action.payload;
},
},
});
export const { setStatus, setIdentifier, setFetchedData, setClientApiKey } =
sharedConversationSlice.actions;
export const selectStatus = (state: RootState) => state.conversation.status;
export const selectClientAPIKey = (state: RootState) =>
state.sharedConversation.apiKey;
export const selectQueries = (state: RootState) =>
state.sharedConversation.queries;
export const selectTitle = (state: RootState) => state.sharedConversation.title;
export const selectDate = (state: RootState) => state.sharedConversation.date;
type RootState = ReturnType<typeof store.getState>;
sharedConversationSlice;
export default sharedConversationSlice.reducer;