fix: improving file/folder structure and resolving typescript errors
This commit is contained in:
@ -1,31 +1,12 @@
|
|||||||
import type { FileEntry } from '@src/lib/project'
|
import type { FileEntry } from '@src/lib/project'
|
||||||
import type { ReactNode } from 'react'
|
|
||||||
import type { CustomIconName } from '@src/components/CustomIcon'
|
|
||||||
import { CustomIcon } from '@src/components/CustomIcon'
|
import { CustomIcon } from '@src/components/CustomIcon'
|
||||||
import { sortFilesAndDirectories } from '@src/lib/desktopFS'
|
import { sortFilesAndDirectories } from '@src/lib/desktopFS'
|
||||||
import { uuidv4 } from '@src/lib/utils'
|
import { uuidv4 } from '@src/lib/utils'
|
||||||
|
import {
|
||||||
export interface FileExplorerEntry extends FileEntry {
|
FileExplorerEntry,
|
||||||
parentPath: string
|
FileExplorerRow,
|
||||||
level: number
|
FileExplorerRender,
|
||||||
index: number
|
} from '@src/components/Explorer/utils'
|
||||||
}
|
|
||||||
|
|
||||||
export interface FileExplorerRow extends FileExplorerEntry {
|
|
||||||
icon: CustomIconName
|
|
||||||
name: string
|
|
||||||
isFolder: boolean
|
|
||||||
status?: ReactNode
|
|
||||||
isOpen: boolean
|
|
||||||
rowClicked: (domIndex: number) => void
|
|
||||||
/**
|
|
||||||
* Fake file or folder rows are the placeholders for users to input a value
|
|
||||||
* and write that to disk to be read as a real one.
|
|
||||||
* they are placed in the DOM as if they are real but not from the source of truth
|
|
||||||
*/
|
|
||||||
isFake: boolean
|
|
||||||
activeIndex: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export const StatusDot = () => {
|
export const StatusDot = () => {
|
||||||
return <span>•</span>
|
return <span>•</span>
|
||||||
@ -47,7 +28,7 @@ const Spacer = (level: number) => {
|
|||||||
>
|
>
|
||||||
{Array(level)
|
{Array(level)
|
||||||
.fill(0)
|
.fill(0)
|
||||||
.map((value, index) => {
|
.map(() => {
|
||||||
const remSpacing = `${0.5}rem`
|
const remSpacing = `${0.5}rem`
|
||||||
return (
|
return (
|
||||||
<div className="h-full w-full" key={uuidv4()}>
|
<div className="h-full w-full" key={uuidv4()}>
|
||||||
@ -137,21 +118,6 @@ export const flattenProject = (
|
|||||||
return flattenTreeInOrder
|
return flattenTreeInOrder
|
||||||
}
|
}
|
||||||
|
|
||||||
const insertFakeRowAtFirstPositionUnderParentAfterFolder = (
|
|
||||||
fileExplorerEntries: FileExplorerEntry[],
|
|
||||||
fakeRow: { entry: FileExplorerEntry | null; isFile: boolean } | null
|
|
||||||
): void => {
|
|
||||||
if (!fakeRow) {
|
|
||||||
// no op
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// const requestedEntry: FileExplorerEntry = {
|
|
||||||
// ...fakeRow,
|
|
||||||
// }
|
|
||||||
// fileExplorerEntries.splice(insertIndex, 0, requestedEntry)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render all the rows of the file explorer in linear layout in the DOM.
|
* Render all the rows of the file explorer in linear layout in the DOM.
|
||||||
* each row is rendered one after another in the same parent DOM element
|
* each row is rendered one after another in the same parent DOM element
|
||||||
@ -177,14 +143,17 @@ export const FileExplorer = ({
|
|||||||
return row.isOpen
|
return row.isOpen
|
||||||
})
|
})
|
||||||
.map((row, index, original) => {
|
.map((row, index, original) => {
|
||||||
row.domIndex = index
|
const renderRow : FileExplorerRender= {
|
||||||
row.domLength = original.length
|
...row,
|
||||||
|
domIndex: index,
|
||||||
|
domLength: original.length
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<FileExplorerRow
|
<FileExplorerRowElement
|
||||||
key={uuidv4()}
|
key={uuidv4()}
|
||||||
row={row}
|
row={renderRow}
|
||||||
selectedRow={selectedRow}
|
selectedRow={selectedRow}
|
||||||
></FileExplorerRow>
|
></FileExplorerRowElement>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
@ -195,11 +164,11 @@ export const FileExplorer = ({
|
|||||||
* Making div soup!
|
* Making div soup!
|
||||||
* A row is a folder or a file.
|
* A row is a folder or a file.
|
||||||
*/
|
*/
|
||||||
export const FileExplorerRow = ({
|
export const FileExplorerRowElement = ({
|
||||||
row,
|
row,
|
||||||
selectedRow,
|
selectedRow,
|
||||||
}: {
|
}: {
|
||||||
row: FileExplorerRow
|
row: FileExplorerRender
|
||||||
selectedRow: FileExplorerEntry | null
|
selectedRow: FileExplorerEntry | null
|
||||||
domLength: number
|
domLength: number
|
||||||
}) => {
|
}) => {
|
||||||
|
|||||||
@ -1,14 +1,15 @@
|
|||||||
import type { Project, FileEntry } from '@src/lib/project'
|
import type { Project } from '@src/lib/project'
|
||||||
import { FILE_EXT } from '@src/lib/constants'
|
import { FILE_EXT } from '@src/lib/constants'
|
||||||
import {
|
import {
|
||||||
FileExplorer,
|
FileExplorer,
|
||||||
constructPath,
|
constructPath,
|
||||||
FileExplorerEntry,
|
|
||||||
FileExplorerRow,
|
|
||||||
flattenProject,
|
flattenProject,
|
||||||
StatusDot
|
StatusDot
|
||||||
} from '@src/components/Explorer/FileExplorer'
|
} from '@src/components/Explorer/FileExplorer'
|
||||||
import type { FileExplorerEntry } from '@src/components/Explorer/FileExplorer'
|
import {
|
||||||
|
FileExplorerRow,
|
||||||
|
} from '@src/components/Explorer/utils'
|
||||||
|
import type { FileExplorerEntry } from '@src/components/Explorer/utils'
|
||||||
import { FileExplorerHeaderActions } from '@src/components/Explorer/FileExplorerHeaderActions'
|
import { FileExplorerHeaderActions } from '@src/components/Explorer/FileExplorerHeaderActions'
|
||||||
import { useState, useRef, useEffect } from 'react'
|
import { useState, useRef, useEffect } from 'react'
|
||||||
import { systemIOActor } from '@src/lib/singletons'
|
import { systemIOActor } from '@src/lib/singletons'
|
||||||
|
|||||||
30
src/components/Explorer/utils.ts
Normal file
30
src/components/Explorer/utils.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import type { ReactNode } from 'react'
|
||||||
|
import type { FileEntry } from '@src/lib/project'
|
||||||
|
import type { CustomIconName } from '@src/components/CustomIcon'
|
||||||
|
|
||||||
|
export interface FileExplorerEntry extends FileEntry {
|
||||||
|
parentPath: string
|
||||||
|
level: number
|
||||||
|
index: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FileExplorerRow extends FileExplorerEntry {
|
||||||
|
icon: CustomIconName
|
||||||
|
name: string
|
||||||
|
isFolder: boolean
|
||||||
|
status?: ReactNode
|
||||||
|
isOpen: boolean
|
||||||
|
rowClicked: (domIndex: number) => void
|
||||||
|
/**
|
||||||
|
* Fake file or folder rows are the placeholders for users to input a value
|
||||||
|
* and write that to disk to be read as a real one.
|
||||||
|
* they are placed in the DOM as if they are real but not from the source of truth
|
||||||
|
*/
|
||||||
|
isFake: boolean
|
||||||
|
activeIndex: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FileExplorerRender extends FileExplorerRow {
|
||||||
|
domIndex: number
|
||||||
|
domLength: number
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user