Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
isMarkdownPreviewFile,
isSvgImagePreviewFile,
isVideoPreviewFile,
needsWorkspaceFileContents,
} from "./filePath";
import { useWorkspaceFileAssetUrlState } from "./workspaceFileAssetUrl";

Expand Down Expand Up @@ -707,15 +708,12 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
const handleRetryPreview = () => {
void assetPreview.refresh().finally(() => setPreviewRevision((current) => current + 1));
};
const needsFileContents =
!metadataPending &&
directoryPath === null &&
relativePath !== null &&
!isVideoFile &&
!isAudioFile &&
(resolvedActiveMode === "source" ||
isMarkdownPreviewFile(relativePath) ||
filePreviewDelimiter({ name: relativePath }) !== null);
// Metadata is needed only to distinguish directories; file contents can load concurrently.
const needsFileContents = needsWorkspaceFileContents({
relativePath,
metadataKind: metadata.data?.kind,
activeMode: resolvedActiveMode,
});
const fileQuery = useEnvironmentQuery(
canReadFiles &&
environmentId !== null &&
Expand Down
9 changes: 9 additions & 0 deletions apps/mobile/src/features/files/filePath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, it } from "vite-plus/test";

import {
fileRoutePathSegments,
needsWorkspaceFileContents,
resolveFileLinkPath,
resolveWorkspaceRelativeFilePath,
} from "./filePath";
Expand Down Expand Up @@ -49,3 +50,11 @@ describe("resolveWorkspaceRelativeFilePath", () => {
expect(resolveWorkspaceRelativeFilePath(null, "/repo/main.ts")).toBeNull();
});
});

describe("needsWorkspaceFileContents", () => {
it("reads a text file while its metadata is still pending, but not a directory", () => {
const input = { relativePath: "package.json", activeMode: "source" } as const;
expect(needsWorkspaceFileContents({ ...input, metadataKind: undefined })).toBe(true);
expect(needsWorkspaceFileContents({ ...input, metadataKind: "directory" })).toBe(false);
});
});
19 changes: 19 additions & 0 deletions apps/mobile/src/features/files/filePath.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { FilesystemEntryMetadata } from "@t3tools/contracts";
import { filePreviewDelimiter } from "@t3tools/shared/delimitedPreview";
import { joinPath, resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
import {
isWorkspaceAudioPreviewPath,
Expand Down Expand Up @@ -109,6 +111,23 @@ export function isMarkdownPreviewFile(path: string): boolean {
return /\.(?:md|mdx)$/i.test(path.split(/[?#]/, 1)[0] ?? "");
}

export function needsWorkspaceFileContents(input: {
readonly relativePath: string | null;
readonly metadataKind: FilesystemEntryMetadata["kind"] | undefined;
readonly activeMode: "preview" | "source";
}): boolean {
const path = input.relativePath;
return (
input.metadataKind !== "directory" &&
path !== null &&
!isVideoPreviewFile(path) &&
!isAudioPreviewFile(path) &&
(input.activeMode === "source" ||
isMarkdownPreviewFile(path) ||
filePreviewDelimiter({ name: path }) !== null)
);
}

export function fileHeaderSubtitle(projectName: string, relativePath: string): string {
const parentDir = relativePath.slice(
0,
Expand Down
Loading