Skip to content

Commit 6c09607

Browse files
committed
enable select node only after input display
1 parent 9a72748 commit 6c09607

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

app/components/chat.tsx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,47 +92,47 @@ const SUGGESTIONS = [
9292

9393
const RemoveLastPath = (messages: Message[]) => {
9494
const index = messages.findIndex((m) => m.type === MessageTypes.Path)
95-
95+
9696
if (index !== -1) {
9797
messages = [...messages.slice(0, index - 2), ...messages.slice(index + 1)];
9898
messages = RemoveLastPath(messages)
9999
}
100-
100+
101101
return messages
102102
}
103103

104104
export function Chat({ repo, path, setPath, graph, chartRef, selectedPathId, isPath, setIsPath }: Props) {
105-
105+
106106
// Holds the messages in the chat
107107
const [messages, setMessages] = useState<Message[]>([]);
108-
108+
109109
// Holds the messages in the chat
110110
const [paths, setPaths] = useState<{ nodes: any[], edges: any[] }[]>([]);
111-
111+
112112
const [selectedPath, setSelectedPath] = useState<{ nodes: any[], edges: any[] }>();
113-
113+
114114
// Holds the user input while typing
115115
const [query, setQuery] = useState('');
116-
116+
117117
const [isPathResponse, setIsPathResponse] = useState(false);
118-
118+
119119
const [tipOpen, setTipOpen] = useState(false);
120-
120+
121121
const [sugOpen, setSugOpen] = useState(false);
122-
122+
123123
// A reference to the chat container to allow scrolling to the bottom
124124
const containerRef: React.RefObject<HTMLDivElement> = useRef(null);
125-
125+
126126
const isSendMessage = messages.some(m => m.type === MessageTypes.Pending) || (messages.some(m => m.text === "Please select a starting point and the end point. Select or press relevant item on the graph") && !messages.some(m => m.type === MessageTypes.Path))
127-
127+
128128
useEffect(() => {
129129
const p = paths.find((path) => [...path.edges, ...path.nodes].some((e: any) => e.id === selectedPathId))
130-
130+
131131
if (!p) return
132-
132+
133133
handleSetSelectedPath(p)
134134
}, [selectedPathId])
135-
135+
136136
// Scroll to the bottom of the chat on new message
137137
useEffect(() => {
138138
setTimeout(() => {
@@ -341,7 +341,6 @@ export function Chat({ repo, path, setPath, graph, chartRef, selectedPathId, isP
341341
className="Tip"
342342
onClick={() => {
343343
setTipOpen(false)
344-
setPath({})
345344
setMessages(prev => [
346345
...RemoveLastPath(prev),
347346
{ type: MessageTypes.Query, text: "Create a path" },
@@ -356,7 +355,10 @@ export function Chat({ repo, path, setPath, graph, chartRef, selectedPathId, isP
356355
type: MessageTypes.Response,
357356
text: "Please select a starting point and the end point. Select or press relevant item on the graph"
358357
}]), 300)
359-
setTimeout(() => setMessages(prev => [...prev, { type: MessageTypes.Path }]), 4000)
358+
setTimeout(() => {
359+
setPath({})
360+
setMessages(prev => [...prev, { type: MessageTypes.Path }])
361+
}, 4000)
360362
}}
361363
>
362364
<Lightbulb />

0 commit comments

Comments
 (0)