fix: pr cleanup fmt, lint, tsc:

This commit is contained in:
Kevin
2025-06-30 11:35:43 -05:00
parent 003a6d2beb
commit c999d12a91
7 changed files with 42 additions and 37 deletions

View File

@ -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 (
<div role="presentation" className="relative h-full w-full">
<AutoSizer>
{({ height, width }) => (
{({ height, width}) => (
<List
height={height}
itemCount={data.length}
@ -228,7 +228,11 @@ function DeleteFileTreeItemDialog({
* Making div soup!
* A row is a folder or a file.
*/
export const FileExplorerRowElement = ({ data, index, style }: {}) => {
export const FileExplorerRowElement = ({
data,
index,
style,
}: { data: FileExplorerRender[]; index: number; style: CSSProperties }) => {
const rowElementRef = useRef(null)
const item = data[index]
const isSelected =

View File

@ -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 =

View File

@ -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,
}

View File

@ -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<Project> {
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> {
})
project.metadata = null
project.default_file = await getDefaultKclFileForDir(projectPath, project)
project.readWriteAcces = true
project.readWriteAccess = true
let metadata
try {

View File

@ -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

View File

@ -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)
}
/**

View File

@ -241,8 +241,6 @@ export const useCommandBarState = () => {
return useSelector(commandBarActor, cmdBarStateSelector)
}
window.dog = systemIOActor
// Initialize global commands
commandBarActor.send({
type: 'Add commands',