import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline"; import { ContextItemWithId } from "../../shims/typings"; import { contextItemToRangeInFileWithContents } from "../../shims/utils"; import React from "react"; import styled from "styled-components"; import { defaultBorderRadius, lightGray, vscBackground, vscForeground, } from ".."; import { WebviewIde } from "../../shims/webviewIde"; import FileIcon from "../FileIcon"; const ContextItemDiv = styled.div` cursor: pointer; padding-left: 6px; padding-right: 10px; padding-top: 6px; padding-bottom: 6px; margin-left: 4px; display: flex; align-items: center; border-radius: ${defaultBorderRadius}; width: fit-content; &:hover { background-color: #fff1; } `; interface ContextItemsPeekProps { contextItems?: ContextItemWithId[]; } const ContextItemsPeek = (props: ContextItemsPeekProps) => { const [open, setOpen] = React.useState(false); if (!props.contextItems || props.contextItems.length === 0) { return null; } function openContextItem(contextItem: ContextItemWithId) { if (contextItem.description.startsWith("http")) { window.open(contextItem.description, "_blank"); } else if ( contextItem.description.startsWith("/") || contextItem.description.startsWith("\\") ) { if (contextItem.name.includes(" (") && contextItem.name.endsWith(")")) { const rif = contextItemToRangeInFileWithContents(contextItem); new WebviewIde().showLines( rif.filepath, rif.range.start.line, rif.range.end.line, ); } else { new WebviewIde().openFile(contextItem.description); } } else { new WebviewIde().showVirtualFile(contextItem.name, contextItem.content); } } return (
setOpen((prev) => !prev)} > {open ? ( ) : ( )} Context Used
{open && (
{props.contextItems?.map((contextItem, idx) => { if (contextItem.description.startsWith("http")) { return ( { openContextItem(contextItem); }} > {contextItem.name} ); } return ( { openContextItem(contextItem); }} > {contextItem.name} ); })}
)}
); }; export default ContextItemsPeek;