From 8659f0f2db34ac504dcbc6d1c58efa3cfcac4d39 Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Wed, 19 Feb 2025 22:09:05 -0800 Subject: [PATCH 1/6] deno outdated --update --latest --- deno.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deno.json b/deno.json index a9509f4..9657e22 100644 --- a/deno.json +++ b/deno.json @@ -24,7 +24,7 @@ ], "imports": { "$fresh/": "https://deno.land/x/fresh@1.7.3/", - "@swanfactory/hclang": "jsr:@swanfactory/hclang@^0.6.9", + "@swanfactory/hclang": "jsr:@swanfactory/hclang@^0.7.1", "preact": "https://esm.sh/preact@10.22.0", "preact/": "https://esm.sh/preact@10.22.0/", "@preact/signals": "https://esm.sh/*@preact/signals@1.2.2", From 08ec3b185e1c09ae5eb408ab0f54d228c3471cc3 Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Wed, 19 Feb 2025 22:13:39 -0800 Subject: [PATCH 2/6] execute! --- islands/Interpreter.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/islands/Interpreter.tsx b/islands/Interpreter.tsx index 8393ae2..3cb2714 100644 --- a/islands/Interpreter.tsx +++ b/islands/Interpreter.tsx @@ -1,11 +1,11 @@ import { useState } from "preact/hooks"; -// import { execute } from "@swanfactory/hclang"; +import { execute } from "@swanfactory/hclang"; function evaluateCode(code: string): string { console.log(`Evaluating code: ${code}`); - // console.log(execute); + console.log(execute); try { - const result = code.toUpperCase(); + const result = execute(code); console.log(`Result: ${result}`); return result.toString(); } catch (error: unknown) { From 27309fa9be8c848cd7c1d1bdb908dbb2cd756ba1 Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar (aider)" <19791+drernie@users.noreply.github.com> Date: Wed, 19 Feb 2025 22:18:35 -0800 Subject: [PATCH 3/6] feat: Add code history tracking with localStorage persistence --- islands/Interpreter.tsx | 53 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/islands/Interpreter.tsx b/islands/Interpreter.tsx index 3cb2714..0d36ac3 100644 --- a/islands/Interpreter.tsx +++ b/islands/Interpreter.tsx @@ -1,6 +1,12 @@ -import { useState } from "preact/hooks"; +import { useState, useEffect } from "preact/hooks"; import { execute } from "@swanfactory/hclang"; +interface HistoryItem { + code: string; + result: string; + timestamp: number; +} + function evaluateCode(code: string): string { console.log(`Evaluating code: ${code}`); console.log(execute); @@ -19,6 +25,14 @@ export default function Interpreter() { const [error, setError] = useState(""); const [isLoading, setIsLoading] = useState(false); const [result, setResult] = useState(""); + const [history, setHistory] = useState([]); + + useEffect(() => { + const savedHistory = localStorage.getItem('hc-history'); + if (savedHistory) { + setHistory(JSON.parse(savedHistory)); + } + }, []); const handleEvaluation = (code: string): void => { setError(""); @@ -26,6 +40,16 @@ export default function Interpreter() { try { const evalResult = evaluateCode(code); setResult(evalResult); + + const newHistoryItem = { + code, + result: evalResult, + timestamp: Date.now() + }; + + const updatedHistory = [newHistoryItem, ...history].slice(0, 50); // Keep last 50 items + setHistory(updatedHistory); + localStorage.setItem('hc-history', JSON.stringify(updatedHistory)); } catch (e: unknown) { setError(e instanceof Error ? e.message : String(e)); } finally { @@ -33,6 +57,10 @@ export default function Interpreter() { } }; + const handleHistoryClick = (historyItem: HistoryItem) => { + setText((prev) => prev + "\n" + historyItem.code); + }; + return (