diff --git a/src/components/extension/tree-view-api/index.tsx b/src/components/extension/tree-view-api/index.tsx index bbb622e..f075791 100644 --- a/src/components/extension/tree-view-api/index.tsx +++ b/src/components/extension/tree-view-api/index.tsx @@ -11,6 +11,7 @@ import React, { } from 'react'; import * as AccordionPrimitive from '@radix-ui/react-accordion'; import { FolderIcon, FolderOpenIcon } from 'lucide-react'; +import { RiDeleteBin6Line } from 'react-icons/ri'; import { Button } from '@/components/ui/button'; import { ScrollArea } from '@/components/ui/scroll-area'; @@ -227,13 +228,16 @@ const Folder = forwardRef - - {expendedItems?.includes(value) - ? (openIcon ?? ) - : (closeIcon ?? )} - {element} - - +
+ {expendedItems?.includes(value) + ? (openIcon ?? ) + : (closeIcon ?? )} + {element} +
+ { + e.stopPropagation(); + removeFileById(value); + }} + className=" pr-2 w-5 h-5 text-white/70 hover:text-white hidden group-hover:block" + /> + + {element && indicator &&
+ ); }, diff --git a/src/components/file/fileItem/index.tsx b/src/components/file/fileItem/index.tsx index 3d13740..7e98519 100644 --- a/src/components/file/fileItem/index.tsx +++ b/src/components/file/fileItem/index.tsx @@ -1,6 +1,7 @@ import React, { useRef } from 'react'; import { editor } from 'monaco-editor'; import { useDraggable } from '@dnd-kit/core'; +import { TiDocumentDelete } from 'react-icons/ti'; import { useActiveEditorStore, @@ -11,6 +12,7 @@ import { useSplitStore, } from '@/store/editorStore'; import { useDragIconStore } from '@/store/dragIconStore'; +import { useUploadFileDataStore } from '@/store/uploadFileDataStore'; import { addNewModel } from '@/components/editor/utils'; interface FileItemProps { file: any; @@ -53,6 +55,9 @@ export const FileItem: React.FC = ({ file, onMouseupFn }: FileIte dragIconRef.style.top = `${transform.y + clickClient.current.y + 5}px`; dragIconRef.innerHTML = `${file.filename}`; } + //used for fileTree + + const { removeFileById } = useUploadFileDataStore(); function handleFileItemMouseUp() { clickClient.current = { @@ -96,7 +101,7 @@ export const FileItem: React.FC = ({ file, onMouseupFn }: FileIte onMouseupFn && onMouseupFn(); handleFileItemMouseUp(); }} - className=" flex justify-start px-2 py-[0.2px] font-[250] text-[11.5px] w-full " + className=" group relative flex justify-between items-center px-2 py-[0.2px] font-[250] text-[11.5px] w-full " > = ({ file, onMouseupFn }: FileIte > {file.filename} + { + e.stopPropagation(); + removeFileById(file.id); + }} + className=" w-[15px] pr-[-4px] h-[15px] text-white/70 hover:text-white hidden group-hover:block" + /> ); }; diff --git a/src/components/file/fileTree/index.tsx b/src/components/file/fileTree/index.tsx index 88a0542..8f8cdbf 100644 --- a/src/components/file/fileTree/index.tsx +++ b/src/components/file/fileTree/index.tsx @@ -1,8 +1,8 @@ 'use client'; import { Tree, TreeViewElement, File, Folder } from '@/components/extension/tree-view-api'; +import { PendingFileItem } from '@/components/file/pendingFileItem'; import { FileItem } from '@/components/file/fileItem'; -import { useUploadFileDataStore } from '@/store/uploadFileDataStore'; type TOCProps = { toc: TreeViewElement[]; @@ -23,27 +23,12 @@ type TreeItemProps = { }; export const TreeItem = ({ elements }: TreeItemProps) => { - const { removeFileById, updateItem } = useUploadFileDataStore(); - return (
    {elements.map((element) => (
  • {element.status === 'pending' ? ( - { - if (e.target.value === '') { - removeFileById(element.id); - } else { - updateItem(element.id, { - filename: e.target.value, - status: 'success', - }); - } - }} - className=" px-px pl-2 pr-1 border-[1px] border-[#3f85f5] focus:outline-none focus:ring-1 focus:ring-[#3f85f5] ring-opacity-50 bg-transparent/30 text-[12px] font-[300]" - /> + ) : (element.children && element.children?.length > 0) || element.kind === 'directory' ? ( = ({ id }) => { + const { removeFileById, updateItem } = useUploadFileDataStore(); + const [fileName, setFileName] = useState(''); + const handleChangeStatus = () => { + if (fileName === '') { + removeFileById(id); + } else { + updateItem(id, { + filename: fileName, + status: 'success', + }); + } + }; + + return ( + { + if (e.key === 'Enter') { + handleChangeStatus(); + } + }} + onChange={(e) => { + setFileName(e.target.value); + }} + onBlur={() => { + handleChangeStatus(); + }} + className=" px-px pl-2 pr-1 border-[1px] border-[#3f85f5] focus:outline-none focus:ring-1 focus:ring-[#3f85f5] ring-opacity-50 bg-transparent/30 text-[12px] font-[300]" + /> + ); +};