Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

WorkspaceFilePreviewError.tsx

54 lines1.9 KB

1import type { EnvironmentId } from "@t3tools/contracts";
2import { useCallback } from "react";
3import { View } from "react-native";
4​
5import { EmptyState } from "../../components/ui/EmptyState";
6import { environmentCatalog } from "../../connection/catalog";
7import type { AssetUrlFailureReason } from "../../state/asset-url-state";
8import { useAtomCommand } from "../../state/use-atom-command";
9import { useEnvironmentPresentation } from "../../state/presentation";
10import { EnvironmentConnectionNotice } from "../connection/EnvironmentConnectionNotice";
11​
12export function WorkspaceFilePreviewError(props: {
13 readonly environmentId: EnvironmentId | null;
14 readonly reason: AssetUrlFailureReason;
15 readonly onRetry: () => void;
16}) {
17 const { environmentId, onRetry } = props;
18 const environment = useEnvironmentPresentation(environmentId);
19 const retryEnvironment = useAtomCommand(environmentCatalog.retryNow, "environment retry");
20 const retryConnection = useCallback(() => {
21 if (environmentId !== null) void retryEnvironment(environmentId);
22 onRetry();
23 }, [environmentId, onRetry, retryEnvironment]);
24​
25 if (props.reason === "disconnected") {
26 return (
27 <View className="flex-1 bg-sheet">
28 <EnvironmentConnectionNotice
29 environmentLabel={environment.presentation?.entry.target.label ?? "Environment"}
30 connection={
31 environment.presentation?.connection ?? {
32 phase: "available",
33 error: null,
34 traceId: null,
35 }
36 }
37 resourceName="preview"
38 onRetry={retryConnection}
39 />
40 </View>
41 );
42 }
43​
44 return (
45 <View className="flex-1 items-center justify-center bg-sheet px-6">
46 <EmptyState
47 title="Preview unavailable"
48 detail="This file may be missing, unsupported, or unavailable on this environment."
49 actionLabel="Try again"
50 onAction={props.onRetry}
51 />
52 </View>
53 );