-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* lift exec into layout; fix cancel button * add iterations to results * fix cfg saving to localstorage; fix nested <a> * fix card styling * add sample tab * stop it vscode * super dumb debugger * fix dumb linting rule
- Loading branch information
Showing
37 changed files
with
1,840 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use client"; | ||
import React, { createContext, ReactNode } from "react"; | ||
import { Executor, ExecutorSupplier, NullExecutor, ServerExecutor } from "@srsim/executor"; | ||
|
||
type ExecutorContextProviderProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
type ExecutorContextType = { | ||
supplier: ExecutorSupplier<Executor>; | ||
}; | ||
|
||
export const ExecutorContext = createContext<ExecutorContextType>({ | ||
supplier: () => { | ||
return new NullExecutor(); | ||
}, | ||
}); | ||
|
||
let exec: ServerExecutor | undefined; | ||
const urlKey = "server-mode-url"; | ||
const defaultURL = "http://127.0.0.1:54321"; | ||
|
||
export const ExecutorProvider = ({ children }: ExecutorContextProviderProps) => { | ||
const [url, setURL] = React.useState<string>(defaultURL); | ||
React.useEffect(() => { | ||
if (typeof window !== "undefined") { | ||
const saved = window.localStorage.getItem(urlKey); | ||
if (saved === null) { | ||
window.localStorage.setItem(urlKey, defaultURL); | ||
return; | ||
} | ||
setURL(saved); | ||
} | ||
}, []); | ||
React.useEffect(() => { | ||
if (typeof window !== "undefined") { | ||
window.localStorage.setItem(urlKey, url); | ||
} | ||
if (exec != null) { | ||
exec.set_url(url); | ||
} | ||
}, [url]); | ||
const supplier = React.useRef<ExecutorSupplier<Executor>>(() => { | ||
if (exec == null) { | ||
exec = new ServerExecutor(url); | ||
} | ||
return exec; | ||
}); | ||
return ( | ||
<ExecutorContext.Provider value={{ supplier: supplier.current }}> | ||
{children} | ||
</ExecutorContext.Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.