diff --git a/.gitignore b/.gitignore
index 4d29575..f6bce2f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
+/.idea
/node_modules
/.pnp
.pnp.js
@@ -17,6 +18,7 @@
.env.development.local
.env.test.local
.env.production.local
+.env
npm-debug.log*
yarn-debug.log*
diff --git a/package.json b/package.json
index b718922..0926812 100644
--- a/package.json
+++ b/package.json
@@ -11,11 +11,13 @@
"@types/node": "^16.7.13",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
+ "@types/uuid": "^8.3.4",
"gh-pages": "^4.0.0",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-scripts": "5.0.1",
"typescript": "^4.4.2",
+ "uuid": "^8.3.2",
"web-vitals": "^2.1.0"
},
"scripts": {
diff --git a/src/s1-main/App.tsx b/src/s1-main/App.tsx
index 99560a6..bea96f8 100644
--- a/src/s1-main/App.tsx
+++ b/src/s1-main/App.tsx
@@ -2,6 +2,7 @@ import React from 'react'
import s from './App.module.css'
import HW1 from '../s2-homeworks/hw01/HW1'
import HW2 from '../s2-homeworks/hw02/HW2'
+import HW3 from '../s2-homeworks/hw03/HW3'
const App = () => {
return (
@@ -9,7 +10,7 @@ const App = () => {
react homeworks:
- {/**/}
+
{/**/}
{/**/}
diff --git a/src/s2-homeworks/hw03/Greeting.module.css b/src/s2-homeworks/hw03/Greeting.module.css
new file mode 100644
index 0000000..1f9d5cf
--- /dev/null
+++ b/src/s2-homeworks/hw03/Greeting.module.css
@@ -0,0 +1,61 @@
+.greetingForm {
+ display: flex;
+ align-items: center;
+}
+
+.error {
+ position: absolute;
+ color: red;
+ margin-left: 10px;
+ margin-top: -14px;
+}
+
+.input {
+ margin: 10px;
+
+ background: #003300;
+ color: #99ff99;
+}
+
+.input:focus {
+ outline: none;
+ border: #99ff99 solid 2px;
+}
+
+.errorInput {
+ margin: 10px;
+
+ background: #003300;
+ color: #99ff99;
+
+ border: 2px solid red;
+ outline: none;
+}
+
+.button {
+ margin: 10px;
+ width: 60px;
+
+ background: #003300;
+ color: #99ff99;
+ outline: none;
+}
+.button:focus {
+ outline: #99ff99 solid 1px;
+}
+
+.button:active {
+ background: #99ff99;
+}
+
+.button:disabled {
+ color: #005500;
+}
+
+.count {
+ margin: 10px;
+}
+
+.greeting {
+ margin-left: 10px;
+}
\ No newline at end of file
diff --git a/src/s2-homeworks/hw03/Greeting.tsx b/src/s2-homeworks/hw03/Greeting.tsx
new file mode 100644
index 0000000..f92d8b2
--- /dev/null
+++ b/src/s2-homeworks/hw03/Greeting.tsx
@@ -0,0 +1,47 @@
+import React, {ChangeEvent, KeyboardEvent} from 'react'
+import s from './Greeting.module.css'
+
+type GreetingPropsType = {
+ name: string // need to fix any
+ setNameCallback: (e: ChangeEvent) => void // need to fix any
+ addUser: () => void // need to fix any
+ onEnter: (e: KeyboardEvent) => void
+ error: string // need to fix any
+ totalUsers: number // need to fix any
+ lastUser?: string // need to fix any
+}
+
+// презентационная компонента (для верстальщика)
+const Greeting: React.FC = (
+ {name, setNameCallback, addUser, onEnter, error, totalUsers, lastUser} // деструктуризация пропсов
+) => {
+ const inputClass = error ? s.errorInput : s.input // need to fix with (?:)
+
+ return (
+
+ )
+}
+
+export default Greeting
diff --git a/src/s2-homeworks/hw03/GreetingContainer.tsx b/src/s2-homeworks/hw03/GreetingContainer.tsx
new file mode 100644
index 0000000..ea5434b
--- /dev/null
+++ b/src/s2-homeworks/hw03/GreetingContainer.tsx
@@ -0,0 +1,59 @@
+import React, {ChangeEvent, KeyboardEvent, useState} from 'react'
+import Greeting from './Greeting'
+import {UserType} from './HW3'
+
+type GreetingContainerPropsType = {
+ users: UserType[] // need to fix any
+ addUserCallback: (name: string) => void // need to fix any
+}
+
+// более простой и понятный для новичков
+// function GreetingContainer(props: GreetingPropsType) {
+
+// более современный и удобный для про :)
+const GreetingContainer: React.FC = ({users, addUserCallback}) => { // деструктуризация пропсов
+ const [name, setName] = useState('') // need to fix any
+ const [error, setError] = useState('') // need to fix any
+
+ const setNameCallback = (e: ChangeEvent) => { // need to fix any // нельзя пробелы перед и после имени, можно в середине
+ const trimmedName = e.currentTarget.value.trim()
+
+ if (trimmedName) {
+ setName(trimmedName) // need to fix
+ setError('')
+ } else {
+ setName('')
+ setError('name is require!')
+ }
+ }
+ const addUser = () => {
+ addUserCallback(name)
+ setName('')
+ }
+
+ const onEnter = (e: KeyboardEvent) => {
+ if (e.key === 'Enter') {
+ if (name) {
+ addUser()
+ } else {
+ setError('name is require!')
+ }
+ }
+ }
+
+ const totalUsers = users.length // need to fix
+
+ return (
+
+ )
+}
+
+export default GreetingContainer
diff --git a/src/s2-homeworks/hw03/HW3.tsx b/src/s2-homeworks/hw03/HW3.tsx
new file mode 100644
index 0000000..9d104ad
--- /dev/null
+++ b/src/s2-homeworks/hw03/HW3.tsx
@@ -0,0 +1,39 @@
+import React, {useState} from 'react'
+import {v1} from 'uuid'
+import s from './Greeting.module.css'
+import GreetingContainer from './GreetingContainer'
+
+// types
+export type UserType = {
+ _id: string// need to fix any
+ name: string // need to fix any
+}
+
+const HW1 = () => {
+ const [users, setUsers] = useState([]) // need to fix any
+
+ const addUserCallback = (name: string) => { // need to fix any
+ const user = {
+ _id: v1(),
+ name,
+ }
+ setUsers([...users, user]) // need to fix
+ }
+
+ return (
+
+
+ {/*можно убрать этот тег*/}
+
+ {/*для автоматической проверки дз (не менять)*/}
+
+
+
+ {/*можно убрать этот тег*/}
+
+ {/*можно убрать этот тег*/}
+
+ )
+}
+
+export default HW1
diff --git a/yarn.lock b/yarn.lock
index 7db13c4..bebcda4 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2022,6 +2022,11 @@
resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.2.tgz#fc25ad9943bcac11cceb8168db4f275e0e72e756"
integrity sha512-F5DIZ36YVLE+PN+Zwws4kJogq47hNgX3Nx6WyDJ3kcplxyke3XIzB8uK5n/Lpm1HBsbGzd6nmGehL8cPekP+Tg==
+"@types/uuid@^8.3.4":
+ version "8.3.4"
+ resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc"
+ integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==
+
"@types/ws@^8.5.1":
version "8.5.3"
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.3.tgz#7d25a1ffbecd3c4f2d35068d0b283c037003274d"