-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Hide example prompts until chat input is focused #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,10 @@ import { ChatPanel } from './chat-panel' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ChatMessages } from './chat-messages' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { EmptyScreen } from './empty-screen' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Mapbox } from './map/mapbox-map' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useUIState, useAIState } from 'ai/rsc' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useUIState, useAIState, useActions } from 'ai/rsc' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { UserMessage } from './user-message' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { nanoid } from 'nanoid' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { UIState } from '@/app/actions' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import MobileIconsBar from './mobile-icons-bar' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useProfileToggle, ProfileToggleEnum } from "@/components/profile-toggle-context"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import SettingsView from "@/components/settings/settings-view"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -20,16 +23,27 @@ type ChatProps = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function Chat({ id }: ChatProps) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const router = useRouter() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const path = usePathname() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [messages] = useUIState() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [messages, setMessages] = useUIState() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [aiState] = useAIState() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { submit } = useActions() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [isMobile, setIsMobile] = useState(false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { activeView } = useProfileToggle(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [input, setInput] = useState('') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [showEmptyScreen, setShowEmptyScreen] = useState(false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setShowEmptyScreen(messages.length === 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [messages]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [isInputFocused, setIsInputFocused] = useState(false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const submitExampleMessage = async (message: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setMessages((currentMessages: UIState) => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...currentMessages, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: nanoid(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| component: <UserMessage message={message} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const responseMessage = await submit(message) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setMessages((currentMessages: UIState) => [...currentMessages, responseMessage as any]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+34
to
+46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. submitExampleMessage sends the wrong payload to
const submitExampleMessage = async (message: string) => {
setMessages(currentMessages => [
...currentMessages,
{
id: nanoid(),
component: <UserMessage message={message} />
}
])
- const responseMessage = await submit(message)
+ const formData = new FormData()
+ formData.append('input', message)
+ const responseMessage = await submit(formData)
setMessages(currentMessages => [...currentMessages, responseMessage as any])
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if device is mobile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -83,18 +97,20 @@ export function Chat({ id }: ChatProps) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <MobileIconsBar /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="mobile-chat-input-area"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ChatPanel messages={messages} input={input} setInput={setInput} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ChatPanel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messages={messages} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input={input} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setInput={setInput} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onFocus={() => setIsInputFocused(true)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onBlur={() => setIsInputFocused(false)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+104
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hiding example prompts on input blur makes them disappear before the user can click an example. In the browser event order, the input SuggestionDelay the blur state update so clicks on the examples still register. Replace the Apply this change to both mobile and desktop Reply with "@CharlieHelps yes please" if you'd like me to add a commit updating both places. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="mobile-chat-messages-area"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {showEmptyScreen ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <EmptyScreen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| submitMessage={message => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setInput(message) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {messages.length > 0 ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ChatMessages messages={messages} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : isInputFocused ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <EmptyScreen submitMessage={submitExampleMessage} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : null} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </MapDataProvider> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -107,16 +123,18 @@ export function Chat({ id }: ChatProps) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="flex justify-start items-start"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {/* This is the new div for scrolling */} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="w-1/2 flex flex-col space-y-3 md:space-y-4 px-8 sm:px-12 pt-12 md:pt-14 pb-4 h-[calc(100vh-0.5in)] overflow-y-auto"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ChatPanel messages={messages} input={input} setInput={setInput} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {showEmptyScreen ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <EmptyScreen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| submitMessage={message => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setInput(message) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ChatPanel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messages={messages} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input={input} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setInput={setInput} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onFocus={() => setIsInputFocused(true)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onBlur={() => setIsInputFocused(false)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {messages.length > 0 ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ChatMessages messages={messages} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : isInputFocused ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <EmptyScreen submitMessage={submitExampleMessage} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : null} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className="w-1/2 p-4 fixed h-[calc(100vh-0.5in)] top-0 right-0 mt-[0.5in]" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ▲ Next.js 15.3.3 (Turbopack) | ||
| - Local: http://localhost:3001 | ||
| - Network: http://192.168.0.2:3001 | ||
| - Environments: .env | ||
|
|
||
| ✓ Starting... | ||
|
Comment on lines
+1
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The SuggestionRemove
Reply with "@CharlieHelps yes please" if you'd like me to add a commit removing |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auto-focus defeats the “show on focus” requirement
Forwarding
onFocus/onBluris good, but because the textarea still auto-focuses on mount (Line 66), the parent handler flipsisInputFocusedtotrueimmediately. The EmptyScreen—and its example prompts—becomes visible before the user interacts, which contradicts the stated goal of hiding prompts until the chat input is manually focused. Please drop or gate the auto-focus so the new visibility logic only triggers after an intentional focus event.📝 Committable suggestion
🤖 Prompt for AI Agents