'use client'; import About from '@/components/About'; import { Contact } from '@/components/Contact'; import Experience from '@/components/Experience'; import Projects from '@/components/Projects'; import React, { useState, useEffect, useRef } from 'react'; export default function Home() { const [input, setInput] = useState(''); const [output, setOutput] = useState([ 'ShrimpTerm v1.0.0', "Type 'help' for a list of commands.", 'Press Tab for autocomplete, Escape to clear the current input.', ]); const [suggestion, setSuggestion] = useState(''); const inputRef = useRef(null); const keyAudio = useRef(null); const enterAudio = useRef(null); useEffect(() => { keyAudio.current = new Audio('/key.mp3'); keyAudio.current.volume = 0.1; enterAudio.current = new Audio('/enter.mp3'); enterAudio.current.volume = 0.1; inputRef.current?.focus(); }, []); const commands = [ 'help', 'about', 'clear', 'projects', 'experience', 'contact', 'back', ]; const handleInput = (e: React.ChangeEvent) => { const { value } = e.target; setInput(value); if (value.trim().length < 3) { setSuggestion(''); return; } const matchedCommand = commands.find((command) => command.startsWith(value.trim().toLowerCase()), ); setSuggestion(matchedCommand || ''); }; const processCommand = (command: string) => { switch (command.trim().toLowerCase()) { case 'help': setOutput((prevOutput) => [ ...prevOutput, 'Available commands (click to autocomplete):', createCommandButton( 'help', 'Help (this command) - List available commands', ), createCommandButton( 'about', 'About - Learn more about Sticks and his projects', ), createCommandButton( 'projects', 'Projects - List of projects created by Sticks', ), createCommandButton( 'experience', "Experience - View Sticks's experience", ), createCommandButton( 'contact', 'Contact - Get in touch with Sticks', ), createCommandButton( 'back', 'Back - Return to the home page', ), createCommandButton('clear', 'Clear - Clear the screen'), ]); break; case 'about': setOutput((prevOutput) => [ ...prevOutput, , ]); break; case 'projects': setOutput((prevOutput) => [ ...prevOutput, , ]); break; case 'experience': setOutput((prevOutput) => [ ...prevOutput, , ]); break; case 'back': window.location.href = '/home'; break; case 'contact': setOutput((prevOutput) => [ ...prevOutput, , ]); break; case 'clear': setOutput([ 'ShrimpTerm v1.0.0', "Type 'help' for a list of commands.", 'Press Tab for autocomplete, Escape to clear the current input.', ]); break; default: setOutput((prevOutput) => [ ...prevOutput,
Error:{' '} {command} is not a valid command or batch file.
, ]); } }; const handleCommandInput = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { enterAudio.current?.play(); setOutput((prevOutput) => [...prevOutput, `S:\\> ${input}.exe`]); processCommand(input); setInput(''); setSuggestion(''); } else if (e.key === 'Tab' && suggestion) { e.preventDefault(); keyAudio.current?.play(); setInput(suggestion); setSuggestion(''); } else if (e.key === 'Escape') { keyAudio.current?.play(); setInput(''); setSuggestion(''); } else { keyAudio.current?.play(); } }; const createCommandButton = (command: string, label: string) => (
); return (
< Back {output.map((line, index) => (

{line}

))}

{input && suggestion ? suggestion : ''}

); }