From 8e5552fd5fab22de78ba8efd8500d1a8199da388 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Fri, 22 Dec 2023 11:30:27 +0100 Subject: [PATCH] tree building --- .../src/lib/tree-view-item/tree-view-item.tsx | 13 ++- .../src/lib/components/file-label.tsx | 4 - .../src/lib/components/file-render.tsx | 84 +++++++++---------- 3 files changed, 45 insertions(+), 56 deletions(-) diff --git a/libs/remix-ui/tree-view/src/lib/tree-view-item/tree-view-item.tsx b/libs/remix-ui/tree-view/src/lib/tree-view-item/tree-view-item.tsx index bb31979198..33c0469073 100644 --- a/libs/remix-ui/tree-view/src/lib/tree-view-item/tree-view-item.tsx +++ b/libs/remix-ui/tree-view/src/lib/tree-view-item/tree-view-item.tsx @@ -5,11 +5,11 @@ import './tree-view-item.css' export const TreeViewItem = (props: TreeViewItemProps) => { const {id, children, label, labelClass, expand, iconX = 'fas fa-caret-right', iconY = '', icon, controlBehaviour = false, innerRef, showIcon = true, ...otherProps} = props - + const [isExpanded, setIsExpanded] = useState(false) useEffect(() => { - //consolelog('tree view item', id) - },[id]) + setIsExpanded(expand) + }, [expand]) return (
  • @@ -17,17 +17,16 @@ export const TreeViewItem = (props: TreeViewItemProps) => { key={`treeViewDiv${id}`} data-id={`treeViewDiv${id}`} className={`d-flex flex-row align-items-center ${labelClass}`} - onClick={() => !controlBehaviour // && setIsExpanded(!isExpanded) - } + onClick={() => !controlBehaviour && setIsExpanded(!isExpanded)} > {children && showIcon ? ( -
    +
    ) : icon ? (
    ) : null} {label} - {expand ? children : null} + {isExpanded ? children : null}
  • ) } diff --git a/libs/remix-ui/workspace/src/lib/components/file-label.tsx b/libs/remix-ui/workspace/src/lib/components/file-label.tsx index 77823752d6..c379d980d4 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-label.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-label.tsx @@ -23,10 +23,6 @@ export const FileLabel = (props: FileLabelProps) => { const [fileStateClasses, setFileStateClasses] = useState('') const labelRef = useRef(null) - useEffect(() => { - //consolelog('file label', file) - },[file]) - useEffect(() => { if (focusEdit.element && file.path) { setIsEditable(focusEdit.element === file.path) diff --git a/libs/remix-ui/workspace/src/lib/components/file-render.tsx b/libs/remix-ui/workspace/src/lib/components/file-render.tsx index c4ed65647a..fcec4b5860 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-render.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-render.tsx @@ -1,21 +1,21 @@ // eslint-disable-next-line no-use-before-define -import React, { SyntheticEvent, useEffect, useState } from 'react' -import { FileType, WorkspaceElement } from '../types' +import React, {SyntheticEvent, useEffect, useState} from 'react' +import {FileType, WorkspaceElement} from '../types' // eslint-disable-next-line @typescript-eslint/no-unused-vars -import { TreeView, TreeViewItem } from '@remix-ui/tree-view' -import { getPathIcon } from '@remix-ui/helper' +import {TreeView, TreeViewItem} from '@remix-ui/tree-view' +import {getPathIcon} from '@remix-ui/helper' // eslint-disable-next-line @typescript-eslint/no-unused-vars -import { FileLabel } from './file-label' -import { fileDecoration, FileDecorationIcons } from '@remix-ui/file-decorators' -import { Draggable } from '@remix-ui/drag-n-drop' +import {FileLabel} from './file-label' +import {fileDecoration, FileDecorationIcons} from '@remix-ui/file-decorators' +import {Draggable} from '@remix-ui/drag-n-drop' import { fileKeySort } from '../utils' export interface RenderFileProps { file: FileType index: number - focusEdit: { element: string; type: string; isNew: boolean; lastEdit: string } - focusElement: { key: string; type: WorkspaceElement }[] - focusContext: { element: string; x: number; y: number; type: string } + focusEdit: {element: string; type: string; isNew: boolean; lastEdit: string} + focusElement: {key: string; type: WorkspaceElement}[] + focusContext: {element: string; x: number; y: number; type: string} ctrlKey: boolean expandPath: string[] hideIconsMenu?: React.Dispatch> @@ -29,24 +29,19 @@ export interface RenderFileProps { } export const FileRender = (props: RenderFileProps) => { - const { file } = props + const [file, setFile] = useState({} as FileType) const [hover, setHover] = useState(false) - //const [icon, setIcon] = useState('') + const [icon, setIcon] = useState('') const [childrenKeys, setChildrenKeys] = useState([]) useEffect(() => { - //if (props.file && props.file.path && props.file.type) { - // //consolelog('set icon', props.file.path) - // setIcon(getPathIcon(props.file.path)) - //} + if (props.file && props.file.path && props.file.type) { + setFile(props.file) + setIcon(getPathIcon(props.file.path)) + } }, [props.file]) useEffect(() => { - //consolelog('file render', props.file.path) - }, []) - - useEffect(() => { - return if (file.child) { try { const children: FileType[] = file.child as any @@ -101,13 +96,8 @@ export const FileRender = (props: RenderFileProps) => { event.stopPropagation() setHover(true) } - //consolelog('eval file render', file.path) - if (!file.path) return (<>) - - ///return (<>
    file
    ) - - if (file.isDirectory && false) { + if (file.isDirectory) { return ( { > {file.child ? ( - {Object.keys(file.child).map((key, index) => ( + {childrenKeys.map((key, index) => ( { )} ) - } else if (!file.isDirectory) { - //consolelog('start do file render', file.path) + } else { return ( - <> -
  • -
    {}} - > -
    - {file.name} -
    -
  • - + + +
    + + +
    +
    + + } + onClick={handleFileClick} + onContextMenu={handleContextMenu} + icon={icon} + labelClass={labelClass} + onMouseOver={handleMouseOver} + onMouseOut={handleMouseOut} + /> ) - } else { - return <> } }