Skip to content

Commit

Permalink
Merge pull request #791 from arc53/bug/sticky-prompts
Browse files Browse the repository at this point in the history
Add getLocalPrompt and setLocalPrompt functions to preferenceApi.ts
  • Loading branch information
dartpain authored Dec 4, 2023
2 parents 453e507 + f8f60c6 commit 1a78a6f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions frontend/src/preferences/preferenceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,19 @@ export function getLocalRecentDocs(): string | null {
return doc;
}

export function getLocalPrompt(): string | null {
const prompt = localStorage.getItem('DocsGPTPrompt');
return prompt;
}

export function setLocalApiKey(key: string): void {
localStorage.setItem('DocsGPTApiKey', key);
}

export function setLocalPrompt(prompt: string): void {
localStorage.setItem('DocsGPTPrompt', prompt);
}

export function setLocalRecentDocs(doc: Doc): void {
localStorage.setItem('DocsGPTRecentDocs', JSON.stringify(doc));
let namePath = doc.name;
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/preferences/preferenceSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ prefListenerMiddleware.startListening({
},
});

prefListenerMiddleware.startListening({
matcher: isAnyOf(setPrompt),
effect: (action, listenerApi) => {
localStorage.setItem(
'DocsGPTPrompt',
JSON.stringify((listenerApi.getState() as RootState).preference.prompt),
);
},
});

export const selectApiKey = (state: RootState) => state.preference.apiKey;
export const selectApiKeyStatus = (state: RootState) =>
!!state.preference.apiKey;
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import {
} from './preferences/preferenceSlice';

const key = localStorage.getItem('DocsGPTApiKey');
const prompt = localStorage.getItem('DocsGPTPrompt');
const doc = localStorage.getItem('DocsGPTRecentDocs');

const store = configureStore({
preloadedState: {
preference: {
apiKey: key ?? '',
selectedDocs: doc !== null ? JSON.parse(doc) : null,
prompt: { name: 'default', id: 'default', type: 'private' },
prompt:
prompt !== null
? JSON.parse(prompt)
: { name: 'default', id: 'default', type: 'private' },
conversations: null,
sourceDocs: [
{
Expand Down

2 comments on commit 1a78a6f

@vercel
Copy link

@vercel vercel bot commented on 1a78a6f Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs-gpt – ./frontend

docs-gpt-brown.vercel.app
docs-gpt-arc53.vercel.app
docs-gpt-git-main-arc53.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 1a78a6f Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nextra-docsgpt – ./docs

nextra-docsgpt.vercel.app
nextra-docsgpt-arc53.vercel.app
nextra-docsgpt-git-main-arc53.vercel.app
docs.docsgpt.co.uk

Please sign in to comment.