diff --git a/README.md b/README.md index 415bb6e4e..7d715e069 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,4 @@ Make the `App` a class component with `pressedKey` in the `state`. - Implement a solution following the [React task guideline](https://github.com/mate-academy/react_task-guideline#react-tasks-guideline). - Use the [React TypeScript cheat sheet](https://mate-academy.github.io/fe-program/js/extra/react-typescript). - Open one more terminal and run tests with `npm test` to ensure your solution is correct. -- Replace `` with your Github username in the [DEMO LINK](https://.github.io/react_keyboard/) and add it to the PR description. +- Replace `` with your Github username in the [DEMO LINK](https://GGLUTT.github.io/react_keyboard/) and add it to the PR description. diff --git a/package-lock.json b/package-lock.json index 89cb98f0f..5f479bac3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ }, "devDependencies": { "@cypress/react18": "^2.0.1", - "@mate-academy/scripts": "^1.8.5", + "@mate-academy/scripts": "^1.9.12", "@mate-academy/students-ts-config": "*", "@mate-academy/stylelint-config": "*", "@types/node": "^20.14.10", @@ -1170,9 +1170,9 @@ } }, "node_modules/@mate-academy/scripts": { - "version": "1.8.5", - "resolved": "https://registry.npmjs.org/@mate-academy/scripts/-/scripts-1.8.5.tgz", - "integrity": "sha512-mHRY2FkuoYCf5U0ahIukkaRo5LSZsxrTSgMJheFoyf3VXsTvfM9OfWcZIDIDB521kdPrScHHnRp+JRNjCfUO5A==", + "version": "1.9.12", + "resolved": "https://registry.npmjs.org/@mate-academy/scripts/-/scripts-1.9.12.tgz", + "integrity": "sha512-/OcmxMa34lYLFlGx7Ig926W1U1qjrnXbjFJ2TzUcDaLmED+A5se652NcWwGOidXRuMAOYLPU2jNYBEkKyXrFJA==", "dev": true, "dependencies": { "@octokit/rest": "^17.11.2", diff --git a/package.json b/package.json index a727a0799..d272a7366 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ }, "devDependencies": { "@cypress/react18": "^2.0.1", - "@mate-academy/scripts": "^1.8.5", + "@mate-academy/scripts": "^1.9.12", "@mate-academy/students-ts-config": "*", "@mate-academy/stylelint-config": "*", "@types/node": "^20.14.10", diff --git a/src/App.tsx b/src/App.tsx index f819cbdb9..ca86ecc9d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,38 @@ -import React from 'react'; +import React, { Component } from 'react'; -export const App: React.FC = () => ( -
-

The last pressed key is [Enter]

-
-); +interface AppState { + pressedKey: string; +} + +class App extends Component<{}, AppState> { + state: AppState = { + pressedKey: 'Nothing was pressed yet' + }; + + + handleKeyUp = (event: KeyboardEvent) => { + this.setState({ pressedKey: event.key }); + }; + + componentDidMount() { + document.addEventListener('keyup', this.handleKeyUp); + } + + componentWillUnmount() { + document.removeEventListener('keyup', this.handleKeyUp); + } + + render() { + return ( +
+

+ {this.state.pressedKey === 'Nothing was pressed yet' + ? 'Nothing was pressed yet' + : `The last pressed key is [${this.state.pressedKey}]`} +

+
+ ); + } +} + +export default App; diff --git a/src/index.tsx b/src/index.tsx index 7d27337cd..f2f33cccc 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,5 +1,5 @@ import { createRoot } from 'react-dom/client'; -import { App } from './App'; +import App from './App'; import './index.scss';