in case if someone comes back or if you wanna see @onyx ember , this worked perfectly.
"use client"
import {
type CommandHistory,
TerminalHistory
} from "@/components/TerminalHistory"
import TerminalInput from "@/components/TerminalInput"
import TerminalPrompt from "@/components/TerminalPrompt"
import commands from "@/utilities/commands"
import { type ChangeEvent, type FormEvent, useEffect, useState } from "react"
export default function Terminal() {
const [command, setCommand] = useState("")
const [commandHistory, setCommandHistory] = useState<CommandHistory[]>([])
useEffect(() => {
const storedCommandHistory = localStorage.getItem("commandHistory")
if (storedCommandHistory) {
setCommandHistory(JSON.parse(storedCommandHistory))
}
}, [])
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
setCommand(e.target.value)
}
const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
e.preventDefault()
const trimmedCommand = command.trim().toLowerCase()
const response = commands[trimmedCommand] || "Unknown command"
const currentTimestamp = new Date()
const id = currentTimestamp.getTime().toString()
const updatedCommandHistory = [
...commandHistory,
{ id, timestamp: currentTimestamp, command: trimmedCommand, response }
]
setCommandHistory(updatedCommandHistory)
localStorage.setItem(
"commandHistory",
JSON.stringify(updatedCommandHistory)
)
setCommand("")
}
return (
<main className="h-full border-2 rounded-md p-4 overflow-auto text-xs sm:text-sm md:text-base border-[#98971a] bg-[#282828] text-[#ebdbb2]">
<TerminalPrompt username="david" />
<div className="flex flex-col">
<TerminalHistory commandHistory={commandHistory} />
<TerminalInput
command={command}
onInputChange={handleInputChange}
onSubmit={handleSubmit}
/>
</div>
</main>
)
}