mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-29 22:51:49 +01:00
fix: recreate full directory path and fix hooks
This fixes two bugs. The first had to do with the path library not working in prod. That involved making a simple version of it that works in the meantime. The other is rendering a different number of hooks which required moving hooks outside of an if statement.
This commit is contained in:
parent
f7c2897904
commit
bf3a036df9
@ -10,6 +10,7 @@ import "./directorypreview.less";
|
||||
|
||||
interface DirectoryTableProps {
|
||||
data: FileInfo[];
|
||||
cwd: string;
|
||||
setFileName: (_: string) => void;
|
||||
}
|
||||
|
||||
@ -26,11 +27,11 @@ const defaultColumns = [
|
||||
}),
|
||||
columnHelper.accessor("mimetype", {
|
||||
cell: (info) => info.getValue(),
|
||||
header: () => <span>Mimetype</span>,
|
||||
header: () => <span>Type</span>,
|
||||
}),
|
||||
];
|
||||
|
||||
function DirectoryTable<T, U>({ data, setFileName }: DirectoryTableProps) {
|
||||
function DirectoryTable({ data, cwd, setFileName }: DirectoryTableProps) {
|
||||
const [columns] = React.useState<typeof defaultColumns>(() => [...defaultColumns]);
|
||||
const table = useReactTable({
|
||||
data,
|
||||
@ -75,9 +76,9 @@ function DirectoryTable<T, U>({ data, setFileName }: DirectoryTableProps) {
|
||||
))}
|
||||
</div>
|
||||
{table.getState().columnSizingInfo.isResizingColumn ? (
|
||||
<MemoizedTableBody table={table} setFileName={setFileName} />
|
||||
<MemoizedTableBody table={table} cwd={cwd} setFileName={setFileName} />
|
||||
) : (
|
||||
<TableBody table={table} setFileName={setFileName} />
|
||||
<TableBody table={table} cwd={cwd} setFileName={setFileName} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
@ -85,10 +86,11 @@ function DirectoryTable<T, U>({ data, setFileName }: DirectoryTableProps) {
|
||||
|
||||
interface TableBodyProps {
|
||||
table: Table<FileInfo>;
|
||||
cwd: string;
|
||||
setFileName: (_: string) => void;
|
||||
}
|
||||
|
||||
function TableBody({ table, setFileName }: TableBodyProps) {
|
||||
function TableBody({ table, cwd, setFileName }: TableBodyProps) {
|
||||
return (
|
||||
<div className="dir-table-body">
|
||||
{table.getRowModel().rows.map((row) => (
|
||||
@ -98,18 +100,21 @@ function TableBody({ table, setFileName }: TableBodyProps) {
|
||||
tabIndex={0}
|
||||
onDoubleClick={() => {
|
||||
const newFileName = row.getValue("path") as string;
|
||||
setFileName(newFileName);
|
||||
const fullPath = cwd.concat("/", newFileName);
|
||||
setFileName(fullPath);
|
||||
}}
|
||||
>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<div
|
||||
className="dir-table-body-cell"
|
||||
key={cell.id}
|
||||
style={{ width: `calc(var(--col-${cell.column.id}-size) * 1px)` }}
|
||||
>
|
||||
{cell.renderValue<any>()}
|
||||
</div>
|
||||
))}
|
||||
{row.getVisibleCells().map((cell) => {
|
||||
return (
|
||||
<div
|
||||
className="dir-table-body-cell"
|
||||
key={cell.id}
|
||||
style={{ width: `calc(var(--col-${cell.column.id}-size) * 1px)` }}
|
||||
>
|
||||
{cell.renderValue<string>()}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@ -130,7 +135,7 @@ function DirectoryPreview({ contentAtom, fileNameAtom }: DirectoryPreviewProps)
|
||||
const contentText = jotai.useAtomValue(contentAtom);
|
||||
let content: FileInfo[] = JSON.parse(contentText);
|
||||
let [fileName, setFileName] = jotai.useAtom(fileNameAtom);
|
||||
return <DirectoryTable data={content} setFileName={setFileName} />;
|
||||
return <DirectoryTable data={content} cwd={fileName} setFileName={setFileName} />;
|
||||
}
|
||||
|
||||
export { DirectoryPreview };
|
||||
|
@ -55,6 +55,7 @@ function StreamingPreview({ fileInfo }: { fileInfo: FileInfo }) {
|
||||
}
|
||||
|
||||
function PreviewView({ blockId }: { blockId: string }) {
|
||||
/*
|
||||
const blockData = WOS.useWaveObjectValueWithSuspense<Block>(WOS.makeORef("block", blockId));
|
||||
if (blockData == null) {
|
||||
return (
|
||||
@ -63,6 +64,7 @@ function PreviewView({ blockId }: { blockId: string }) {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
*/
|
||||
const blockAtom = WOS.getWaveObjectAtom<Block>(`block:${blockId}`);
|
||||
const fileNameAtom: jotai.WritableAtom<string, [string], void> = useBlockCache(blockId, "preview:filename", () =>
|
||||
jotai.atom<string, [string], void>(
|
||||
@ -114,6 +116,7 @@ function PreviewView({ blockId }: { blockId: string }) {
|
||||
mimeType = "";
|
||||
}
|
||||
const fileInfo = jotai.useAtomValue(statFileAtom);
|
||||
const fileContent = jotai.useAtomValue(fileContentAtom);
|
||||
|
||||
// handle streaming files here
|
||||
if (mimeType.startsWith("video/") || mimeType.startsWith("audio/") || mimeType.startsWith("image/")) {
|
||||
@ -131,7 +134,7 @@ function PreviewView({ blockId }: { blockId: string }) {
|
||||
if (mimeType.startsWith("text/")) {
|
||||
return (
|
||||
<div className="view-preview view-preview-text">
|
||||
<pre>{jotai.useAtomValue(fileContentAtom)}</pre>
|
||||
<pre>{fileContent}</pre>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -73,9 +73,8 @@ func (fs *FileService) ReadFile(path string) (*FullFile, error) {
|
||||
var innerFilesInfo []FileInfo
|
||||
for _, innerFileEntry := range innerFilesEntries {
|
||||
innerFileInfoInt, _ := innerFileEntry.Info()
|
||||
fullFilePath := filepath.Join(finfo.Path, innerFileInfoInt.Name())
|
||||
innerFileInfo := FileInfo{
|
||||
Path: fullFilePath,
|
||||
Path: innerFileInfoInt.Name(),
|
||||
Size: innerFileInfoInt.Size(),
|
||||
Mode: innerFileInfoInt.Mode(),
|
||||
ModTime: innerFileInfoInt.ModTime().UnixMilli(),
|
||||
|
Loading…
Reference in New Issue
Block a user