Skip to content

Commit 9874453

Browse files
committed
working move hooks and resize change content
1 parent 52d1c86 commit 9874453

File tree

9 files changed

+54
-12
lines changed

9 files changed

+54
-12
lines changed

src/components/Chat/index.tsx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ import { useChatContext } from '@/contexts/ChatContext'
1515
import StartChat from './StartChat'
1616
import resolveLLMClient from '@/lib/llm/client'
1717
import { appendToolCallsAndAutoExecuteTools, convertToolConfigToZodSchema } from '../../lib/llm/tools/utils'
18+
import useResizeObserver from '@/lib/hooks/use-resize-observer'
1819

1920
const ChatComponent: React.FC = () => {
2021
const [loadingState, setLoadingState] = useState<LoadingState>('idle')
2122
const [defaultModelName, setDefaultLLMName] = useState<string>('')
23+
const [containerWidth, setContainerWidth] = useState<number>(0)
24+
const containerRef = useRef<HTMLDivElement>(null)
2225
const { currentChat, setCurrentChat, saveChat } = useChatContext()
2326
const abortControllerRef = useRef<AbortController | null>(null)
2427

28+
useResizeObserver(containerRef, (entry) => {
29+
setContainerWidth(entry.contentRect.width)
30+
})
31+
2532
useEffect(() => {
2633
const fetchDefaultLLM = async () => {
2734
const defaultName = await window.llm.getDefaultLLMName()
@@ -133,9 +140,17 @@ const ChatComponent: React.FC = () => {
133140
[saveChat, setCurrentChat],
134141
)
135142

143+
// eslint-disable-next-line react/no-unstable-nested-components
144+
const CompactChatStart: React.FC = () => (
145+
<div className="flex size-full flex-col items-center justify-center p-4">
146+
<h3 className="text-lg font-medium">Chat Assistant</h3>
147+
<p className="text-sm text-muted-foreground">Please expand the panel to start a new chat</p>
148+
</div>
149+
)
150+
136151
return (
137-
<div className="flex size-full items-center justify-center">
138-
<div className="mx-auto flex size-full flex-col overflow-hidden bg-background">
152+
<div ref={containerRef} className="flex size-full items-center justify-center">
153+
<div className="mx-auto flex size-full flex-col overflow-hidden bg-background">
139154
{currentChat && currentChat.messages && currentChat.messages.length > 0 ? (
140155
<ChatMessages
141156
currentChat={currentChat}
@@ -146,12 +161,19 @@ const ChatComponent: React.FC = () => {
146161
}
147162
/>
148163
) : (
149-
<StartChat
150-
defaultModelName={defaultModelName}
151-
handleNewChatMessage={(userTextFieldInput?: string, agentConfig?: AgentConfig) =>
152-
handleNewChatMessage(undefined, userTextFieldInput, agentConfig)
153-
}
154-
/>
164+
// eslint-disable-next-line react/jsx-no-useless-fragment
165+
<>
166+
{containerWidth > 400 ? (
167+
<StartChat
168+
defaultModelName={defaultModelName}
169+
handleNewChatMessage={(userTextFieldInput?: string, agentConfig?: AgentConfig) =>
170+
handleNewChatMessage(undefined, userTextFieldInput, agentConfig)
171+
}
172+
/>
173+
) : (
174+
<CompactChatStart />
175+
)}
176+
</>
155177
)}
156178
</div>
157179
</div>

src/components/Settings/LLMSettings/InitialSetupLLMSettings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import { CheckCircleIcon, CogIcon } from '@heroicons/react/24/solid'
33
import { Button } from '@material-tailwind/react'
4-
import useLLMConfigs from './hooks/use-llm-configs'
4+
import useLLMConfigs from '../../../lib/hooks/use-llm-configs'
55
import LLMSettingsContent from './LLMSettingsContent'
66
import { Dialog, DialogContent, DialogTrigger } from '@/components/ui/dialog'
77

src/components/Settings/LLMSettings/LLMSettingsContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react'
22
import DefaultLLMSelector from './DefaultLLMSelector'
3-
import useLLMConfigs from './hooks/use-llm-configs'
3+
import useLLMConfigs from '../../../lib/hooks/use-llm-configs'
44
import SettingsRow from '../Shared/SettingsRow'
55
import { Button } from '@/components/ui/button'
66
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'

src/components/WritingAssistant/WritingAssistant.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import TextField from '@mui/material/TextField'
44
import Button from '@mui/material/Button'
55
import posthog from 'posthog-js'
66
import { streamText } from 'ai'
7-
import useOutsideClick from './hooks/use-outside-click'
7+
import useOutsideClick from '../../lib/hooks/use-outside-click'
88
import { generatePromptString, getLastMessage } from './utils'
99
import { ReorChatMessage } from '../../lib/llm/types'
1010
import { useFileContext } from '@/contexts/FileContext'

src/contexts/FileContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { RichTextLink } from '@/components/Editor/RichTextLink'
3535
import '@/styles/tiptap.scss'
3636
import SearchAndReplace from '@/components/Editor/Search/SearchAndReplaceExtension'
3737
import getMarkdown from '@/components/Editor/utils'
38-
import useOrderedSet from './hooks/use-ordered-set'
38+
import useOrderedSet from '../lib/hooks/use-ordered-set'
3939
import welcomeNote from '@/lib/welcome-note'
4040

4141
type FileContextType = {
File renamed without changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { useEffect, RefObject } from 'react'
2+
3+
const useResizeObserver = (ref: RefObject<HTMLElement>, callback: (entry: ResizeObserverEntry) => void) => {
4+
// eslint-disable-next-line consistent-return
5+
useEffect(() => {
6+
if (ref.current) {
7+
const observer = new ResizeObserver((entries) => {
8+
callback(entries[0])
9+
})
10+
11+
observer.observe(ref.current)
12+
13+
return () => {
14+
observer.disconnect()
15+
}
16+
}
17+
}, [ref, callback])
18+
}
19+
20+
export default useResizeObserver

0 commit comments

Comments
 (0)