11//This ensures that the component is only rendered on the client side
2- ' use client' ;
2+ " use client" ;
33import React , { useState , useEffect , useRef } from "react" ;
44import { useRouter } from "next/navigation" ;
55import { MdOutlineTerminal } from "react-icons/md" ;
66import TerminalInput from "@/components/terminal/TerminalInput" ;
77import TerminalHistory from "@/components/terminal/TerminalHistory" ;
8- import AboutCommand from "@/components/terminal/commands/AboutCommand"
9- import ContactCommand from "@/components/terminal/commands/ContactCommand"
8+ import AboutCommand from "@/components/terminal/commands/AboutCommand" ;
9+ import ContactCommand from "@/components/terminal/commands/ContactCommand" ;
1010import SwitchUser from "@/components/terminal/commands/SwitchUser" ;
1111import ShowProjects from "@/components/terminal/commands/ShowProjects" ;
1212import ManCommand from "@/components/terminal/commands/ManCommand" ;
1313import CowSay from "@/components/terminal/commands/CowSayCommand" ;
14- import { asciiArtDesktop , asciiArtMobile } from "@/components/terminal/asciiArt" ;
14+ import {
15+ asciiArtDesktop ,
16+ asciiArtMobile ,
17+ } from "@/components/terminal/asciiArt" ;
1518
1619export default function TerminalPage ( ) {
17-
1820 const router = useRouter ( ) ;
1921 const [ name , switchUser ] = useState ( "guest" ) ;
2022 const [ input , setInput ] = useState ( "" ) ;
21- const [ history , setHistory ] = useState ( [ {
22- id : Date . now ( ) ,
23- command : "" ,
24- name : "" ,
25- text : typeof window !== "undefined" && window . innerWidth < 768
26- ? asciiArtMobile
27- : asciiArtDesktop
28- } ] ) ;
29-
23+ const [ history , setHistory ] = useState ( [
24+ {
25+ id : Date . now ( ) ,
26+ command : "" ,
27+ name : "" ,
28+ text :
29+ typeof window !== "undefined" && window . innerWidth < 768
30+ ? asciiArtMobile
31+ : asciiArtDesktop ,
32+ } ,
33+ ] ) ;
34+
3035 const terminalRef = useRef ( null ) ;
3136 const inputRef = useRef ( null ) ;
3237
@@ -44,79 +49,87 @@ export default function TerminalPage() {
4449 command : cmd ,
4550 text : "" ,
4651 } ;
47-
48-
52+
4953 if ( cmd === "clear" ) {
50- setHistory ( [ {
51- id : Date . now ( ) ,
52- command : "" ,
53- name : "" ,
54- text : typeof window !== "undefined" && window . innerWidth < 768
55- ? asciiArtMobile
56- : asciiArtDesktop
57- } ] ) ;
54+ setHistory ( [
55+ {
56+ id : Date . now ( ) ,
57+ command : "" ,
58+ name : "" ,
59+ text :
60+ typeof window !== "undefined" && window . innerWidth < 768
61+ ? asciiArtMobile
62+ : asciiArtDesktop ,
63+ } ,
64+ ] ) ;
5865 setInput ( "" ) ;
59- return ;
66+ return ;
6067 } else if ( cmd === "about" ) {
6168 entry . text = AboutCommand ;
6269 } else if ( cmd === "contact" ) {
6370 entry . text = ContactCommand ;
6471 } else if ( cmd . startsWith ( "project" ) ) {
6572 entry . text = ShowProjects ( { cmd } ) ;
6673 } else if ( cmd . startsWith ( "su" ) ) {
67- entry . text = SwitchUser ( { cmd, switchUser} ) ;
74+ entry . text = SwitchUser ( { cmd, switchUser } ) ;
6875 } else if ( cmd . startsWith ( "man" ) ) {
6976 entry . text = ManCommand ( { cmd } ) ;
7077 } else if ( cmd . startsWith ( "cowsay" ) ) {
7178 entry . text = CowSay ( { cmd } ) ;
72- } else if ( cmd === "whoami" ) {
73- entry . text = name
79+ } else if ( cmd === "whoami" ) {
80+ entry . text = name ;
7481 } else {
7582 entry . text = `Command not found: ${ cmd } ` ;
7683 }
7784
7885 entry . name = name ;
79- setHistory ( prev => [ ...prev , entry ] ) ;
86+ setHistory ( ( prev ) => [ ...prev , entry ] ) ;
8087 setInput ( "" ) ;
81- }
88+ } ;
8289
83- const onKeyDown = ( e ) => {
90+ const onKeyDown = ( e ) => {
8491 if ( e . key === "Enter" ) {
8592 handleCommand ( input . trim ( ) ) ;
8693 }
8794 } ;
8895
89- return (
90- < div className = "min-h-screen bg-black text-white p-4 font-mono"
96+ return (
97+ < div
98+ className = "min-h-screen bg-black text-white p-4 font-mono"
9199 style = { {
92100 maxWidth : "100vw" ,
93101 overflowX : "auto" ,
94- fontSize : "1em"
95- } } >
102+ fontSize : "1em" ,
103+ } }
104+ >
96105 < div className = "flex items-center justify-between mb-4" >
97106 < h1 className = "text-2xl" > Finn van Montfort's Portfolio</ h1 >
98107 < button
99108 aria-label = "Switch to Bauhaus"
100109 onClick = { ( ) => router . push ( "/Bauhaus" ) }
101- > < MdOutlineTerminal size = { 32 } className = "text-white hover:text-green-400 transition-colors" /> </ button >
102-
110+ >
111+ < MdOutlineTerminal
112+ size = { 32 }
113+ className = "text-white hover:text-green-400 transition-colors"
114+ />
115+ </ button >
103116 </ div >
104117 < div
105118 ref = { terminalRef }
106119 className = "mt-2 w-full overflow-x-auto whitespace-pre-wrap"
107120 style = { { maxWidth : "100%" , height : "60vh" , position : "relative" } }
108121 >
109122 < div text = "white" className = "mt-2" >
110- < TerminalHistory history = { history } />
123+ < TerminalHistory history = { history } />
111124 < TerminalInput
112125 name = { name }
113126 input = { input }
114- onChange = { e => setInput ( e . target . value ) }
127+ onChange = { ( e ) => setInput ( e . target . value ) }
115128 onKeyDown = { onKeyDown }
116129 inputRef = { inputRef }
117130 />
118131 </ div >
119132 </ div >
120133 </ div >
121- )
122- }
134+ ) ;
135+ }
0 commit comments