From bf3a036df96e6aa2c5aea5ceff18d9aad93e19c6 Mon Sep 17 00:00:00 2001 From: Sylvia Crowe Date: Mon, 3 Jun 2024 13:24:20 -0700 Subject: [PATCH] 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. --- frontend/app/view/directorypreview.tsx | 37 +++++++++++++++----------- frontend/app/view/preview.tsx | 5 +++- pkg/service/fileservice/fileservice.go | 3 +-- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/frontend/app/view/directorypreview.tsx b/frontend/app/view/directorypreview.tsx index 464ae20e0..8801e93ea 100644 --- a/frontend/app/view/directorypreview.tsx +++ b/frontend/app/view/directorypreview.tsx @@ -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: () => Mimetype, + header: () => Type, }), ]; -function DirectoryTable({ data, setFileName }: DirectoryTableProps) { +function DirectoryTable({ data, cwd, setFileName }: DirectoryTableProps) { const [columns] = React.useState(() => [...defaultColumns]); const table = useReactTable({ data, @@ -75,9 +76,9 @@ function DirectoryTable({ data, setFileName }: DirectoryTableProps) { ))} {table.getState().columnSizingInfo.isResizingColumn ? ( - + ) : ( - + )} ); @@ -85,10 +86,11 @@ function DirectoryTable({ data, setFileName }: DirectoryTableProps) { interface TableBodyProps { table: Table; + cwd: string; setFileName: (_: string) => void; } -function TableBody({ table, setFileName }: TableBodyProps) { +function TableBody({ table, cwd, setFileName }: TableBodyProps) { return (
{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) => ( -
- {cell.renderValue()} -
- ))} + {row.getVisibleCells().map((cell) => { + return ( +
+ {cell.renderValue()} +
+ ); + })}
))} @@ -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 ; + return ; } export { DirectoryPreview }; diff --git a/frontend/app/view/preview.tsx b/frontend/app/view/preview.tsx index e896baf8e..32de511d1 100644 --- a/frontend/app/view/preview.tsx +++ b/frontend/app/view/preview.tsx @@ -55,6 +55,7 @@ function StreamingPreview({ fileInfo }: { fileInfo: FileInfo }) { } function PreviewView({ blockId }: { blockId: string }) { + /* const blockData = WOS.useWaveObjectValueWithSuspense(WOS.makeORef("block", blockId)); if (blockData == null) { return ( @@ -63,6 +64,7 @@ function PreviewView({ blockId }: { blockId: string }) { ); } + */ const blockAtom = WOS.getWaveObjectAtom(`block:${blockId}`); const fileNameAtom: jotai.WritableAtom = useBlockCache(blockId, "preview:filename", () => jotai.atom( @@ -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 (
-
{jotai.useAtomValue(fileContentAtom)}
+
{fileContent}
); } diff --git a/pkg/service/fileservice/fileservice.go b/pkg/service/fileservice/fileservice.go index 0178d6f1b..c66c81d07 100644 --- a/pkg/service/fileservice/fileservice.go +++ b/pkg/service/fileservice/fileservice.go @@ -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(),