Skip to content

Commit 26b1797

Browse files
committed
feat: remove unused export utils
1 parent a655ab0 commit 26b1797

File tree

10 files changed

+36
-328
lines changed

10 files changed

+36
-328
lines changed

src/components/Chat/Chat.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface Props {
2020

2121
export const Chat = memo(({ stopConversationRef }: Props) => {
2222
const {
23-
state: { selectedConversation, conversations, apiKey },
23+
state: { selectedConversation, conversations },
2424
handleUpdateConversation,
2525
dispatch: homeDispatch,
2626
} = useContext(ReactStreamChatContext)
@@ -220,7 +220,7 @@ QuickSort is an efficient, in-place sorting algorithm that, in practice, outperf
220220
homeDispatch({ field: 'messageIsStreaming', value: false })
221221
}
222222
},
223-
[apiKey, conversations, selectedConversation, stopConversationRef],
223+
[conversations, selectedConversation, stopConversationRef],
224224
)
225225

226226
const handleScroll = () => {

src/components/ReactStreamChat/index.tsx

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const ReactStreamChat = () => {
2626
})
2727

2828
const {
29-
state: { lightMode, folders, conversations, selectedConversation, prompts },
29+
state: { lightMode, conversations, selectedConversation },
3030
dispatch,
3131
} = contextValue
3232

@@ -90,42 +90,9 @@ export const ReactStreamChat = () => {
9090
dispatch({ field: 'conversations', value: all })
9191
}
9292

93-
// EFFECTS --------------------------------------------
94-
95-
useEffect(() => {
96-
if (window.innerWidth < 640) {
97-
dispatch({ field: 'showChatbar', value: false })
98-
}
99-
}, [selectedConversation])
100-
10193
// ON LOAD --------------------------------------------
10294

10395
useEffect(() => {
104-
if (window.innerWidth < 640) {
105-
dispatch({ field: 'showChatbar', value: false })
106-
dispatch({ field: 'showPromptbar', value: false })
107-
}
108-
109-
const showChatbar = localStorage.getItem('showChatbar')
110-
if (showChatbar) {
111-
dispatch({ field: 'showChatbar', value: showChatbar === 'true' })
112-
}
113-
114-
const showPromptbar = localStorage.getItem('showPromptbar')
115-
if (showPromptbar) {
116-
dispatch({ field: 'showPromptbar', value: showPromptbar === 'true' })
117-
}
118-
119-
const folders = localStorage.getItem('folders')
120-
if (folders) {
121-
dispatch({ field: 'folders', value: JSON.parse(folders) })
122-
}
123-
124-
const prompts = localStorage.getItem('prompts')
125-
if (prompts) {
126-
dispatch({ field: 'prompts', value: JSON.parse(prompts) })
127-
}
128-
12996
const conversationHistory = localStorage.getItem('conversationHistory')
13097
if (conversationHistory) {
13198
const parsedConversationHistory: Conversation[] =
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,32 @@
11
import { Conversation, Message } from '@/types/chat'
2-
import { FolderInterface } from '@/types/folder'
32
import { OpenAIModel, OpenAIModelID } from '@/types/openai'
4-
import { Prompt } from '@/types/prompt'
53

64
export interface ReactStreamChatInitialState {
7-
apiKey: string
85
loading: boolean
96
lightMode: 'light' | 'dark'
107
messageIsStreaming: boolean
118
models: OpenAIModel[]
12-
folders: FolderInterface[]
139
conversations: Conversation[]
1410
selectedConversation: Conversation | undefined
1511
currentMessage: Message | undefined
16-
prompts: Prompt[]
1712
temperature: number
18-
showChatbar: boolean
1913
showPromptbar: boolean
20-
currentFolder: FolderInterface | undefined
2114
messageError: boolean
2215
searchTerm: string
2316
defaultModelId: OpenAIModelID | undefined
24-
serverSideApiKeyIsSet: boolean
2517
}
2618

2719
export const initialState: ReactStreamChatInitialState = {
28-
apiKey: '',
2920
loading: false,
3021
lightMode: 'dark',
3122
messageIsStreaming: false,
3223
models: [],
33-
folders: [],
3424
conversations: [],
3525
selectedConversation: undefined,
3626
currentMessage: undefined,
37-
prompts: [],
3827
temperature: 1,
3928
showPromptbar: true,
40-
showChatbar: true,
41-
currentFolder: undefined,
4229
messageError: false,
4330
searchTerm: '',
4431
defaultModelId: undefined,
45-
serverSideApiKeyIsSet: false,
4632
}

src/lib/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { ReactStreamChat } from '@/components/ReactStreamChat'
2+
export {
3+
cleanConversationHistory,
4+
cleanSelectedConversation,
5+
} from '@/utils/app/clean'

src/types/export.ts

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

src/types/folder.ts

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

src/types/prompt.ts

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

src/types/storage.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
import { Conversation } from './chat';
2-
import { FolderInterface } from './folder';
3-
import { Prompt } from './prompt';
1+
import { Conversation } from './chat'
42

53
// keep track of local storage schema
64
export interface LocalStorage {
7-
apiKey: string;
8-
conversationHistory: Conversation[];
9-
selectedConversation: Conversation;
10-
theme: 'light' | 'dark';
11-
// added folders (3/23/23)
12-
folders: FolderInterface[];
13-
// added prompts (3/26/23)
14-
prompts: Prompt[];
15-
// added showChatbar and showPromptbar (3/26/23)
16-
showChatbar: boolean;
17-
showPromptbar: boolean;
5+
conversationHistory: Conversation[]
6+
selectedConversation: Conversation
7+
theme: 'light' | 'dark'
188
}

src/utils/app/clean.ts

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,84 @@
1-
import { Conversation } from '@/types/chat';
2-
import { OpenAIModelID, OpenAIModels } from '@/types/openai';
3-
4-
import { DEFAULT_SYSTEM_PROMPT, DEFAULT_TEMPERATURE } from './const';
1+
import { Conversation } from '@/types/chat'
2+
import { OpenAIModelID, OpenAIModels } from '@/types/openai'
3+
import { DEFAULT_SYSTEM_PROMPT, DEFAULT_TEMPERATURE } from './const'
54

65
export const cleanSelectedConversation = (conversation: Conversation) => {
7-
// added model for each conversation (3/20/23)
8-
// added system prompt for each conversation (3/21/23)
9-
// added folders (3/23/23)
10-
// added prompts (3/26/23)
11-
// added messages (4/16/23)
12-
13-
let updatedConversation = conversation;
6+
let updatedConversation = conversation
147

15-
// check for model on each conversation
168
if (!updatedConversation.model) {
179
updatedConversation = {
1810
...updatedConversation,
1911
model: updatedConversation.model || OpenAIModels[OpenAIModelID.GPT_3_5],
20-
};
12+
}
2113
}
2214

23-
// check for system prompt on each conversation
2415
if (!updatedConversation.prompt) {
2516
updatedConversation = {
2617
...updatedConversation,
2718
prompt: updatedConversation.prompt || DEFAULT_SYSTEM_PROMPT,
28-
};
19+
}
2920
}
3021

3122
if (!updatedConversation.temperature) {
3223
updatedConversation = {
3324
...updatedConversation,
3425
temperature: updatedConversation.temperature || DEFAULT_TEMPERATURE,
35-
};
26+
}
3627
}
3728

3829
if (!updatedConversation.folderId) {
3930
updatedConversation = {
4031
...updatedConversation,
4132
folderId: updatedConversation.folderId || null,
42-
};
33+
}
4334
}
4435

