+
+
+
+
+
@@ -532,6 +554,28 @@ exports[`App renders the log visualizer when text is pasted 2`] = `
Clear
+
+
+
+
+
diff --git a/src/components.tsx b/src/components.tsx
index 7050a7d..9f7fd02 100644
--- a/src/components.tsx
+++ b/src/components.tsx
@@ -69,6 +69,8 @@ type HelperArg = {
name: string | null;
};
+export type StoredLogs = [string, string[]][];
+
function isVoidHelperArg(arg: HelperArg) {
return arg.type === "void" && arg.name === null && arg.star === null;
}
@@ -200,33 +202,53 @@ declare global {
}
export function Examples({
+ storedLogs,
handleLoadExample,
}: {
- handleLoadExample: (exampleLink: string) => Promise
;
+ storedLogs: StoredLogs;
+ handleLoadExample: (example: string, isLink: boolean) => Promise;
}) {
const exampleLinks: [string, string][] = globalThis.exampleLinks || [];
- const [selectedOption, setSelectedOption] = useState(
- exampleLinks.length ? exampleLinks[0][1] : "",
+ const hasStoredLogs = storedLogs.length !== 0;
+
+ const [selectedOption, setSelectedOption] = useState("");
+
+ useEffect(() => {
+ setSelectedOption(
+ hasStoredLogs
+ ? storedLogs[0][0]
+ : exampleLinks.length
+ ? exampleLinks[0][1]
+ : "",
+ );
+ }, [storedLogs]);
+
+ const handleChange = useCallback(
+ (event: ChangeEvent) => {
+ setSelectedOption(event.target.value);
+ },
+ [storedLogs],
);
- const handleChange = useCallback((event: ChangeEvent) => {
- setSelectedOption(event.target.value);
- }, []);
const onLoad = useCallback(() => {
- handleLoadExample(selectedOption);
+ handleLoadExample(selectedOption, !hasStoredLogs);
}, [selectedOption]);
- if (exampleLinks && exampleLinks.length !== 0) {
+ const loadableLogs = hasStoredLogs
+ ? storedLogs.map((x) => [x[0], x[0]])
+ : exampleLinks;
+
+ if (loadableLogs && loadableLogs.length !== 0) {
return (
-
+