Bläddra i källkod

added 21st hometask

Ata 4 år sedan
förälder
incheckning
c5aac64e14
55 ändrade filer med 17270 tillägg och 49 borttagningar
  1. 1 1
      react/hw19-react/src/App/App.jsx
  2. 1 1
      react/hw20-react/.eslintcache
  3. 1 0
      react/hw20-react/debug.log
  4. 29 10
      react/hw20-react/src/App/App.jsx
  5. 10 0
      react/hw20-react/src/components/Button/style.css
  6. 1 2
      react/hw20-react/src/containers/Form/style.css
  7. 16 35
      react/hw20-react/src/containers/Modal/Modal.jsx
  8. 1 0
      react/hw21-react/.eslintcache
  9. 23 0
      react/hw21-react/.gitignore
  10. 70 0
      react/hw21-react/README.md
  11. 16444 0
      react/hw21-react/package-lock.json
  12. 39 0
      react/hw21-react/package.json
  13. BIN
      react/hw21-react/public/favicon.ico
  14. 43 0
      react/hw21-react/public/index.html
  15. BIN
      react/hw21-react/public/logo192.png
  16. BIN
      react/hw21-react/public/logo512.png
  17. 25 0
      react/hw21-react/public/manifest.json
  18. 3 0
      react/hw21-react/public/robots.txt
  19. 36 0
      react/hw21-react/src/App/App.jsx
  20. 2 0
      react/hw21-react/src/App/index.js
  21. 6 0
      react/hw21-react/src/App/style.css
  22. 17 0
      react/hw21-react/src/components/Button/Button.jsx
  23. 2 0
      react/hw21-react/src/components/Button/index.js
  24. 10 0
      react/hw21-react/src/components/Button/style.css
  25. 22 0
      react/hw21-react/src/components/Input/Input.jsx
  26. 2 0
      react/hw21-react/src/components/Input/index.js
  27. 14 0
      react/hw21-react/src/components/Label/Label.jsx
  28. 2 0
      react/hw21-react/src/components/Label/index.js
  29. 0 0
      react/hw21-react/src/components/Label/style.css
  30. 40 0
      react/hw21-react/src/containers/Card/Card.jsx
  31. 2 0
      react/hw21-react/src/containers/Card/index.js
  32. 9 0
      react/hw21-react/src/containers/Card/style.css
  33. 10 0
      react/hw21-react/src/containers/Footer/Footer.jsx
  34. 2 0
      react/hw21-react/src/containers/Footer/index.js
  35. 7 0
      react/hw21-react/src/containers/Footer/style.css
  36. 59 0
      react/hw21-react/src/containers/Form/Form.jsx
  37. 2 0
      react/hw21-react/src/containers/Form/index.js
  38. 17 0
      react/hw21-react/src/containers/Form/style.css
  39. 22 0
      react/hw21-react/src/containers/Main/Main.jsx
  40. 2 0
      react/hw21-react/src/containers/Main/index.js
  41. 6 0
      react/hw21-react/src/containers/Main/style.css
  42. 56 0
      react/hw21-react/src/containers/Modal/Modal.jsx
  43. 2 0
      react/hw21-react/src/containers/Modal/index.js
  44. 19 0
      react/hw21-react/src/containers/Modal/style.css
  45. 19 0
      react/hw21-react/src/containers/Search/Search.jsx
  46. 2 0
      react/hw21-react/src/containers/Search/index.js
  47. 7 0
      react/hw21-react/src/containers/Search/style.css
  48. 57 0
      react/hw21-react/src/containers/UsersComponent/UsersComponent.jsx
  49. 2 0
      react/hw21-react/src/containers/UsersComponent/index.js
  50. 6 0
      react/hw21-react/src/containers/UsersComponent/style.css
  51. 13 0
      react/hw21-react/src/index.css
  52. 12 0
      react/hw21-react/src/index.js
  53. 3 0
      react/hw21-react/src/state/UsersContex.js
  54. 70 0
      react/hw21-react/src/state/UsersReducer.js
  55. 4 0
      react/hw21-react/src/state/index.js

+ 1 - 1
react/hw19-react/src/App/App.jsx