4536
if (!updatedConversation.messages) {
4637
updatedConversation = {
4738
...updatedConversation,
4839
messages: updatedConversation.messages || [],
49-
};
40+
}
5041
}
5142

52-
return updatedConversation;
53-
};
43+
return updatedConversation
44+
}
5445

5546
export const cleanConversationHistory = (history: any[]): Conversation[] => {
56-
// added model for each conversation (3/20/23)
57-
// added system prompt for each conversation (3/21/23)
58-
// added folders (3/23/23)
59-
// added prompts (3/26/23)
60-
// added messages (4/16/23)
61-
6247
if (!Array.isArray(history)) {
63-
console.warn('history is not an array. Returning an empty array.');
64-
return [];
48+
console.warn('history is not an array. Returning an empty array.')
49+
return []
6550
}
6651

6752
return history.reduce((acc: any[], conversation) => {
6853
try {
6954
if (!conversation.model) {
70-
conversation.model = OpenAIModels[OpenAIModelID.GPT_3_5];
55+
conversation.model = OpenAIModels[OpenAIModelID.GPT_3_5]
7156
}
7257

7358
if (!conversation.prompt) {
74-
conversation.prompt = DEFAULT_SYSTEM_PROMPT;
59+
conversation.prompt = DEFAULT_SYSTEM_PROMPT
7560
}
7661

7762
if (!conversation.temperature) {
78-
conversation.temperature = DEFAULT_TEMPERATURE;
63+
conversation.temperature = DEFAULT_TEMPERATURE
7964
}
8065

8166
if (!conversation.folderId) {
82-
conversation.folderId = null;
67+
conversation.folderId = null
8368
}
8469

8570
if (!conversation.messages) {
86-
conversation.messages = [];
71+
conversation.messages = []
8772
}
8873

89-
acc.push(conversation);
90-
return acc;
74+
acc.push(conversation)
75+
return acc
9176
} catch (error) {
9277
console.warn(
9378
`error while cleaning conversations' history. Removing culprit`,
9479
error,
95-
);
80+
)
9681
}
97-
return acc;
98-
}, []);
99-
};
82+
return acc
83+
}, [])
84+
}

0 commit comments

Comments
 (0)