Skip to content
Merged
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
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/bin/ui/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ function useTerminalSize() {

// Component to open a sandbox by ID
export function Dashboard() {
const { apiClient } = useSDK();

// Poll getRunningVms API every 2 seconds
const runningVmsQuery = useQuery({
queryKey: ["runningVms"],
queryFn: getRunningVms,
queryFn: () => getRunningVms(apiClient),
});

const [sandboxId, setSandboxId] = useState("");
Expand Down Expand Up @@ -103,11 +105,11 @@ const Sandbox = memo(
}) => {
const sandboxQuery = useQuery({
queryKey: ["sandbox", id],
queryFn: () => getSandbox(id),
queryFn: () => getSandbox(apiClient, id),
});
const runningStateRef = useRef(runningState);

const sdk = useSDK();
const { sdk, apiClient } = useSDK();

// Only two states: RUNNING or IDLE
const [sandboxState, setSandboxState] = useState<
Expand Down
19 changes: 17 additions & 2 deletions src/bin/ui/sdkContext.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import * as React from "react";
import { createContext, useContext } from "react";
import { CodeSandbox } from "@codesandbox/sdk";
import { createApiClient } from "../../utils/api";
import { Client } from "@hey-api/client-fetch";
import { getInferredApiKey } from "../../utils/constants";
import { instrumentedFetch } from "../utils/sentry";

const sdk = new CodeSandbox();

export const SDKContext = createContext<CodeSandbox>(sdk);
const apiKey = getInferredApiKey();
const apiClient: Client = createApiClient(apiKey, {}, instrumentedFetch);

export const SDKContext = createContext<{ sdk: CodeSandbox; apiClient: Client }>({
sdk,
apiClient,
});


export const SDKProvider = ({ children }: { children: React.ReactNode }) => {
return <SDKContext.Provider value={sdk}>{children}</SDKContext.Provider>;
return (
<SDKContext.Provider value={{ sdk, apiClient }}>
{children}
</SDKContext.Provider>
);
};

export function useSDK() {
Expand Down