From b4428ef1f7bf496ed421535c2c79c14d5ea37358 Mon Sep 17 00:00:00 2001 From: Anchel135 Date: Mon, 18 Nov 2024 13:46:50 +0200 Subject: [PATCH 1/5] add suggestions and little fixes --- app/components/Input.tsx | 4 +- app/components/chat.tsx | 75 +++++++++++++++++++++++++++--------- app/components/dataPanel.tsx | 2 +- 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/app/components/Input.tsx b/app/components/Input.tsx index d314fe8e..38bc17ac 100644 --- a/app/components/Input.tsx +++ b/app/components/Input.tsx @@ -91,7 +91,7 @@ export default function Input({ value, onValueChange, handelSubmit, graph, icon, case "ArrowUp": { e.preventDefault() setSelectedOption(prev => { - containerRef.current?.scrollTo({ behavior: 'smooth', top: (prev <= 0 ? options.length - 1 : prev - 1) * 64 }) + containerRef.current?.scrollTo({ behavior: 'smooth', top: (prev <= 0 ? options.length - 1 : prev - 1) * containerRef.current.children[0].clientHeight }) return prev <= 0 ? options.length - 1 : prev - 1 }) return @@ -99,7 +99,7 @@ export default function Input({ value, onValueChange, handelSubmit, graph, icon, case "ArrowDown": { e.preventDefault() setSelectedOption(prev => { - containerRef.current?.scrollTo({ behavior: 'smooth', top: ((prev + 1) % options.length) * 64 }) + containerRef.current?.scrollTo({ behavior: 'smooth', top: ((prev + 1) % options.length) * containerRef.current.children[0].clientHeight }) return (prev + 1) % options.length }) return diff --git a/app/components/chat.tsx b/app/components/chat.tsx index c2df1aa0..fde3d035 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -1,13 +1,14 @@ import { toast } from "@/components/ui/use-toast"; import { Dispatch, FormEvent, MutableRefObject, SetStateAction, useEffect, useRef, useState } from "react"; import Image from "next/image"; -import { AlignLeft, ArrowRight, ChevronDown, Lightbulb, Undo2 } from "lucide-react"; +import { AlignLeft, ArrowDown, ArrowRight, ChevronDown, Lightbulb, Undo2 } from "lucide-react"; import { Path } from "../page"; import Input from "./Input"; import { Graph } from "./model"; import { cn } from "@/lib/utils"; import { LAYOUT } from "./code-graph"; import { TypeAnimation } from "react-type-animation"; +import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; enum MessageTypes { Query, @@ -35,6 +36,14 @@ interface Props { setIsPath: (isPathResponse: boolean) => void } +const SUGGETSTIONS = [ + "List a few recursive functions", + "What is the name of the most used method?", + "Who is calling the most used method?", + "Which function has the largest number of arguments? List a few arguments", + "Show a calling path between the drop_edge_range_index function and _query, only return function(s) names", +] + const RemoveLastPath = (messages: Message[]) => { const index = messages.findIndex((m) => m.type === MessageTypes.Path) @@ -62,6 +71,8 @@ export function Chat({ repo, path, setPath, graph, chartRef, selectedPathId, isP const [isPathResponse, setIsPathResponse] = useState(false); const [tipOpen, setTipOpen] = useState(false); + + const [sugOpen, setSugOpen] = useState(false); // A reference to the chat container to allow scrolling to the bottom const containerRef: React.RefObject = useRef(null); @@ -202,11 +213,13 @@ export function Chat({ repo, path, setPath, graph, chartRef, selectedPathId, isP } // Send the user query to the server - async function sendQuery(event: FormEvent) { + async function sendQuery(event?: FormEvent, sugQuery?: string) { + + event?.preventDefault(); - event.preventDefault(); + if (isSendMessage) return - const q = query.trim() + const q = query?.trim() || sugQuery! if (!q) { toast({ @@ -491,22 +504,46 @@ export function Chat({ repo, path, setPath, graph, chartRef, selectedPathId, isP } -
- { - repo && -
- -
- - -
-
- } -
+
+ + + + + +
+ + } + + + { + SUGGETSTIONS.map((s, i) => ( + + )) + } + + ); } diff --git a/app/components/dataPanel.tsx b/app/components/dataPanel.tsx index 7aefeb7d..bbbe9328 100644 --- a/app/components/dataPanel.tsx +++ b/app/components/dataPanel.tsx @@ -25,7 +25,7 @@ export default function DataPanel({ obj, setObj, url }: Props) { const object = Object.entries(obj).filter(([k]) => !excludedProperties.includes(k)) return ( -
+

{label.toUpperCase()}

From 7272707fec10f392e0141e27bd8dce6adc659587 Mon Sep 17 00:00:00 2001 From: Anchel135 Date: Wed, 27 Nov 2024 11:44:30 +0200 Subject: [PATCH 2/5] fix suggestions box --- app/components/chat.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index fde3d035..9a9fadb9 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -36,7 +36,7 @@ interface Props { setIsPath: (isPathResponse: boolean) => void } -const SUGGETSTIONS = [ +const SUGGESTIONS = [ "List a few recursive functions", "What is the name of the most used method?", "Who is calling the most used method?", @@ -526,9 +526,9 @@ export function Chat({ repo, path, setPath, graph, chartRef, selectedPathId, isP
} - + { - SUGGETSTIONS.map((s, i) => ( + SUGGESTIONS.map((s, i) => (
From e3982421d8d2e8c0a54013723bb9701dfd230a3d Mon Sep 17 00:00:00 2001 From: Anchel135 Date: Wed, 27 Nov 2024 13:27:49 +0200 Subject: [PATCH 4/5] fix test --- app/components/chat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 9e4a9c06..9686eda7 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -501,7 +501,7 @@ export function Chat({ repo, path, setPath, graph, chartRef, selectedPathId, isP { repo &&
- From 709119904ab5f0caf055857c479fdb4fa2c8837f Mon Sep 17 00:00:00 2001 From: Anchel135 Date: Wed, 27 Nov 2024 13:31:30 +0200 Subject: [PATCH 5/5] fix sugg box --- app/components/chat.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 9686eda7..4e2e4ef6 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -506,7 +506,7 @@ export function Chat({ repo, path, setPath, graph, chartRef, selectedPathId, isP - @@ -522,6 +522,7 @@ export function Chat({ repo, path, setPath, graph, chartRef, selectedPathId, isP { SUGGESTIONS.map((s, i) => (