Skip to content

Commit ad9520f

Browse files
committed
add comments and sort import
1 parent 4bc4765 commit ad9520f

File tree

113 files changed

+543
-414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+543
-414
lines changed

src/components/Chat/Chat.tsx

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
// src/components/Chat/Chat.tsx
2+
import { useDownloadPresignedUrlQuery } from '~/hooks/queries/useDownloadPresignedUrl'
3+
import { useFetchEnabledDocGroups } from '@/hooks/queries/useFetchEnabledDocGroups'
4+
import { useFetchLLMProviders } from '@/hooks/queries/useFetchLLMProviders'
5+
import { useDeleteMessages } from '@/hooks/queries/useDeleteMessages'
6+
import { useLogConversation } from '@/hooks/queries/useLogConversation'
7+
import { useQueryRewrite } from '@/hooks/queries/useQueryRewrite'
8+
import { useRouteChat } from '@/hooks/queries/useRouteChat'
9+
import { useUpdateConversation } from '@/hooks/queries/useUpdateConversation'
10+
211
import { Button, Text } from '@mantine/core'
312
import {
413
IconAlertCircle,
@@ -29,7 +38,6 @@ import { v4 as uuidv4 } from 'uuid'
2938

3039
import HomeContext from '~/pages/api/home/home.context'
3140

32-
import { useDownloadPresignedUrlQuery } from '~/hooks/queries/useDownloadPresignedUrl'
3341
import { ChatInput } from './ChatInput'
3442
import { ChatLoader } from './ChatLoader'
3543
import { ErrorMessageDiv } from './ErrorMessageDiv'
@@ -57,13 +65,6 @@ import { Montserrat } from 'next/font/google'
5765
import Head from 'next/head'
5866
import { useRouter } from 'next/router'
5967
import { useAuth } from 'react-oidc-context'
60-
import { useFetchEnabledDocGroups } from '@/hooks/queries/useFetchEnabledDocGroups'
61-
import { useFetchLLMProviders } from '@/hooks/queries/useFetchLLMProviders'
62-
import { useDeleteMessages } from '@/hooks/queries/useDeleteMessages'
63-
import { useLogConversation } from '@/hooks/queries/useLogConversation'
64-
import { useQueryRewrite } from '@/hooks/queries/useQueryRewrite'
65-
import { useRouteChat } from '@/hooks/queries/useRouteChat'
66-
import { useUpdateConversation } from '@/hooks/queries/useUpdateConversation'
6768
import { CropwizardLicenseDisclaimer } from '~/pages/cropwizard-licenses'
6869

6970
import { get_user_permission } from '~/components/UIUC-Components/runAuthCheck'
@@ -110,45 +111,41 @@ export const Chat = memo(
110111
const auth = useAuth()
111112
const router = useRouter()
112113
const queryClient = useQueryClient()
114+
const getCurrentPageName = () => {
115+
// /CS-125/dashboard --> CS-125
116+
return router.asPath.slice(1).split('/')[0] as string
117+
}
118+
const bannerS3Path = courseMetadata?.banner_image_s3 || undefined
119+
120+
// React Query hooks
113121
const { refetch: refetchLLMProviders } = useFetchLLMProviders({
114122
projectName: courseName,
115123
})
116124
const { mutateAsync: runQueryRewriteAsync } = useQueryRewrite()
117125
const { mutateAsync: routeChatAsync } = useRouteChat()
118-
// const
119-
const bannerS3Path = courseMetadata?.banner_image_s3 || undefined
120126
const { data: bannerUrl } = useDownloadPresignedUrlQuery(
121127
bannerS3Path,
122128
courseName,
123129
)
124-
const getCurrentPageName = () => {
125-
// /CS-125/dashboard --> CS-125
126-
return router.asPath.slice(1).split('/')[0] as string
127-
}
128-
const [chat_ui] = useState(new ChatUI(new MLCEngine()))
129-
130-
const [inputContent, setInputContent] = useState<string>('')
131-
132-
const [enabledDocumentGroups, setEnabledDocumentGroups] = useState<
133-
string[]
134-
>(['All Documents']) // Default to 'All Documents' so retrieval can work immediately
135-
const [enabledTools, setEnabledTools] = useState<string[]>([])
136-
137130
const logConversationMutation = useLogConversation(getCurrentPageName())
138-
139131
const {
140132
data: documentGroupsHook,
141133
isSuccess: isSuccessDocumentGroups,
142134
// isError: isErrorDocumentGroups,
143135
} = useFetchEnabledDocGroups(getCurrentPageName())
144-
145136
const {
146137
data: toolsHook,
147138
isSuccess: isSuccessTools,
148139
isLoading: isLoadingTools,
149140
isError: isErrorTools,
150141
error: toolLoadingError,
151142
} = useFetchAllWorkflows(getCurrentPageName())
143+
const updateConversationMutation = useUpdateConversation(
144+
currentEmail,
145+
queryClient,
146+
courseName,
147+
)
148+
const deleteMessagesMutation = useDeleteMessages(currentEmail, courseName)
152149

153150
const permission = get_user_permission(courseMetadata, auth)
154151

@@ -172,6 +169,16 @@ export const Chat = memo(
172169
dispatch: homeDispatch,
173170
} = useContext(HomeContext)
174171

172+
// const
173+
const [chat_ui] = useState(new ChatUI(new MLCEngine()))
174+
175+
const [inputContent, setInputContent] = useState<string>('')
176+
177+
const [enabledDocumentGroups, setEnabledDocumentGroups] = useState<
178+
string[]
179+
>(['All Documents']) // Default to 'All Documents' so retrieval can work immediately
180+
const [enabledTools, setEnabledTools] = useState<string[]>([])
181+
175182
useEffect(() => {
176183
const loadModel = async () => {
177184
if (selectedConversation?.model && !chat_ui.isModelLoading()) {
@@ -206,13 +213,6 @@ export const Chat = memo(
206213
const chatContainerRef = useRef<HTMLDivElement>(null)
207214
const textareaRef = useRef<HTMLTextAreaElement>(null)
208215
const editedMessageIdRef = useRef<string | undefined>(undefined)
209-
const updateConversationMutation = useUpdateConversation(
210-
currentEmail,
211-
queryClient,
212-
courseName,
213-
)
214-
215-
const deleteMessagesMutation = useDeleteMessages(currentEmail, courseName)
216216

217217
// Document Groups
218218
useEffect(() => {

src/components/Chat/ChatInput.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useRouteChat } from '@/hooks/queries/useRouteChat'
2+
13
import {
24
type Content,
35
type Message,
@@ -53,7 +55,6 @@ import {
5355
import { type OpenAIModelID } from '~/utils/modelProviders/types/openai'
5456
import type ChatUI from '~/utils/modelProviders/WebLLM'
5557
import { webLLMModels } from '~/utils/modelProviders/WebLLM'
56-
import { useRouteChat } from '@/hooks/queries/useRouteChat'
5758
import { type ChatBody, ContextWithMetadata } from '~/types/chat'
5859
import { ALLOWED_FILE_EXTENSIONS, isImageFile } from '~/utils/fileUploadUtils'
5960

@@ -98,6 +99,9 @@ export const ChatInput = ({
9899
dispatch: homeDispatch,
99100
} = useContext(HomeContext)
100101

102+
// React Query hooks
103+
const { mutateAsync: routeChatAsync } = useRouteChat()
104+
101105
const {
102106
fileUploads,
103107
fileUploadRef,
@@ -130,7 +134,6 @@ export const ChatInput = ({
130134
const chatInputParentContainerRef = useRef<HTMLDivElement>(null)
131135
const isSmallScreen = useMediaQuery('(max-width: 960px)')
132136
const modelSelectContainerRef = useRef<HTMLDivElement | null>(null)
133-
const { mutateAsync: routeChatAsync } = useRouteChat()
134137
const { resetHeight } = useTextareaAutosize({ textareaRef, content })
135138
const { isFocused, handleFocus, handleBlur } = useChatInputFocus({
136139
textareaRef,

src/components/Chat/ChatMessage.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
// ChatMessage.tsx
2+
import {
3+
useDownloadPresignedUrl,
4+
useDownloadPresignedUrlQuery,
5+
} from '~/hooks/queries/useDownloadPresignedUrl'
6+
import { useLogConversation } from '@/hooks/queries/useLogConversation'
7+
28
import React, {
39
memo,
410
useContext,
@@ -31,10 +37,6 @@ import {
3137
} from '@/types/chat'
3238
import { useTranslation } from 'next-i18next'
3339
import HomeContext from '~/pages/api/home/home.context'
34-
import {
35-
useDownloadPresignedUrl,
36-
useDownloadPresignedUrlQuery,
37-
} from '~/hooks/queries/useDownloadPresignedUrl'
3840
import { CodeBlock } from '../Markdown/CodeBlock'
3941
import { MemoizedReactMarkdown } from '../Markdown/MemoizedReactMarkdown'
4042
import { generateSecureKey } from '~/utils/cryptoRandom'
@@ -48,7 +50,6 @@ import {
4850
saveConversationToServer,
4951
createLogConversationPayload,
5052
} from '@/hooks/__internal__/conversation'
51-
import { useLogConversation } from '@/hooks/queries/useLogConversation'
5253
import dayjs from 'dayjs'
5354
import utc from 'dayjs/plugin/utc'
5455
import { montserrat_heading, montserrat_paragraph } from 'fonts'

src/components/Chatbar/Chatbar.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import { useDeleteAllConversations } from '@/hooks/queries/useDeleteAllConversations'
2+
import { useDeleteConversation } from '@/hooks/queries/useDeleteConversation'
3+
import { useFetchConversationHistory } from '@/hooks/queries/useFetchConversationHistory'
4+
import { useUpdateConversation } from '@/hooks/queries/useUpdateConversation'
5+
import { useDownloadConvoHistory } from '@/hooks/queries/useDownloadConvoHistory'
6+
17
import { useState, useCallback, useContext, useEffect, Suspense } from 'react'
28
import { useTranslation } from 'next-i18next'
39
import { useCreateReducer } from '@/hooks/useCreateReducer'
@@ -14,11 +20,6 @@ import ChatbarContext from './Chatbar.context'
1420
import { type ChatbarInitialState, initialState } from './Chatbar.state'
1521
import { v4 as uuidv4 } from 'uuid'
1622
import { useQueryClient } from '@tanstack/react-query'
17-
import { useDeleteAllConversations } from '@/hooks/queries/useDeleteAllConversations'
18-
import { useDeleteConversation } from '@/hooks/queries/useDeleteConversation'
19-
import { useFetchConversationHistory } from '@/hooks/queries/useFetchConversationHistory'
20-
import { useUpdateConversation } from '@/hooks/queries/useUpdateConversation'
21-
import { useDownloadConvoHistory } from '@/hooks/queries/useDownloadConvoHistory'
2223

2324
import { AnimatePresence, motion } from 'framer-motion'
2425
import { LoadingSpinner } from '../UIUC-Components/LoadingSpinner'
@@ -41,7 +42,6 @@ export const Chatbar = ({
4142
const chatBarContextValue = useCreateReducer<ChatbarInitialState>({
4243
initialState,
4344
})
44-
const [isExporting, setIsExporting] = useState<boolean>(false)
4545

4646
const {
4747
state: { conversations, showChatbar, defaultModelId, folders },
@@ -62,27 +62,19 @@ export const Chatbar = ({
6262
)
6363

6464
const queryClient = useQueryClient()
65+
66+
// React Query hooks
6567
const deleteConversationMutation = useDeleteConversation(
6668
current_email as string,
6769
queryClient,
6870
courseName as string,
6971
searchTerm,
7072
)
71-
7273
const deleteAllConversationMutation = useDeleteAllConversations(
7374
queryClient,
7475
current_email as string,
7576
courseName as string,
7677
)
77-
78-
const handleApiKeyChange = useCallback(
79-
(apiKey: string) => {
80-
homeDispatch({ field: 'apiKey', value: apiKey })
81-
localStorage.setItem('apiKey', apiKey)
82-
},
83-
[homeDispatch],
84-
)
85-
8678
const {
8779
data: conversationHistory,
8880
error: conversationHistoryError,
@@ -97,15 +89,23 @@ export const Chatbar = ({
9789
debouncedSearchTerm,
9890
courseName,
9991
)
100-
10192
const updateConversationMutation = useUpdateConversation(
10293
current_email as string,
10394
queryClient,
10495
courseName as string,
10596
)
106-
10797
const { mutateAsync: downloadConvoHistoryAsync } = useDownloadConvoHistory()
10898

99+
const [isExporting, setIsExporting] = useState<boolean>(false)
100+
101+
const handleApiKeyChange = useCallback(
102+
(apiKey: string) => {
103+
homeDispatch({ field: 'apiKey', value: apiKey })
104+
localStorage.setItem('apiKey', apiKey)
105+
},
106+
[homeDispatch],
107+
)
108+
109109
const [convoMigrationLoading, setConvoMigrationLoading] =
110110
useState<boolean>(false)
111111

src/components/Chatbar/components/ChatFolders.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useUpdateConversation } from '@/hooks/queries/useUpdateConversation'
2+
13
import { useContext } from 'react'
24

35
import {
@@ -11,7 +13,6 @@ import Folder from '@/components/Folder'
1113

1214
import { ConversationComponent } from './Conversation'
1315
import { useQueryClient } from '@tanstack/react-query'
14-
import { useUpdateConversation } from '@/hooks/queries/useUpdateConversation'
1516

1617
interface Props {
1718
searchTerm: string

src/components/Sidebar/Sidebar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useDownloadPresignedUrlQuery } from '@/hooks/queries/useDownloadPresignedUrl'
2+
13
import {
24
IconEdit,
35
IconFolderPlus,
@@ -8,7 +10,6 @@ import {
810
import { type ReactNode } from 'react'
911
import Image from 'next/image'
1012
import { useTranslation } from 'react-i18next'
11-
import { useDownloadPresignedUrlQuery } from '@/hooks/queries/useDownloadPresignedUrl'
1213

1314
import { IconSettings } from '@tabler/icons-react'
1415

src/components/UIUC-Components/APIRequestBuilder.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useFetchLLMProviders } from '@/hooks/queries/useFetchLLMProviders'
2+
13
import { useState, useEffect } from 'react'
24
import {
35
Textarea,
@@ -15,7 +17,6 @@ import {
1517
IconChevronDown,
1618
IconInfoCircle,
1719
} from '@tabler/icons-react'
18-
import { useFetchLLMProviders } from '@/hooks/queries/useFetchLLMProviders'
1920
import { findDefaultModel } from './api-inputs/LLMsApiKeyInputForm'
2021
import { type AnySupportedModel } from '~/utils/modelProviders/LLMProvider'
2122
import { montserrat_heading, montserrat_paragraph } from 'fonts'
@@ -33,6 +34,11 @@ export default function APIRequestBuilder({
3334
apiKey,
3435
courseMetadata,
3536
}: APIRequestBuilderProps) {
37+
// React Query hooks
38+
const { data: llmProviders } = useFetchLLMProviders({
39+
projectName: course_name,
40+
})
41+
3642
const [selectedLanguage, setSelectedLanguage] = useState<
3743
'curl' | 'python' | 'node'
3844
>('curl')
@@ -47,10 +53,6 @@ export default function APIRequestBuilder({
4753
const [streamEnabled, setStreamEnabled] = useState(true)
4854
const [temperature, setTemperature] = useState(0.1)
4955

50-
const { data: llmProviders } = useFetchLLMProviders({
51-
projectName: course_name,
52-
})
53-
5456
useEffect(() => {
5557
if (llmProviders) {
5658
const defaultModel = findDefaultModel(llmProviders)

0 commit comments

Comments
 (0)