@@ -23,7 +23,7 @@ const App = () => {
      setValueInput(value);
     
       const result = userData.filter(user => {
-        debugger;
+       
         return user.name.toLocaleLowerCase().includes(value.toLocaleLowerCase())
   
       })

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
react/hw20-react/.eslintcache


+ 1 - 0
react/hw20-react/debug.log

@@ -0,0 +1 @@
+[1215/191719.703:ERROR:directory_reader_win.cc(43)] FindFirstFile: Ñèñòåìå íå óäàåòñÿ íàéòè óêàçàííûé ïóòü. (0x3)

+ 29 - 10
react/hw20-react/src/App/App.jsx

@@ -3,7 +3,7 @@ import './style.css';
 import React from "react";
 
 
-import {useState, useEffect} from 'react';
+import {useState} from 'react';
 import Main from '../containers/Main'
 import Footer from '../containers/Footer/Footer';
 import Modal from '../containers/Modal';
@@ -16,8 +16,6 @@ const App = () => {
   const [id, setId] = useState(1);
   const [modal, setModal] = useState(false);
   const [userModal, setUserModal] = useState({});
-  
-  
  
 
 
@@ -55,14 +53,35 @@ const closePopUp =()=> {
   setModal(false);
 }
 
-  const popUpUser = (evt) => {
+const popUpUser = (evt) => {
     let card = evt.target.id;
     setModal(true);
-    let userModal = users.find(user => user.id === +card);
-    return setUserModal(userModal)
-   
-    
+    let userModals = users.find(user => user.id === +card);
+    return setUserModal(userModals) 
   }
+   
+const changeValueInput = (evt) =>{
+    const {name, value} = evt.target;
+    setUserModal({...userModal, [name]:value})
+}
+
+const saveChanges = ()=> {
+  let changedUser = {...userModal}
+  debugger;
+   let usersNew = users.map(user => {
+    if (user.id === changedUser.id){
+      return user = {name: changedUser.name, 
+        surname: changedUser.surname, 
+        address: changedUser.address, 
+        id: user.id
+    }}
+    else{
+      return user
+    }
+  })
+  
+  setUsers(usersNew)
+}
 
  
     
@@ -70,8 +89,8 @@ const closePopUp =()=> {
     <>
      
       <Main handleListen={listenForm} users={users} deleteUser={deleteUser} popUpUser={popUpUser} />
-     {modal&&<Modal users={userModal} closePopUp={closePopUp} 
-    //  changeValueInputName={changeValueInputName} changeValueInputSurname={changeValueInputSurname} changeValueInputAddress={changeValueInputAddress} valueInputName={valueInputName} valueInputSurname={valueInputSurname} valueInputAddress={valueInputAddress}
+     {modal&&<Modal valueInput={userModal} closePopUp={closePopUp} saveChanges={saveChanges} changeValueInput={changeValueInput}
+  
     />}
       <Footer count = {count}/>
     

+ 10 - 0
react/hw20-react/src/components/Button/style.css

@@ -0,0 +1,10 @@
+button {
+    width: 70%;
+    padding: 10px;
+    background-color: rgb(79, 158, 0);
+    margin: 10px auto;
+    text-transform: uppercase;
+    color: darkblue;
+    font-weight: 800;
+    border-radius: 20px;
+}

+ 1 - 2
react/hw20-react/src/containers/Form/style.css

@@ -11,8 +11,7 @@
 .form button {
     background-color: rgba(25, 25, 190, 0.836);
     width: 160px;
-    padding: 10px;
     margin: 20px auto;
     font-weight: 700;
-    font-size: 20px;
+   
 }

+ 16 - 35
react/hw20-react/src/containers/Modal/Modal.jsx

@@ -1,44 +1,25 @@
 import React from 'react'
-import {useState} from 'react'
 import Button from '../../components/Button';
 import Input from '../../components/Input';
 import './style.css';
 const Modal = ({
-  users,
+  valueInput,
   closePopUp,
-  // changeValueInputName,
-  // changeValueInputSurname,
-  // changeValueInputAddress,
-  // valueInputName,
-  // valueInputSurname,
-  // valueInputAddress
+  saveChanges, 
+  changeValueInput
 
 }) => {
-  const [valueInputName, setValueInputName] = useState(users.name);
-  const [valueInputSurname, setValueInputSurname] = useState(users.surname);
-  const [valueInputAddress, setValueInputAddress] = useState(users.address);
-  const changeValueInputName = (evt) =>{
-    let value = evt.target.value;
-    setValueInputName(value)
-}
-const changeValueInputSurname = (evt) =>{
-  let value = evt.target.value;
-  setValueInputSurname(value)
-}
-const changeValueInputAddress = (evt) =>{
-  let value = evt.target.value;
-  setValueInputAddress(value)
-}
-    return (
-      <div className="modal" tabIndex="1"  name={users.id}>
+  return (
+    <div className="modal" tabIndex="1"  name={valueInput.id}>
 
-        <Input  value={valueInputName} onChange={changeValueInputName}/>
-        <Input value={valueInputSurname}onChange={changeValueInputSurname}/>
-        <Input value={valueInputAddress} onChange={changeValueInputAddress}/>
-        <Button onClick={closePopUp}>Close</Button>
-      
-  
-      </div>
-    )
-  }
-  export default Modal 
+      <Input name="name" value={valueInput.name} onChange={changeValueInput}/>
+      <Input name="surname" value={valueInput.surname}onChange={changeValueInput}/>
+      <Input name="address" value={valueInput.address} onChange={changeValueInput}/>
+      <Button onClick={closePopUp}>Close</Button>
+      <Button onClick={saveChanges}>Save changes</Button> 
+    
+
+    </div>
+  )
+}
+export default Modal 

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 0
react/hw21-react/.eslintcache


+ 23 - 0
react/hw21-react/.gitignore

@@ -0,0 +1,23 @@
+# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
+
+# dependencies
+/node_modules
+/.pnp
+.pnp.js
+
+# testing
+/coverage
+
+# production
+/build
+
+# misc
+.DS_Store
+.env.local
+.env.development.local
+.env.test.local
+.env.production.local
+
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*

+ 70 - 0
react/hw21-react/README.md

@@ -0,0 +1,70 @@
+# Getting Started with Create React App
+
+This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
+
+## Available Scripts
+
+In the project directory, you can run:
+
+### `npm start`
+
+Runs the app in the development mode.\
+Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
+
+The page will reload if you make edits.\
+You will also see any lint errors in the console.
+
+### `npm test`
+
+Launches the test runner in the interactive watch mode.\
+See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
+
+### `npm run build`
+
+Builds the app for production to the `build` folder.\
+It correctly bundles React in production mode and optimizes the build for the best performance.
+
+The build is minified and the filenames include the hashes.\
+Your app is ready to be deployed!
+
+See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
+
+### `npm run eject`
+
+**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
+
+If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
+
+Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
+
+You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
+
+## Learn More
+
+You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
+
+To learn React, check out the [React documentation](https://reactjs.org/).
+
+### Code Splitting
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
+
+### Analyzing the Bundle Size
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
+
+### Making a Progressive Web App
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
+
+### Advanced Configuration
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
+
+### Deployment
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
+
+### `npm run build` fails to minify
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 16444 - 0
react/hw21-react/package-lock.json


+ 39 - 0
react/hw21-react/package.json

@@ -0,0 +1,39 @@
+{
+  "name": "hw21-react",
+  "version": "0.1.0",
+  "private": true,
+  "dependencies": {
+    "@testing-library/jest-dom": "^5.11.6",
+    "@testing-library/react": "^11.2.2",
+    "@testing-library/user-event": "^12.6.0",
+    "react": "^17.0.1",
+    "react-dom": "^17.0.1",
+    "react-scripts": "4.0.1",
+    "uuid": "^8.3.2",
+    "web-vitals": "^0.2.4"
+  },
+  "scripts": {
+    "start": "react-scripts start",
+    "build": "react-scripts build",
+    "test": "react-scripts test",
+    "eject": "react-scripts eject"
+  },
+  "eslintConfig": {
+    "extends": [
+      "react-app",
+      "react-app/jest"
+    ]
+  },
+  "browserslist": {
+    "production": [
+      ">0.2%",
+      "not dead",
+      "not op_mini all"
+    ],
+    "development": [
+      "last 1 chrome version",
+      "last 1 firefox version",
+      "last 1 safari version"
+    ]
+  }
+}

BIN
react/hw21-react/public/favicon.ico


+ 43 - 0
react/hw21-react/public/index.html

@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8" />
+    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
+    <meta name="viewport" content="width=device-width, initial-scale=1" />
+    <meta name="theme-color" content="#000000" />
+    <meta
+      name="description"
+      content="Web site created using create-react-app"
+    />
+    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
+    <!--
+      manifest.json provides metadata used when your web app is installed on a
+      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
+    -->
+    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
+    <!--
+      Notice the use of %PUBLIC_URL% in the tags above.
+      It will be replaced with the URL of the `public` folder during the build.
+      Only files inside the `public` folder can be referenced from the HTML.
+
+      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
+      work correctly both with client-side routing and a non-root public URL.
+      Learn how to configure a non-root public URL by running `npm run build`.
+    -->
+    <title>React App</title>
+  </head>
+  <body>
+    <noscript>You need to enable JavaScript to run this app.</noscript>
+    <div id="root"></div>
+    <!--
+      This HTML file is a template.
+      If you open it directly in the browser, you will see an empty page.
+
+      You can add webfonts, meta tags, or analytics to this file.
+      The build step will place the bundled scripts into the <body> tag.
+
+      To begin the development, run `npm start` or `yarn start`.
+      To create a production bundle, use `npm run build` or `yarn build`.
+    -->
+  </body>
+</html>

BIN
react/hw21-react/public/logo192.png


BIN
react/hw21-react/public/logo512.png


+ 25 - 0
react/hw21-react/public/manifest.json

@@ -0,0 +1,25 @@
+{
+  "short_name": "React App",
+  "name": "Create React App Sample",
+  "icons": [
+    {
+      "src": "favicon.ico",
+      "sizes": "64x64 32x32 24x24 16x16",
+      "type": "image/x-icon"
+    },
+    {
+      "src": "logo192.png",
+      "type": "image/png",
+      "sizes": "192x192"
+    },
+    {
+      "src": "logo512.png",
+      "type": "image/png",
+      "sizes": "512x512"
+    }
+  ],
+  "start_url": ".",
+  "display": "standalone",
+  "theme_color": "#000000",
+  "background_color": "#ffffff"
+}

+ 3 - 0
react/hw21-react/public/robots.txt

@@ -0,0 +1,3 @@
+# https://www.robotstxt.org/robotstxt.html
+User-agent: *
+Disallow:

+ 36 - 0
react/hw21-react/src/App/App.jsx

@@ -0,0 +1,36 @@
+import './style.css';
+import React from "react";
+import {useReducer} from 'react';
+import {UsersContext, UsersReducer} from '../state'
+import Main from '../containers/Main'
+import Footer from '../containers/Footer/Footer';
+import Modal from '../containers/Modal';
+
+
+
+const App = () => {
+ 
+const initialStore = 
+ { users: [],
+modal : false,
+userModal: {},
+foundUsers: [],
+usersKeys: [],
+};
+    
+const [store, dispatch] = useReducer(UsersReducer, initialStore)
+    return (
+    <>
+     <UsersContext.Provider value={{store, dispatch}}>
+        <Main/>
+        {store.modal&&<Modal/>}
+        <Footer/>
+     </UsersContext.Provider>
+      
+    </>
+    )
+  }
+
+export default App;
+
+  

+ 2 - 0
react/hw21-react/src/App/index.js

@@ -0,0 +1,2 @@
+import App from './App'
+export default App;

+ 6 - 0
react/hw21-react/src/App/style.css

@@ -0,0 +1,6 @@
+.list {
+    display: flex;
+    flex-direction: row;
+    flex-wrap: wrap;
+
+}

+ 17 - 0
react/hw21-react/src/components/Button/Button.jsx

@@ -0,0 +1,17 @@
+import React from 'react';
+import './style.css'
+
+const Button = ({
+   btnId,
+    onClick,
+    children
+})=> {
+    return <button
+    name={btnId}
+               onClick={(e) => onClick && onClick(e)}>
+                   {children}
+            </button>
+   
+}
+
+export default Button;

+ 2 - 0
react/hw21-react/src/components/Button/index.js

@@ -0,0 +1,2 @@
+import Button from './Button'
+export default Button

+ 10 - 0
react/hw21-react/src/components/Button/style.css

@@ -0,0 +1,10 @@
+button {
+    width: 70%;
+    padding: 10px;
+    background-color: rgb(79, 158, 0);
+    margin: 10px auto;
+    text-transform: uppercase;
+    color: darkblue;
+    font-weight: 800;
+    border-radius: 20px;
+}

+ 22 - 0
react/hw21-react/src/components/Input/Input.jsx

@@ -0,0 +1,22 @@
+
+import React from "react";
+const Input =({
+  value,
+  name,
+  placeholder,
+  onChange,
+id
+}) => { 
+    
+      return (
+       
+     
+        <input value={value} name={name} id={id}  placeholder={ placeholder}
+                onChange={(e) => onChange && onChange(e)}
+         />
+    
+      );
+    }
+  
+ 
+export default Input

+ 2 - 0
react/hw21-react/src/components/Input/index.js

@@ -0,0 +1,2 @@
+import Input from './Input'
+export default Input;

+ 14 - 0
react/hw21-react/src/components/Label/Label.jsx

@@ -0,0 +1,14 @@
+import './style.css';
+import React from "react";
+const Label =({
+  htmlFor, children
+  
+}) => { 
+    
+      return (
+      <label  htmlFor={htmlFor}>{children}</label>
+      );
+    }
+  
+ 
+export default Label

+ 2 - 0
react/hw21-react/src/components/Label/index.js

@@ -0,0 +1,2 @@
+import Label from './Label'
+export default Label;

+ 0 - 0
react/hw21-react/src/components/Label/style.css


+ 40 - 0
react/hw21-react/src/containers/Card/Card.jsx

@@ -0,0 +1,40 @@
+
+import React, {useContext} from 'react';
+import { UsersContext } from '../../state'
+import Button from '../../components/Button'
+import './style.css';
+const Card = ({user}) => {
+ 
+const {store, dispatch} = useContext(UsersContext);
+const deleteUser = (evt) => {
+  evt.stopPropagation();
+  dispatch({
+    type: 'DELETE_USER',
+    payload: user.id
+  })
+
+}
+
+const popUpUser = (evt) => {
+
+  let card = evt.target.id;
+  
+  let userModals = store.users.find(user => user.id === card);
+
+dispatch({
+  type: 'OPEN_MODAL',
+  payload: userModals
+})
+}
+
+    return (
+      <div className="card" tabIndex="1" onClick={popUpUser} id={user.id}>
+        <h1>Name: {user.name}</h1>
+        <p>Surname:  {user.surname}</p>
+        <p>Address:  {user.address}</p>
+        <Button onClick = {deleteUser} btnId={user.id} >Delete user</Button>
+  
+      </div>
+    )
+  }
+  export default Card 

+ 2 - 0
react/hw21-react/src/containers/Card/index.js

@@ -0,0 +1,2 @@
+import Card from './Card'
+export default Card;

+ 9 - 0
react/hw21-react/src/containers/Card/style.css

@@ -0,0 +1,9 @@
+.card {
+    display: flex;
+    flex-direction: column;
+    justify-content: center;
+    width: 300px;
+    border: 2px solid blue;
+    margin: 20px;
+    padding: 20px;
+}

+ 10 - 0
react/hw21-react/src/containers/Footer/Footer.jsx

@@ -0,0 +1,10 @@
+import './style.css';
+import React, {useContext} from 'react';
+import { UsersContext } from '../../state'
+const Footer = () => {
+    const { store } = useContext(UsersContext);   
+    return(
+    <footer className="footer">Total users count: {store.users.length}</footer>
+    )
+}
+export default Footer;

+ 2 - 0
react/hw21-react/src/containers/Footer/index.js

@@ -0,0 +1,2 @@
+import Header from './Header'
+export default Header;

+ 7 - 0
react/hw21-react/src/containers/Footer/style.css

@@ -0,0 +1,7 @@
+.footer {
+    width: 80%;
+    margin: 0 auto;;
+    border: 2px solid black;
+    font-size: 40px;
+    font-weight: 700;
+}

+ 59 - 0
react/hw21-react/src/containers/Form/Form.jsx

@@ -0,0 +1,59 @@
+import './style.css';
+import React, {useContext, useEffect, useState} from 'react';
+import { UsersContext } from '../../state'
+import Input from '../../components/Input';
+import Button from '../../components/Button';
+import Label from '../../components/Label';
+import { v4 as uuid} from 'uuid'
+
+
+
+const Form = () => {
+const { store, dispatch } = useContext(UsersContext);
+const [valueInput, setValueInput] = useState('');
+const listenForm = (evt) => {
+  
+  evt.preventDefault()
+  
+  let name = evt.target.elements.name.value;
+  let surname = evt.target.elements.surname.value
+  let address = evt.target.elements.address.value
+  let newUsers = store.users
+let user ={
+  name: name,
+  surname: surname,
+  address: address,
+  id: uuid(),
+}
+
+let keys = store.usersKeys||[]
+ 
+ newUsers.push(user);
+ let userId = user.id;
+ keys.push(userId);
+ let stringedUser = JSON.stringify(user)
+ localStorage.setItem(`users${userId}`, stringedUser);
+ localStorage.setItem('users',JSON.stringify(keys))
+ let savedKeys= JSON.parse(localStorage.getItem('users'))
+ dispatch(  { type: 'LOCAL_STORAGE', payload: savedKeys})
+ dispatch(  { type: 'CREATE_USER', payload: newUsers})
+
+
+ 
+}
+
+
+  return (
+    <form className="form" onSubmit={listenForm}>
+      <Label htmlFor='nameInput' >Enter name</Label>
+      <Input name="name" id='nameInput' type='text'/>
+      <Label htmlFor="surnameInput">Enter Surname</Label>
+      <Input name="surname" id="surnameInput" type="text" />
+      <Label htmlFor="addressInput">Enter address</Label>
+      <Input  name="address" id="addressInput" type="text"/>
+      <Button >Create user</Button>
+    </form>
+  )
+}
+
+export default Form

+ 2 - 0
react/hw21-react/src/containers/Form/index.js

@@ -0,0 +1,2 @@
+import Form from './Form'
+export default Form;

+ 17 - 0
react/hw21-react/src/containers/Form/style.css

@@ -0,0 +1,17 @@
+.form {
+    display: flex;
+    flex-direction: column;
+    justify-content: center;
+    width: 200px;
+    border: 2px solid rgba(29, 29, 32, 0.356);
+    margin: 20px;
+    padding: 20px;
+}
+
+.form button {
+    background-color: rgba(25, 25, 190, 0.836);
+    width: 160px;
+    margin: 20px auto;
+    font-weight: 700;
+   
+}

+ 22 - 0
react/hw21-react/src/containers/Main/Main.jsx

@@ -0,0 +1,22 @@
+import './style.css';
+import Form from '../Form';
+import React from 'react';
+import UsersComponent from '../UsersComponent';
+
+
+
+const Main =() => {
+  
+  return (
+    <main className="main">
+
+    <Form/>
+    <UsersComponent />
+    
+    
+    </main>
+
+  )
+}
+
+export default Main

+ 2 - 0
react/hw21-react/src/containers/Main/index.js

@@ -0,0 +1,2 @@
+import Main from './Main'
+export default Main;

+ 6 - 0
react/hw21-react/src/containers/Main/style.css

@@ -0,0 +1,6 @@
+.main {
+    display: flex;
+    justify-content: center;
+    margin: 20px;
+    padding: 20px;
+}

+ 56 - 0
react/hw21-react/src/containers/Modal/Modal.jsx

@@ -0,0 +1,56 @@
+import React, {useContext, useState} from 'react';
+import { UsersContext } from '../../state'
+import Button from '../../components/Button';
+import Input from '../../components/Input';
+import './style.css';
+const Modal = () => {
+  const {store, dispatch} = useContext(UsersContext);
+  const [userModalInfo, setUserModalInfo] = useState(store.userModal)
+  const changeValueInput = (evt) =>{
+    const {name, value} = evt.target;
+let userN = userModalInfo;
+
+userN[name] = value
+
+setUserModalInfo(userN) 
+dispatch({type: 'CHANGE_INPUT', payload: userN})
+    
+}
+
+const saveChanges = ()=> {
+  let changedUser = userModalInfo;
+
+   let usersNew = store.users.map(user => {
+    if (user.id === changedUser.id){
+      return user = {name: changedUser.name, 
+        surname: changedUser.surname, 
+        address: changedUser.address, 
+        id: user.id
+    }}
+    else{
+      return user
+    }
+  })
+
+  dispatch({type: 'EDIT_CARD', payload: usersNew})
+}
+const closePopUp =()=> {
+
+  dispatch({type: 'CLOSE_MODAL', payload: store.modal})
+}
+  return (
+    <div className="modal" tabIndex="1"  name={store.userModal.id}>
+      <Input name="name" value={store.userModal.name} onChange={changeValueInput}/>
+
+      <Input name="surname" value={store.userModal.surname}onChange={changeValueInput}/>
+      
+      <Input name="address" value={store.userModal.address} onChange={changeValueInput}/>
+      
+      <Button onClick={saveChanges}>Save changes</Button> 
+      <Button onClick={closePopUp}>Close</Button>
+    
+
+    </div>
+  )
+}
+export default Modal 

+ 2 - 0
react/hw21-react/src/containers/Modal/index.js

@@ -0,0 +1,2 @@
+import Modal from './Modal'
+export default Modal;

+ 19 - 0
react/hw21-react/src/containers/Modal/style.css

@@ -0,0 +1,19 @@
+.modal {
+    position: absolute;
+    height: 80%;
+    top: 0;
+    left: center;
+    display: flex;
+    background-color: rgb(230, 230, 230);
+    flex-direction: column;
+    justify-content: center;
+    width: 80%;
+    border: 2px solid rgb(51, 255, 0);
+    margin: 20px;
+    padding: 20px;
+}
+
+.modal input {
+    padding: 30px;
+    margin: 10px;
+}

+ 19 - 0
react/hw21-react/src/containers/Search/Search.jsx

@@ -0,0 +1,19 @@
+import './style.css';
+import Input from '../../components/Input'
+
+
+
+
+
+const Search =({
+ placeholder, valueInput, handleSearchCards
+
+}) => {
+
+  return (
+    <Input placeholder={placeholder} onChange={handleSearchCards} value={valueInput}/>
+
+  )
+}
+
+export default Search

+ 2 - 0
react/hw21-react/src/containers/Search/index.js

@@ -0,0 +1,2 @@
+import Search from './Search'
+export default Search;

+ 7 - 0
react/hw21-react/src/containers/Search/style.css

@@ -0,0 +1,7 @@
+input {
+    width: 80%;
+    padding: 5px;
+    max-height: 70px;
+    margin: 20px auto;
+    border: 1px solid  gray;
+}

+ 57 - 0
react/hw21-react/src/containers/UsersComponent/UsersComponent.jsx

@@ -0,0 +1,57 @@
+
+import Card from '../Card';
+import Search from '../Search';
+import './style.css';
+import React, {useContext, useEffect, useState} from 'react';
+import { UsersContext } from '../../state'
+
+
+const UsersComponent = () => {
+ 
+  const {store, dispatch} = useContext(UsersContext);
+  const [valueInput, setValueInput] = useState('');
+  
+  let usersKeys = JSON.parse(localStorage.getItem('users'))||[];
+
+  const handleSearchCards = evt => {
+    const {value} = evt.target;
+    setValueInput(value);
+    const result = store.users.filter(user => {
+       return user.name.toLocaleLowerCase().includes(value.toLocaleLowerCase())
+
+  })
+  
+  dispatch({type: 'SEARCH_BY_NAME', payload: result})
+  } 
+  const  getUsers = function(){
+  
+    let savedUsers = [];
+    
+        for(let i=0; i<usersKeys.length; i++) {
+            savedUsers.push(JSON.parse(localStorage.getItem(`users${usersKeys[i]}`)))
+            
+        }
+        return savedUsers
+    }
+  
+useEffect(()=> {
+  let savedUsers = getUsers();
+  dispatch({type: 'LOCAL_STORAGE_USERS', payload: savedUsers || []})
+  dispatch({type: 'LOCAL_STORAGE', payload: usersKeys})
+}, [])
+
+
+  
+  let cards = store.users.map(user => <Card user={user} key={user.id} />);
+  let searchCards = store.foundUsers.map(user => <Card user={user} key={user.id} />)
+
+  
+    return (
+      <div className="users-list">
+       <Search placeholder='search by name....' handleSearchCards ={handleSearchCards } valueInput={valueInput} />
+       {valueInput.length === 0 ? cards : searchCards}
+      </div>
+    )
+
+  }
+  export default UsersComponent

+ 2 - 0
react/hw21-react/src/containers/UsersComponent/index.js

@@ -0,0 +1,2 @@
+import UsersComponent from './UsersComponent'
+export default UsersComponent;

+ 6 - 0
react/hw21-react/src/containers/UsersComponent/style.css

@@ -0,0 +1,6 @@
+.users-list {
+    display: flex;
+    flex-wrap: wrap;
+    width: 70%;
+    border: 2px solid black;
+}

+ 13 - 0
react/hw21-react/src/index.css

@@ -0,0 +1,13 @@
+body {
+  margin: 0;
+  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
+    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
+    sans-serif;
+  -webkit-font-smoothing: antialiased;
+  -moz-osx-font-smoothing: grayscale;
+}
+
+code {
+  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
+    monospace;
+}

+ 12 - 0
react/hw21-react/src/index.js

@@ -0,0 +1,12 @@
+import React from 'react';
+import ReactDOM from 'react-dom';
+import './index.css';
+import App from './App';
+
+ReactDOM.render(
+  <React.StrictMode>
+    <App />
+  </React.StrictMode>,
+  document.getElementById('root')
+);
+

+ 3 - 0
react/hw21-react/src/state/UsersContex.js

@@ -0,0 +1,3 @@
+import {createContext} from 'react';
+
+export const UsersContext = createContext();

+ 70 - 0
react/hw21-react/src/state/UsersReducer.js

@@ -0,0 +1,70 @@
+export const UsersReducer = (store, action) => {
+
+  switch (action.type) {
+    case 'CREATE_USER':
+
+      return {
+        ...store,
+        users: action.payload
+      }
+    case 'DELETE_USER':
+      const id = action.payload
+      const newArr = store.users.filter(user => user.id !== id)
+      localStorage.removeItem('users');
+      localStorage.removeItem(`users${id}`);
+      let newUsersKeys = store.usersKeys.filter(user => user !== id);
+      localStorage.setItem('users', JSON.stringify(newUsersKeys))
+      return {
+        ...store,
+        users: newArr,
+        usersKeys: newUsersKeys
+      }
+    case 'OPEN_MODAL':
+      return {
+        ...store,
+        modal: true,
+        userModal: action.payload
+      }
+    case 'CLOSE_MODAL':
+      return {
+        ...store,
+        modal: false,
+
+      }
+    case 'EDIT_CARD':
+      return {
+        ...store,
+
+        users: action.payload
+      }
+    case 'CHANGE_INPUT':
+      return {
+        ...store,
+
+        userModal: action.payload
+      }
+    case 'SEARCH_BY_NAME':
+
+
+      return {
+        ...store,
+
+        foundUsers: action.payload
+      }
+    case 'LOCAL_STORAGE':
+
+      return {
+        ...store,
+        usersKeys: action.payload
+      }
+    case 'LOCAL_STORAGE_USERS':
+
+      return {
+        ...store,
+        users: action.payload
+      }
+    default:
+      return store
+  }
+};
+

+ 4 - 0
react/hw21-react/src/state/index.js

@@ -0,0 +1,4 @@
+import {UsersReducer} from './UsersReducer';
+import { UsersContext} from './UsersContex';
+
+export  {UsersReducer, UsersContext};