'use client'; import { VscodeFileIcon } from "@/app/components/vscodeFileIcon"; import { Skeleton } from "@/components/ui/skeleton"; import { cn } from "@/lib/utils"; import { forwardRef, useMemo } from "react"; import { createPortal } from "react-dom"; import { VscFiles } from "react-icons/vsc"; import { FileSuggestion, RefineSuggestion, Suggestion } from "./types"; interface SuggestionBoxProps { selectedIndex: number; onInsertSuggestion: (suggestion: Suggestion) => void; isLoading: boolean; suggestions: Suggestion[]; } export const SuggestionBox = forwardRef(({ selectedIndex, onInsertSuggestion, isLoading, suggestions, }, ref) => { return createPortal(
{isLoading ? (
{ Array.from({ length: 10 }).map((_, index) => ( )) }
) : (suggestions.length === 0) ? (

No results found

) : (
{suggestions.map((suggestion, i) => (
{ onInsertSuggestion(suggestion); }} > { suggestion.type === 'file' && ( ) } { suggestion.type === 'refine' && ( ) }
))}
)}
, document.body ) }); SuggestionBox.displayName = 'SuggestionBox'; const FileSuggestionListItem = ({ file }: { file: FileSuggestion }) => { return ( <>
{file.name} {file.repo.split('/').pop()}/{file.path}
) } const RefineSuggestionListItem = ({ refine }: { refine: RefineSuggestion }) => { const Icon = useMemo(() => { switch (refine.targetSuggestionMode) { case 'file': return VscFiles; } }, [refine.targetSuggestionMode]); return ( <>
{refine.name} {refine.description}
) }