File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -21,10 +21,12 @@ function useTerminalSize() {
2121
2222// Component to open a sandbox by ID
2323export function Dashboard ( ) {
24+ const { apiClient } = useSDK ( ) ;
25+
2426 // Poll getRunningVms API every 2 seconds
2527 const runningVmsQuery = useQuery ( {
2628 queryKey : [ "runningVms" ] ,
27- queryFn : getRunningVms ,
29+ queryFn : ( ) => getRunningVms ( apiClient ) ,
2830 } ) ;
2931
3032 const [ sandboxId , setSandboxId ] = useState ( "" ) ;
@@ -103,11 +105,11 @@ const Sandbox = memo(
103105 } ) => {
104106 const sandboxQuery = useQuery ( {
105107 queryKey : [ "sandbox" , id ] ,
106- queryFn : ( ) => getSandbox ( id ) ,
108+ queryFn : ( ) => getSandbox ( apiClient , id ) ,
107109 } ) ;
108110 const runningStateRef = useRef ( runningState ) ;
109111
110- const sdk = useSDK ( ) ;
112+ const { sdk, apiClient } = useSDK ( ) ;
111113
112114 // Only two states: RUNNING or IDLE
113115 const [ sandboxState , setSandboxState ] = useState <
Original file line number Diff line number Diff line change 11import * as React from "react" ;
22import { createContext , useContext } from "react" ;
33import { CodeSandbox } from "@codesandbox/sdk" ;
4+ import { createApiClient } from "../../utils/api" ;
5+ import { Client } from "@hey-api/client-fetch" ;
6+ import { getInferredApiKey } from "../../utils/constants" ;
7+ import { instrumentedFetch } from "../utils/sentry" ;
48
59const sdk = new CodeSandbox ( ) ;
610
7- export const SDKContext = createContext < CodeSandbox > ( sdk ) ;
11+ const apiKey = getInferredApiKey ( ) ;
12+ const apiClient : Client = createApiClient ( apiKey , { } , instrumentedFetch ) ;
13+
14+ export const SDKContext = createContext < { sdk : CodeSandbox ; apiClient : Client } > ( {
15+ sdk,
16+ apiClient,
17+ } ) ;
18+
819
920export const SDKProvider = ( { children } : { children : React . ReactNode } ) => {
10- return < SDKContext . Provider value = { sdk } > { children } </ SDKContext . Provider > ;
21+ return (
22+ < SDKContext . Provider value = { { sdk, apiClient } } >
23+ { children }
24+ </ SDKContext . Provider >
25+ ) ;
1126} ;
1227
1328export function useSDK ( ) {
You can’t perform that action at this time.
0 commit comments