Skip to content

Commit a655ab0

Browse files
committed
feat: remove folders & prompts utils
1 parent 9bc91da commit a655ab0

File tree

11 files changed

+39
-232
lines changed

11 files changed

+39
-232
lines changed

src/components/Chat/Chat.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
2727

2828
const [currentMessage, setCurrentMessage] = useState<Message>()
2929
const [autoScrollEnabled, setAutoScrollEnabled] = useState<boolean>(true)
30-
const [showSettings, setShowSettings] = useState<boolean>(false)
3130
const [showScrollDownButton, setShowScrollDownButton] =
3231
useState<boolean>(false)
3332

@@ -246,22 +245,6 @@ QuickSort is an efficient, in-place sorting algorithm that, in practice, outperf
246245
})
247246
}
248247

249-
const handleSettings = () => {
250-
setShowSettings(!showSettings)
251-
}
252-
253-
const onClearAll = () => {
254-
if (
255-
confirm('Are you sure you want to clear all messages?') &&
256-
selectedConversation
257-
) {
258-
handleUpdateConversation(selectedConversation, {
259-
key: 'messages',
260-
value: [],
261-
})
262-
}
263-
}
264-
265248
const scrollDown = () => {
266249
if (autoScrollEnabled) {
267250
messagesEndRef.current?.scrollIntoView(true)

src/components/ReactStreamChat/index.tsx

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ import {
1010
saveConversations,
1111
updateConversation,
1212
} from '@/utils/app/conversation'
13-
import { saveFolders } from '@/utils/app/folders'
14-
import { savePrompts } from '@/utils/app/prompts'
15-
import { getSettings } from '@/utils/app/settings'
1613
import { Conversation } from '@/types/chat'
1714
import { KeyValuePair } from '@/types/data'
18-
import { FolderInterface, FolderType } from '@/types/folder'
1915
import { OpenAIModelID, OpenAIModels } from '@/types/openai'
20-
import { Prompt } from '@/types/prompt'
2116
import { Chat } from '@/components/Chat/Chat'
2217
import { ReactStreamChatContext } from './context'
2318
import { ReactStreamChatInitialState, initialState } from './state'
@@ -46,72 +41,6 @@ export const ReactStreamChat = () => {
4641
saveConversation(conversation)
4742
}
4843

49-
// FOLDER OPERATIONS --------------------------------------------
50-
51-
const handleCreateFolder = (name: string, type: FolderType) => {
52-
const newFolder: FolderInterface = {
53-
id: uuidv4(),
54-
name,
55-
type,
56-
}
57-
58-
const updatedFolders = [...folders, newFolder]
59-
60-
dispatch({ field: 'folders', value: updatedFolders })
61-
saveFolders(updatedFolders)
62-
}
63-
64-
const handleDeleteFolder = (folderId: string) => {
65-
const updatedFolders = folders.filter((f) => f.id !== folderId)
66-
dispatch({ field: 'folders', value: updatedFolders })
67-
saveFolders(updatedFolders)
68-
69-
const updatedConversations: Conversation[] = conversations.map((c) => {
70-
if (c.folderId === folderId) {
71-
return {
72-
...c,
73-
folderId: null,
74-
}
75-
}
76-
77-
return c
78-
})
79-
80-
dispatch({ field: 'conversations', value: updatedConversations })
81-
saveConversations(updatedConversations)
82-
83-
const updatedPrompts: Prompt[] = prompts.map((p) => {
84-
if (p.folderId === folderId) {
85-
return {
86-
...p,
87-
folderId: null,
88-
}
89-
}
90-
91-
return p
92-
})
93-
94-
dispatch({ field: 'prompts', value: updatedPrompts })
95-
savePrompts(updatedPrompts)
96-
}
97-
98-
const handleUpdateFolder = (folderId: string, name: string) => {
99-
const updatedFolders = folders.map((f) => {
100-
if (f.id === folderId) {
101-
return {
102-
...f,
103-
name,
104-
}
105-
}
106-
107-
return f
108-
})
109-
110-
dispatch({ field: 'folders', value: updatedFolders })
111-
112-
saveFolders(updatedFolders)
113-
}
114-
11544
// CONVERSATION OPERATIONS --------------------------------------------
11645

11746
const handleNewConversation = () => {
@@ -172,14 +101,6 @@ export const ReactStreamChat = () => {
172101
// ON LOAD --------------------------------------------
173102

174103
useEffect(() => {
175-
const settings = getSettings()
176-
if (settings.theme) {
177-
dispatch({
178-
field: 'lightMode',
179-
value: settings.theme,
180-
})
181-
}
182-
183104
if (window.innerWidth < 640) {
184105
dispatch({ field: 'showChatbar', value: false })
185106
dispatch({ field: 'showPromptbar', value: false })

src/styles/globals.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
height: 6px;
2929
}
3030

31-
html {
32-
background: #202123;
33-
}
34-
3531
@media (max-width: 720px) {
3632
pre {
3733
width: calc(100vw - 110px);

src/types/export.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
1-
import { Conversation, Message } from './chat';
2-
import { FolderInterface } from './folder';
3-
import { OpenAIModel } from './openai';
4-
import { Prompt } from './prompt';
1+
import { Conversation, Message } from './chat'
2+
import { FolderInterface } from './folder'
3+
import { Prompt } from './prompt'
54

65
export type SupportedExportFormats =
76
| ExportFormatV1
87
| ExportFormatV2
98
| ExportFormatV3
10-
| ExportFormatV4;
11-
export type LatestExportFormat = ExportFormatV4;
9+
| ExportFormatV4
10+
export type LatestExportFormat = ExportFormatV4
1211

1312
////////////////////////////////////////////////////////////////////////////////////////////
1413
interface ConversationV1 {
15-
id: number;
16-
name: string;
17-
messages: Message[];
14+
id: number
15+
name: string
16+
messages: Message[]
1817
}
1918

20-
export type ExportFormatV1 = ConversationV1[];
19+
export type ExportFormatV1 = ConversationV1[]
2120

2221
////////////////////////////////////////////////////////////////////////////////////////////
2322
interface ChatFolder {
24-
id: number;
25-
name: string;
23+
id: number
24+
name: string
2625
}
2726

2827
export interface ExportFormatV2 {
29-
history: Conversation[] | null;
30-
folders: ChatFolder[] | null;
28+
history: Conversation[] | null
29+
folders: ChatFolder[] | null
3130
}
3231

3332
////////////////////////////////////////////////////////////////////////////////////////////
3433
export interface ExportFormatV3 {
35-
version: 3;
36-
history: Conversation[];
37-
folders: FolderInterface[];
34+
version: 3
35+
history: Conversation[]
36+
folders: FolderInterface[]
3837
}
3938

4039
export interface ExportFormatV4 {
41-
version: 4;
42-
history: Conversation[];
43-
folders: FolderInterface[];
44-
prompts: Prompt[];
40+
version: 4
41+
history: Conversation[]
42+
folders: FolderInterface[]
43+
prompts: Prompt[]
4544
}

src/types/settings.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/utils/app/codeblock.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/utils/app/const.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export const DEFAULT_SYSTEM_PROMPT =
2-
"You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown.";
3-
export const OPENAI_API_HOST = 'https://api.openai.com';
4-
export const DEFAULT_TEMPERATURE = parseFloat('1');
5-
export const OPENAI_API_TYPE = 'openai';
6-
export const OPENAI_API_VERSION = '2023-03-15-preview';
7-
export const OPENAI_ORGANIZATION = '';
8-
export const AZURE_DEPLOYMENT_ID = '';
2+
"You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown."
3+
export const OPENAI_API_HOST = 'https://api.openai.com'
4+
export const DEFAULT_TEMPERATURE = parseFloat('1')
5+
export const OPENAI_API_TYPE = 'openai'
6+
export const OPENAI_API_VERSION = '2023-03-15-preview'
7+
export const OPENAI_ORGANIZATION = ''
8+
export const AZURE_DEPLOYMENT_ID = ''

src/utils/app/conversation.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import { Conversation } from '@/types/chat';
1+
import { Conversation } from '@/types/chat'
22

33
export const updateConversation = (
44
updatedConversation: Conversation,
55
allConversations: Conversation[],
66
) => {
77
const updatedConversations = allConversations.map((c) => {
88
if (c.id === updatedConversation.id) {
9-
return updatedConversation;
9+
return updatedConversation
1010
}
1111

12-
return c;
13-
});
12+
return c
13+
})
1414

15-
saveConversation(updatedConversation);
16-
saveConversations(updatedConversations);
15+
saveConversation(updatedConversation)
16+
saveConversations(updatedConversations)
1717

1818
return {
1919
single: updatedConversation,
2020
all: updatedConversations,
21-
};
22-
};
21+
}
22+
}
2323

2424
export const saveConversation = (conversation: Conversation) => {
25-
localStorage.setItem('selectedConversation', JSON.stringify(conversation));
26-
};
25+
localStorage.setItem('selectedConversation', JSON.stringify(conversation))
26+
}
2727

2828
export const saveConversations = (conversations: Conversation[]) => {
29-
localStorage.setItem('conversationHistory', JSON.stringify(conversations));
30-
};
29+
localStorage.setItem('conversationHistory', JSON.stringify(conversations))
30+
}

src/utils/app/folders.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/utils/app/prompts.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)