mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-18 08:14:06 +00:00
save further queries to localstorage
This commit is contained in:
1 parent
a0dd8f8e0f
commit
360d790282
3 files changed
+24
-23
No files matched your search
@@ -139,6 +139,7 @@ export const SharedConversation = () => {
|
|||||||
if (query.response) {
|
if (query.response) {
|
||||||
responseView = (
|
responseView = (
|
||||||
<ConversationBubble
|
<ConversationBubble
|
||||||
|
ref={endMessageRef}
|
||||||
className={`${index === queries.length - 1 ? 'mb-32' : 'mb-7'}`}
|
className={`${index === queries.length - 1 ? 'mb-32' : 'mb-7'}`}
|
||||||
key={`${index}ANSWER`}
|
key={`${index}ANSWER`}
|
||||||
message={query.response}
|
message={query.response}
|
||||||
@@ -148,6 +149,7 @@ export const SharedConversation = () => {
|
|||||||
} else if (query.error) {
|
} else if (query.error) {
|
||||||
responseView = (
|
responseView = (
|
||||||
<ConversationBubble
|
<ConversationBubble
|
||||||
|
ref={endMessageRef}
|
||||||
className={`${index === queries.length - 1 ? 'mb-32' : 'mb-7'} `}
|
className={`${index === queries.length - 1 ? 'mb-32' : 'mb-7'} `}
|
||||||
key={`${index}ERROR`}
|
key={`${index}ERROR`}
|
||||||
message={query.error}
|
message={query.error}
|
||||||
@@ -191,7 +193,7 @@ export const SharedConversation = () => {
|
|||||||
if (question === '') return;
|
if (question === '') return;
|
||||||
setEventInterrupt(false);
|
setEventInterrupt(false);
|
||||||
!isRetry && dispatch(addQuery({ prompt: question })); //dispatch only new queries
|
!isRetry && dispatch(addQuery({ prompt: question })); //dispatch only new queries
|
||||||
dispatch(fetchSharedAnswer({ question: '' }));
|
dispatch(fetchSharedAnswer({ question }));
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchQueries();
|
fetchQueries();
|
||||||
@@ -220,6 +222,7 @@ export const SharedConversation = () => {
|
|||||||
return (
|
return (
|
||||||
<Fragment key={index}>
|
<Fragment key={index}>
|
||||||
<ConversationBubble
|
<ConversationBubble
|
||||||
|
ref={endMessageRef}
|
||||||
className={'mb-1 last:mb-28 md:mb-7'}
|
className={'mb-1 last:mb-28 md:mb-7'}
|
||||||
key={`${index}QUESTION`}
|
key={`${index}QUESTION`}
|
||||||
message={query.prompt}
|
message={query.prompt}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const API_STREAMING = import.meta.env.VITE_API_STREAMING === 'true';
|
|||||||
interface SharedConversationsType {
|
interface SharedConversationsType {
|
||||||
queries: Query[];
|
queries: Query[];
|
||||||
apiKey?: string;
|
apiKey?: string;
|
||||||
identifier: string | null;
|
identifier: string;
|
||||||
status: Status;
|
status: Status;
|
||||||
date?: string;
|
date?: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
@@ -20,15 +20,15 @@ interface SharedConversationsType {
|
|||||||
|
|
||||||
const initialState: SharedConversationsType = {
|
const initialState: SharedConversationsType = {
|
||||||
queries: [],
|
queries: [],
|
||||||
identifier: null,
|
identifier: '',
|
||||||
status: 'idle',
|
status: 'idle',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchSharedAnswer = createAsyncThunk<Answer, { question: string }>(
|
export const fetchSharedAnswer = createAsyncThunk<Answer, { question: string }>(
|
||||||
'shared/fetchAnswer',
|
'shared/fetchAnswer',
|
||||||
async ({ question }, { dispatch, getState, signal }) => {
|
async ({ question }, { dispatch, getState, signal }) => {
|
||||||
console.log('bulaya sahab ji ?');
|
|
||||||
const state = getState() as RootState;
|
const state = getState() as RootState;
|
||||||
|
|
||||||
if (state.preference && state.sharedConversation.apiKey) {
|
if (state.preference && state.sharedConversation.apiKey) {
|
||||||
if (API_STREAMING) {
|
if (API_STREAMING) {
|
||||||
await handleFetchSharedAnswerStreaming(
|
await handleFetchSharedAnswerStreaming(
|
||||||
@@ -43,6 +43,7 @@ export const fetchSharedAnswer = createAsyncThunk<Answer, { question: string }>(
|
|||||||
if (data.type === 'end') {
|
if (data.type === 'end') {
|
||||||
// set status to 'idle'
|
// set status to 'idle'
|
||||||
dispatch(sharedConversationSlice.actions.setStatus('idle'));
|
dispatch(sharedConversationSlice.actions.setStatus('idle'));
|
||||||
|
dispatch(saveToLocalStorage());
|
||||||
} else if (data.type === 'error') {
|
} else if (data.type === 'error') {
|
||||||
// set status to 'failed'
|
// set status to 'failed'
|
||||||
dispatch(sharedConversationSlice.actions.setStatus('failed'));
|
dispatch(sharedConversationSlice.actions.setStatus('failed'));
|
||||||
@@ -137,24 +138,6 @@ export const sharedConversationSlice = createSlice({
|
|||||||
},
|
},
|
||||||
addQuery(state, action: PayloadAction<Query>) {
|
addQuery(state, action: PayloadAction<Query>) {
|
||||||
state.queries.push(action.payload);
|
state.queries.push(action.payload);
|
||||||
if (state.identifier) {
|
|
||||||
const previousQueriesStr = localStorage.getItem(state.identifier);
|
|
||||||
previousQueriesStr
|
|
||||||
? localStorage.setItem(
|
|
||||||
state.identifier,
|
|
||||||
JSON.stringify([
|
|
||||||
...JSON.parse(previousQueriesStr),
|
|
||||||
action.payload,
|
|
||||||
]),
|
|
||||||
)
|
|
||||||
: localStorage.setItem(
|
|
||||||
state.identifier,
|
|
||||||
JSON.stringify([action.payload]),
|
|
||||||
);
|
|
||||||
if (action.payload.prompt) {
|
|
||||||
fetchSharedAnswer({ question: action.payload.prompt });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
updateStreamingQuery(
|
updateStreamingQuery(
|
||||||
state,
|
state,
|
||||||
@@ -188,6 +171,21 @@ export const sharedConversationSlice = createSlice({
|
|||||||
const { index, message } = action.payload;
|
const { index, message } = action.payload;
|
||||||
state.queries[index].error = message;
|
state.queries[index].error = message;
|
||||||
},
|
},
|
||||||
|
saveToLocalStorage(state) {
|
||||||
|
const previousQueriesStr = localStorage.getItem(state.identifier);
|
||||||
|
previousQueriesStr
|
||||||
|
? localStorage.setItem(
|
||||||
|
state.identifier,
|
||||||
|
JSON.stringify([
|
||||||
|
...JSON.parse(previousQueriesStr),
|
||||||
|
state.queries[state.queries.length - 1],
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
: localStorage.setItem(
|
||||||
|
state.identifier,
|
||||||
|
JSON.stringify([state.queries[state.queries.length - 1]]),
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
extraReducers(builder) {
|
extraReducers(builder) {
|
||||||
builder
|
builder
|
||||||
@@ -214,6 +212,7 @@ export const {
|
|||||||
updateQuery,
|
updateQuery,
|
||||||
updateStreamingQuery,
|
updateStreamingQuery,
|
||||||
addQuery,
|
addQuery,
|
||||||
|
saveToLocalStorage,
|
||||||
} = sharedConversationSlice.actions;
|
} = sharedConversationSlice.actions;
|
||||||
|
|
||||||
export const selectStatus = (state: RootState) => state.conversation.status;
|
export const selectStatus = (state: RootState) => state.conversation.status;
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ export const ShareConversationModal = ({
|
|||||||
conversationService
|
conversationService
|
||||||
.shareConversation(isPromptable, payload)
|
.shareConversation(isPromptable, payload)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res.status);
|
|
||||||
return res.json();
|
return res.json();
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
|||||||
Reference in new issue
Block a user