From c999d12a91d45ea6c9840fd21245d704cb93912c Mon Sep 17 00:00:00 2001 From: Kevin Date: Mon, 30 Jun 2025 11:35:43 -0500 Subject: [PATCH] fix: pr cleanup fmt, lint, tsc: --- src/components/Explorer/FileExplorer.tsx | 10 ++++-- src/components/Explorer/ProjectExplorer.tsx | 39 +++++++++++---------- src/components/Explorer/utils.test.ts | 4 --- src/lib/desktop.ts | 18 ++++++---- src/lib/isDesktop.ts | 2 +- src/lib/paths.ts | 4 ++- src/lib/singletons.ts | 2 -- 7 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/components/Explorer/FileExplorer.tsx b/src/components/Explorer/FileExplorer.tsx index b6ff2ce55..bf0216f42 100644 --- a/src/components/Explorer/FileExplorer.tsx +++ b/src/components/Explorer/FileExplorer.tsx @@ -8,7 +8,7 @@ import { isRowFake, } from '@src/components/Explorer/utils' import { ContextMenu, ContextMenuItem } from '@src/components/ContextMenu' -import type { Dispatch } from 'react' +import type { CSSProperties, Dispatch } from 'react' import { useRef, useState } from 'react' import { DeleteConfirmationDialog } from '@src/components/ProjectCard/DeleteProjectDialog' import { FixedSizeList as List } from 'react-window' @@ -85,7 +85,7 @@ export const FileExplorer = ({ return (
- {({ height, width }) => ( + {({ height, width}) => ( { +export const FileExplorerRowElement = ({ + data, + index, + style, +}: { data: FileExplorerRender[]; index: number; style: CSSProperties }) => { const rowElementRef = useRef(null) const item = data[index] const isSelected = diff --git a/src/components/Explorer/ProjectExplorer.tsx b/src/components/Explorer/ProjectExplorer.tsx index 9bbd3eedd..2c357292e 100644 --- a/src/components/Explorer/ProjectExplorer.tsx +++ b/src/components/Explorer/ProjectExplorer.tsx @@ -244,7 +244,7 @@ export const ProjectExplorer = ({ const isFile = child.children === null const isKCLFile = isFile && child.name?.endsWith(FILE_EXT) - const isOpen = project.name === child.path || openedRows.get(child.path) + const isOpen = project.name === child.path || openedRows.get(child.path) || false /** * If any parent is closed, keep the history of open children @@ -264,7 +264,7 @@ export const ProjectExplorer = ({ const render = !isAnyParentClosed && (project.path === child.parentPath || - openedRows.get(child.parentPath)) + openedRows.get(child.parentPath)) || false let icon: CustomIconName = 'file' if (isKCLFile) { @@ -373,10 +373,10 @@ export const ProjectExplorer = ({ systemIOActor.send({ type: SystemIOMachineEvents.createBlankFolder, data: { - requestedAbsolutePath: desktopSafePathJoin( - [getParentAbsolutePath(row.path), - requestedName] - ), + requestedAbsolutePath: desktopSafePathJoin([ + getParentAbsolutePath(row.path), + requestedName, + ]), }, }) } else { @@ -425,7 +425,10 @@ export const ProjectExplorer = ({ if (openedRowsRef.current.get(child.path)) { // If the file tree had the folder opened make the new one open. const newOpenedRows = new Map(openedRowsRef.current) - const key = [child.parentPath, requestedName].join('/') + const key = desktopSafePathJoin([ + child.parentPath, + requestedName, + ]) newOpenedRows.set(key, true) setOpenedRows(newOpenedRows) } @@ -444,10 +447,10 @@ export const ProjectExplorer = ({ } const pathRelativeToParent = parentPathRelativeToProject( - desktopSafePathJoin( - [getParentAbsolutePath(row.path), - fileNameForcedWithOriginalExt] - ), + desktopSafePathJoin([ + getParentAbsolutePath(row.path), + fileNameForcedWithOriginalExt, + ]), applicationProjectDirectory ) @@ -466,18 +469,16 @@ export const ProjectExplorer = ({ systemIOActor.send({ type: SystemIOMachineEvents.createBlankFile, data: { - requestedAbsolutePath: desktopSafePathJoin( - [getParentAbsolutePath(row.path), - fileNameForcedWithOriginalExt] - ), + requestedAbsolutePath: desktopSafePathJoin([ + getParentAbsolutePath(row.path), + fileNameForcedWithOriginalExt, + ]), }, }) } } else { - const requestedAbsoluteFilePathWithExtension = desktopSafePathJoin( - [getParentAbsolutePath(row.path), - name] - ) + const requestedAbsoluteFilePathWithExtension = + desktopSafePathJoin([getParentAbsolutePath(row.path), name]) // If your router loader is within the file you are renaming then reroute to the new path on disk // If you are renaming a file you are not loaded into, do not reload! const shouldWeNavigate = diff --git a/src/components/Explorer/utils.test.ts b/src/components/Explorer/utils.test.ts index 64b7f4d8e..56bd9fc06 100644 --- a/src/components/Explorer/utils.test.ts +++ b/src/components/Explorer/utils.test.ts @@ -17,7 +17,6 @@ describe('Explorer utils.ts', () => { parentPath: '/home/kevin/zoo/test-project', level: 0, index: 0, - key: '/home/kevin/zoo/test-project/.zoo-placeholder-file.kcl', setSize: 1, positionInSet: 1, } @@ -35,7 +34,6 @@ describe('Explorer utils.ts', () => { parentPath: '/home/kevin/zoo/test-project', level: 0, index: 0, - key: '/home/kevin/zoo/test-project/main.kcl', setSize: 1, positionInSet: 1, } @@ -54,7 +52,6 @@ describe('Explorer utils.ts', () => { parentPath: '/home/kevin/zoo/test-project', level: 0, index: 0, - key: '/home/kevin/zoo/test-project/.zoo-placeholder-folder', setSize: 1, positionInSet: 1, } @@ -72,7 +69,6 @@ describe('Explorer utils.ts', () => { parentPath: '/home/kevin/zoo/test-project', level: 0, index: 0, - key: '/home/kevin/zoo/test-project/part001', setSize: 1, positionInSet: 1, } diff --git a/src/lib/desktop.ts b/src/lib/desktop.ts index 9e1aeb39b..c1221a9a8 100644 --- a/src/lib/desktop.ts +++ b/src/lib/desktop.ts @@ -26,7 +26,11 @@ import { err } from '@src/lib/trap' import type { DeepPartial } from '@src/lib/types' import { getInVariableCase } from '@src/lib/utils' import { IS_STAGING } from '@src/routes/utils' -import { desktopSafePathJoin, desktopSafePathSplit, joinOSPaths } from './paths' +import { + desktopSafePathJoin, + desktopSafePathSplit, + joinOSPaths, +} from '@src/lib/paths' let cacheRelevantFileExtension: string[] | null = null const cachedRelevantFileExtensions = () => { @@ -390,8 +394,8 @@ const directoryCount = (file: FileEntry) => { return count } -function buildFileTree2(fileEntries, baseDir = '') { - const root = [] +function buildFileTree2(fileEntries: FileEntry[], baseDir = '') { + const root: Project[] = [] const pathMap = new Map() for (const entry of fileEntries) { @@ -400,7 +404,7 @@ function buildFileTree2(fileEntries, baseDir = '') { ? entry.path.slice(baseDir.length) : entry.path - const parts = relativePath.split('/').filter(Boolean) + const parts = desktopSafePathSplit(relativePath).filter(Boolean) let currentLevel = root let currentPath = '' let topLevelNode = null @@ -461,13 +465,13 @@ export async function getProjectInfo(projectPath: string): Promise { const isRelevantFile = (filename: string): boolean => cachedRelevantFileExtensions().some((ext) => filename.endsWith('.' + ext)) results = results.filter((entry) => { - return isRelevantFile(entry.path) || entry?.children?.length >= 0 + const isFolder = entry.children && entry.children.length >= 0 + return isRelevantFile(entry.path) || isFolder }) const splitter = desktopSafePathSplit(projectPath) splitter.pop() const projectDirectoryPath = desktopSafePathJoin(splitter) const project = buildFileTree2(results, projectDirectoryPath)[0] - console.log('PROJECT', project.name, project) project.children?.sort((a, b) => { if (a.path < b.path) { @@ -480,7 +484,7 @@ export async function getProjectInfo(projectPath: string): Promise { }) project.metadata = null project.default_file = await getDefaultKclFileForDir(projectPath, project) - project.readWriteAcces = true + project.readWriteAccess = true let metadata try { diff --git a/src/lib/isDesktop.ts b/src/lib/isDesktop.ts index 76704ca80..695b88a27 100644 --- a/src/lib/isDesktop.ts +++ b/src/lib/isDesktop.ts @@ -1,7 +1,7 @@ // https://github.com/electron/electron/issues/2288#issuecomment-337858978 // Thank you -let canThisBeCached : boolean | null = null +let canThisBeCached: boolean | null = null export function isDesktop(): boolean { if (canThisBeCached === null) { canThisBeCached = navigator.userAgent.toLowerCase().indexOf('electron') > -1 diff --git a/src/lib/paths.ts b/src/lib/paths.ts index 4e6e3b6ca..294e2c79a 100644 --- a/src/lib/paths.ts +++ b/src/lib/paths.ts @@ -242,7 +242,9 @@ export function desktopSafePathSplit(path: string, sep?: string): string[] { } export function desktopSafePathJoin(paths: string[], sep?: string): string { - return isDesktop() ? paths.join(sep || window?.electron?.sep) : webSafeJoin(paths) + return isDesktop() + ? paths.join(sep || window?.electron?.sep) + : webSafeJoin(paths) } /** diff --git a/src/lib/singletons.ts b/src/lib/singletons.ts index 63f2d53a4..8eb57da67 100644 --- a/src/lib/singletons.ts +++ b/src/lib/singletons.ts @@ -241,8 +241,6 @@ export const useCommandBarState = () => { return useSelector(commandBarActor, cmdBarStateSelector) } -window.dog = systemIOActor - // Initialize global commands commandBarActor.send({ type: 'Add commands',