starchat-ui / utils /app /prompts.ts
matthoffner's picture
Duplicate from matthoffner/chatbot
13095e0
raw
history blame
482 Bytes
import { Prompt } from '@/types/prompt';
export const updatePrompt = (updatedPrompt: Prompt, allPrompts: Prompt[]) => {
const updatedPrompts = allPrompts.map((c) => {
if (c.id === updatedPrompt.id) {
return updatedPrompt;
}
return c;
});
savePrompts(updatedPrompts);
return {
single: updatedPrompt,
all: updatedPrompts,
};
};
export const savePrompts = (prompts: Prompt[]) => {
localStorage.setItem('prompts', JSON.stringify(prompts));
};