Browse Source

ДЗ 20 декабря

Vladislav342 2 years ago
parent
commit
8875d899f3
40 changed files with 58790 additions and 0 deletions
  1. 23 0
      React/HW_React_3/HW/.gitignore
  2. 70 0
      React/HW_React_3/HW/README.md
  3. 27174 0
      React/HW_React_3/HW/package-lock.json
  4. 38 0
      React/HW_React_3/HW/package.json
  5. BIN
      React/HW_React_3/HW/public/favicon.ico
  6. 43 0
      React/HW_React_3/HW/public/index.html
  7. BIN
      React/HW_React_3/HW/public/logo192.png
  8. BIN
      React/HW_React_3/HW/public/logo512.png
  9. 25 0
      React/HW_React_3/HW/public/manifest.json
  10. 3 0
      React/HW_React_3/HW/public/robots.txt
  11. 273 0
      React/HW_React_3/HW/src/App.js
  12. 28 0
      React/HW_React_3/HW/src/App.scss
  13. 8 0
      React/HW_React_3/HW/src/App.test.js
  14. 13 0
      React/HW_React_3/HW/src/index.css
  15. 17 0
      React/HW_React_3/HW/src/index.js
  16. 1 0
      React/HW_React_3/HW/src/logo.svg
  17. BIN
      React/HW_React_3/HW/src/pics/ClockFace.png
  18. BIN
      React/HW_React_3/HW/src/pics/ClockFace_H.png
  19. BIN
      React/HW_React_3/HW/src/pics/ClockFace_M.png
  20. BIN
      React/HW_React_3/HW/src/pics/ClockFace_S.png
  21. 13 0
      React/HW_React_3/HW/src/reportWebVitals.js
  22. 5 0
      React/HW_React_3/HW/src/setupTests.js
  23. 23 0
      React/HW_React_3/InClass/.gitignore
  24. 70 0
      React/HW_React_3/InClass/README.md
  25. 30210 0
      React/HW_React_3/InClass/package-lock.json
  26. 42 0
      React/HW_React_3/InClass/package.json
  27. BIN
      React/HW_React_3/InClass/public/favicon.ico
  28. 43 0
      React/HW_React_3/InClass/public/index.html
  29. BIN
      React/HW_React_3/InClass/public/logo192.png
  30. BIN
      React/HW_React_3/InClass/public/logo512.png
  31. 25 0
      React/HW_React_3/InClass/public/manifest.json
  32. 3 0
      React/HW_React_3/InClass/public/robots.txt
  33. 537 0
      React/HW_React_3/InClass/src/App.js
  34. 46 0
      React/HW_React_3/InClass/src/App.scss
  35. 8 0
      React/HW_React_3/InClass/src/App.test.js
  36. 13 0
      React/HW_React_3/InClass/src/index.css
  37. 17 0
      React/HW_React_3/InClass/src/index.js
  38. 1 0
      React/HW_React_3/InClass/src/logo.svg
  39. 13 0
      React/HW_React_3/InClass/src/reportWebVitals.js
  40. 5 0
      React/HW_React_3/InClass/src/setupTests.js

+ 23 - 0
React/HW_React_3/HW/.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/HW_React_3/HW/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 your browser.
+
+The page will reload when you make changes.\
+You may 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)

File diff suppressed because it is too large
+ 27174 - 0
React/HW_React_3/HW/package-lock.json


+ 38 - 0
React/HW_React_3/HW/package.json

@@ -0,0 +1,38 @@
+{
+  "name": "secondproj",
+  "version": "0.1.0",
+  "private": true,
+  "dependencies": {
+    "@testing-library/jest-dom": "^5.16.1",
+    "@testing-library/react": "^12.1.2",
+    "@testing-library/user-event": "^13.5.0",
+    "react": "^17.0.2",
+    "react-dom": "^17.0.2",
+    "react-scripts": "5.0.0",
+    "web-vitals": "^2.1.3"
+  },
+  "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/HW_React_3/HW/public/favicon.ico


+ 43 - 0
React/HW_React_3/HW/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/HW_React_3/HW/public/logo192.png


BIN
React/HW_React_3/HW/public/logo512.png


+ 25 - 0
React/HW_React_3/HW/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/HW_React_3/HW/public/robots.txt

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

+ 273 - 0
React/HW_React_3/HW/src/App.js

@@ -0,0 +1,273 @@
+import {useEffect, useState, useRef} from "react";
+import React from 'react';
+import './App.scss';
+import ClockFace from './pics/ClockFace.png'
+import ClockSec from './pics/ClockFace_S.png'
+import ClockMin from './pics/ClockFace_M.png'
+import ClockHour from './pics/ClockFace_H.png'
+
+const Spoiler = ({header="+", open=true, children}) => {
+	const [open2, setOpen] = useState(open);
+	return(
+		<>
+			<div onClick={()=> setOpen(open2===true?false:true)}>
+				{header}
+				{open2 && children}
+			</div>
+		</>
+	)
+}
+
+const RangeInput = ({min=0, max=0}) => {
+	//const [min2, setMin] = useState(min);
+	//const [max2, setMax] = useState(max);
+	const [length, setLength] = useState(0);
+	return(
+		<>
+			<input type='text' style={{backgroundColor: (length<min || length>max)?'red':'green'}} 
+			   onChange={e=>setLength(+e.target.value.length)} 	/>
+		</>
+	)
+}
+
+const PasswordConfirm = ({min=0}) => {
+	const [val, setVal] = useState('');
+	const [secVal, setSecVal] = useState('');
+	const [length, setLength] = useState(0);
+	return(
+		<>
+			<div className='BTF'>
+				<input type='password' onChange={e=>{setVal(e.target.value); setLength(e.target.value.length)}} 
+					style={{backgroundColor: length<min?'red':'green'}} className='btf1'/>
+				<h3>{val}</h3>
+			</div>
+			<div className='BTF'>
+				<input type='password' style={{backgroundColor: (length<min||secVal.toLowerCase()!==val.toLowerCase())?'red':'green'}} 
+					onChange={e=>setSecVal(e.target.value)} className='btf1'/>
+				<p>{secVal}</p>
+			</div>	
+		</>
+	)
+}
+
+const Timer = ({startSec, onDelete, c}) => {
+    const [sec, setSec] = useState(startSec);
+    const [stop, setStop] = useState(false);
+    const [add, setAdd] =useState(0);
+    const [min,setMin] = useState(0);
+    const [hour, setHour] = useState(0);
+    const [err, setErr] = useState('');
+    const [count, setCount] = useState(c);
+    useEffect(() => {
+        if(!stop) {
+        	if(sec === 0) return;
+            const interval = setInterval(() => {
+            	setSec(sec => sec - 1)
+        	}, 1000)
+        	return () => { 
+        		 clearInterval(interval)	
+        	}
+        }
+    }, [stop, sec, add])
+    return (
+        <div className='t'>
+        	<hr className='h' />
+        	<p>{count}</p>
+            <p>{new Date(new Date().setHours(hour, min, sec)).toLocaleString().split (", ")[1]}</p>
+            <input onChange={e=>setAdd(+e.target.value)} placeholder='add' />
+            <button onClick={()=>setSec(sec+add)}>Add</button>
+            <button onClick={() => setStop(!stop)}>Stop</button>
+            <button onClick={onDelete}>x</button>
+            {err}
+        </div>
+    )
+}
+
+//доделать: как сделать чтобы count совподал с текущей позицией
+
+const TimerControl = ({hours, minutes, seconds}) => {
+    const [timers, setTimers] = useState([]);
+    const [count, setCount] = useState(0);     
+    let [h, setH] = useState(hours);
+    let [m, setM] = useState(minutes);
+    let [s, setS] = useState(seconds);
+    let item=0;
+    let res = (h * 3600) + (m * 60) + +s;
+    console.log(timers);
+    return (
+        <>
+            <input value={h.toString()} type='number' min='0' max='23' placeholder='hours' onChange={e => setH(+e.target.value)}/>
+            <input value={m.toString()} type='number' min='0' max='59' placeholder='minutes' onChange={e => setM(+e.target.value)}/>
+            <input value={s.toString()} type='number' min='0' max='59' placeholder='seconds' onChange={e => setS(+e.target.value)}/>
+            <button onClick={() =>{setCount(count+1); setTimers([Math.random(), ...timers]);}}>Start</button>
+            <p>{timers.map(i => <Timer startSec={res} c={count} key={i} onDelete={()=>{setCount(count-1); setTimers(timers.filter(t=>t!==i));}}/>)}</p>
+        </>
+    )
+}
+
+
+const SecondsTimer = ({seconds}) => <h2>{seconds || 0}</h2>
+
+const TimerContainer = ({seconds, refresh, render:Tag}) => {
+	const [count, setCount] = useState(seconds);
+	useEffect(()=>{
+		if(count<=0) return;
+		let interval = setInterval(()=>{
+			setCount(count=>count-1);
+		}, refresh)
+		return ()=> clearInterval(interval);
+	}, [count, refresh])
+    return(
+    	<>
+    		<Tag seconds={count}/>
+    	</>
+    )
+}
+
+
+const Timer2 = ({startSec}) => {
+    return (
+        <div className='t'>
+        	<p>00:00:{startSec}</p>
+        	<input placeholder='not used' />
+        	<button>Add</button>
+        	<button>Stop</button>
+        </div>
+    )
+}
+
+const TimerContainer2 = ({startSec, refresh, render:Tag}) => {
+	const [count, setCount] = useState(startSec);
+	useEffect(()=>{
+		if(count<=0) return;
+		let interval = setInterval(()=>{
+			setCount(count=>count-1);
+		}, refresh)
+		return ()=> clearInterval(interval);
+	}, [count, refresh])
+    return(
+    	<>
+    		<Tag startSec={count>0?(count<10?'0'+count:count):'00'}/>
+    	</>
+    )
+}
+
+
+
+
+const Watch = ({ seconds = 1000 }) =>
+  <div style={{ width: 'fit-content' }}>
+    <img src={ClockFace} style={{ width: 'inherit', position: 'absolute' }} alt='img' />
+    <img src={ClockSec} style={{
+      width: 'inherit', position: 'absolute',
+      transform: `rotate(${seconds % 60 * 6}deg)`
+    }} alt='img' />
+    <img src={ClockMin} style={{
+      width: 'inherit', position: 'absolute',
+      transform: `rotate(${(seconds / 60) % 60 * 6}deg)`
+    }} alt='img' />
+    <img src={ClockHour} style={{
+      width: 'inherit', position: 'absolute',
+      transform: `rotate(${((seconds) / (60 * 60)) % 24 * 30}deg)`
+    }} alt='img' />
+  </div>
+
+
+
+
+const TimerContainer3 = ({ seconds = 0, refresh = 10, render: Tag}) => {
+  	const [time, setTime] = useState(seconds * 1000)
+  	let [isPause, setIsPause] = useState(false)
+
+	useEffect(() => {
+	   setTime(seconds * 1000)
+	}, [seconds])
+
+	useEffect(() => {
+		let interval = null
+	    let now = performance.now()
+	    if (time > 0) {
+	      	interval = setInterval(() => {  
+	      		if(!isPause){	
+					console.log('1:'+`${isPause}`)
+	          	 	time > 0 ? setTime(time => time - (performance.now() - now)) : clearInterval(interval)
+	      		}else{
+ 					console.log('2:'+`${isPause}`)
+	      		}
+	      	}, refresh)
+	    }
+	    return () =>  clearInterval(interval) 
+	})
+
+	return (
+	    <div>
+	     	<button onClick={()=>setIsPause(!isPause)}>Pause / Continue</button>
+	      	<Tag className="clock" seconds={time > 0 ? time / 1000 : 0} />
+	    </div>
+	)
+}
+
+const Timer_Control_Container = ({h=0, m=0, s=0, render:Tag, refresh=10}) => {
+	const [sec, setSec] = useState(s)
+	const [min, setMin] = useState(m)
+	const [hour, setHour] = useState(h)
+	const [work, setWork] = useState(null)
+	const [active, setActive] = useState(false)
+	return (
+	    <div>
+	      	<span>
+	        	<input type="number" min="0" max="30" placeholder='hour'
+	          		onChange={(e) => setHour(+e.target.value)}
+	        	/>
+	        	<input type="number" min="0" max="59" placeholder='minutes' 
+	          		onChange={(e) => setMin(+e.target.value)}
+	        	/>
+	        	<input type="number" min="0" max="59" placeholder='seconds'
+	          		onChange={(e) => setSec(+e.target.value)}
+	        	/>
+	        		{active===false ? <button disabled={!hour && !min && !sec} onClick={() => { setWork(hour * 60 * 60 + min * 60 + sec); setActive(true) }}>Start</button> :
+	        		<button className='bckgr' onClick={() => { setWork(null); setActive(false) }}>Stop</button>}
+	        	<br />
+	      	</span>
+	      		{work ? <TimerContainer3 seconds={work} render={Tag} refresh={refresh} /> :
+	        	<TimerContainer3 seconds={0} render={Tag} refresh={refresh} />}
+	    </div>
+  	)
+}
+  
+
+function App() {
+  return (
+    <div className="App">
+    	<h2><hr/>Spoiler</h2>
+      	<Spoiler header={<h1>Заголовок</h1>} open>
+    		Контент 1
+    		<p>
+        		лорем ипсум траливали и тп.
+    		</p>
+		</Spoiler>
+		<Spoiler>
+		    <h2>Контент 2</h2>
+		    <p>
+		        лорем ипсум траливали и тп.
+		    </p>
+		</Spoiler>
+		<h2><hr/>RangeInput</h2>
+		<RangeInput min={5} max={10} />
+		<h2><hr/>PasswordConfirm</h2>
+		<PasswordConfirm min={2} />
+		<h2><hr/>Timer</h2>
+		<Timer startSec={5}/>
+		<h2><hr/>TimerControl</h2>
+		<TimerControl hours={1} minutes={10} seconds={10}/>
+		<h2><hr/>TimerContainer</h2>
+		<TimerContainer seconds={200} refresh={100} render={SecondsTimer}/>
+		<h2><hr/>LCD</h2>
+		<TimerContainer2 startSec={20} refresh={1000} render={Timer2}/>
+		<h2><hr/>Watch</h2>
+		<Timer_Control_Container render={Watch} />
+    </div>
+  );
+}
+
+export default App;

+ 28 - 0
React/HW_React_3/HW/src/App.scss

@@ -0,0 +1,28 @@
+body{
+  margin-bottom: 100px;
+  padding-left: 50px;
+  hr{
+    margin-left: -50px !important;
+  }
+  .BTF{
+    display: -webkit-flex; 
+    display:flex;
+    flex-direction: nowrap;
+    .btf1{
+      height: 20px;
+    }
+    .btf2{
+
+    }
+  }
+  .h{
+    width:20%;
+    margin-left:-10px !important;
+  }
+  .clock{
+    margin-top: 30px;
+  }
+  .bckgr:hover{
+      background-color: pink;
+  }
+}

+ 8 - 0
React/HW_React_3/HW/src/App.test.js

@@ -0,0 +1,8 @@
+import { render, screen } from '@testing-library/react';
+import App from './App';
+
+test('renders learn react link', () => {
+  render(<App />);
+  const linkElement = screen.getByText(/learn react/i);
+  expect(linkElement).toBeInTheDocument();
+});

+ 13 - 0
React/HW_React_3/HW/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;
+}

+ 17 - 0
React/HW_React_3/HW/src/index.js

@@ -0,0 +1,17 @@
+import React from 'react';
+import ReactDOM from 'react-dom';
+import './index.css';
+import App from './App';
+import reportWebVitals from './reportWebVitals';
+
+ReactDOM.render(
+  <React.StrictMode>
+    <App />
+  </React.StrictMode>,
+  document.getElementById('root')
+);
+
+// If you want to start measuring performance in your app, pass a function
+// to log results (for example: reportWebVitals(console.log))
+// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
+reportWebVitals();

File diff suppressed because it is too large
+ 1 - 0
React/HW_React_3/HW/src/logo.svg


BIN
React/HW_React_3/HW/src/pics/ClockFace.png


BIN
React/HW_React_3/HW/src/pics/ClockFace_H.png


BIN
React/HW_React_3/HW/src/pics/ClockFace_M.png


BIN
React/HW_React_3/HW/src/pics/ClockFace_S.png


+ 13 - 0
React/HW_React_3/HW/src/reportWebVitals.js

@@ -0,0 +1,13 @@
+const reportWebVitals = onPerfEntry => {
+  if (onPerfEntry && onPerfEntry instanceof Function) {
+    import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
+      getCLS(onPerfEntry);
+      getFID(onPerfEntry);
+      getFCP(onPerfEntry);
+      getLCP(onPerfEntry);
+      getTTFB(onPerfEntry);
+    });
+  }
+};
+
+export default reportWebVitals;

+ 5 - 0
React/HW_React_3/HW/src/setupTests.js

@@ -0,0 +1,5 @@
+// jest-dom adds custom jest matchers for asserting on DOM nodes.
+// allows you to do things like:
+// expect(element).toHaveTextContent(/react/i)
+// learn more: https://github.com/testing-library/jest-dom
+import '@testing-library/jest-dom';

+ 23 - 0
React/HW_React_3/InClass/.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/HW_React_3/InClass/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 your browser.
+
+The page will reload when you make changes.\
+You may 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)

File diff suppressed because it is too large
+ 30210 - 0
React/HW_React_3/InClass/package-lock.json


+ 42 - 0
React/HW_React_3/InClass/package.json

@@ -0,0 +1,42 @@
+{
+  "name": "firstproj",
+  "version": "0.1.0",
+  "private": true,
+  "dependencies": {
+    "@testing-library/jest-dom": "^5.16.1",
+    "@testing-library/react": "^12.1.2",
+    "@testing-library/user-event": "^13.5.0",
+    "node-sass": "^7.0.0",
+    "react": "^17.0.2",
+    "react-dom": "^17.0.2",
+    "react-redux": "^7.2.6",
+    "react-scripts": "5.0.0",
+    "redux": "^4.1.2",
+    "redux-thunk": "^2.4.1",
+    "web-vitals": "^2.1.2"
+  },
+  "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/HW_React_3/InClass/public/favicon.ico


+ 43 - 0
React/HW_React_3/InClass/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/HW_React_3/InClass/public/logo192.png


BIN
React/HW_React_3/InClass/public/logo512.png


+ 25 - 0
React/HW_React_3/InClass/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/HW_React_3/InClass/public/robots.txt

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

+ 537 - 0
React/HW_React_3/InClass/src/App.js

@@ -0,0 +1,537 @@
+import logoDefault from './logo.svg';
+import './App.scss';
+import {Provider, connect} from 'react-redux';
+import {createStore, combineReducers, applyMiddleware} from 'redux';
+import thunk from 'redux-thunk';
+import {useEffect, useState, useRef} from "react";
+import React from 'react';
+
+const jwtDecode = token => {
+    try {
+        let arrToken = token.split('.')
+        let base64Token = atob(arrToken[1])
+        return JSON.parse(base64Token)
+    }
+    catch (e) {
+        console.log('Лажа, Бро ' + e);
+    }
+}
+
+
+function authReducer(state, { type, token }) {
+    if (!state) {
+        if (localStorage.authToken) {
+            type = 'AUTH_LOGIN'
+            token = localStorage.authToken
+        } else state = {}
+    }
+    if (type === 'AUTH_LOGIN') {
+        localStorage.setItem('authToken', token)
+        let payload = jwtDecode(token)
+        if (typeof payload === 'object') {
+            return {
+                ...state,
+                token,
+                payload
+            }
+        } else return state
+    }
+    if (type === 'AUTH_LOGOUT') {
+        localStorage.removeItem('authToken')
+        return {}
+    }
+    return state
+}
+const actionAuthLogin = token => ({ type: 'AUTH_LOGIN', token })
+const actionAuthLogout = () => ({ type: 'AUTH_LOGOUT' })
+const actionFullLogin = (login,password) =>
+	async function i(dispatch){
+		let token = await dispatch(actionLogin(login,password));
+		console.log(token);
+		if(token){
+			dispatch(actionAuthLogin(token));
+		}
+	}
+
+const actionLogin = (login, password) =>
+    actionPromise('login', gql(`query NameForMe1($login:String, $password:String){
+            login(login:$login, password:$password)
+        }`, { login, password }))
+
+
+function cartReducer(state = {}, { type, good = {}, count = 1 }) {
+    const { _id } = good
+    const types = {
+        CART_ADD() {
+            count = +count
+            if (!count) return state
+            return {
+                ...state,
+                [_id]: {
+                    good,
+                    count: count + (state[_id]?.count || 0)
+                }
+            }
+        },
+        CART_CHANGE() {
+            count = +count
+            if (!count) return state
+            return {
+                ...state,
+                [_id]: {
+                    good,
+                    count: count
+                }
+            }
+        },
+        CART_REMOVE() {
+            let { [_id]: remove, ...newState } = state
+            return {
+                ...newState
+            }
+        },
+        CART_CLEAR() {
+            return {}
+        },
+    }
+    if (type in types) {
+        return types[type]()
+    }
+    return state
+}
+const actionCartAdd = (good, count=1) => ({type: "CART_ADD", good, count});
+
+
+function promiseReducer(state = {}, { type, status, payload, error, name }) {
+    if (type === 'PROMISE') {
+        return {
+            ...state,
+            [name]: { status, payload, error }
+        }
+    }
+    return state;
+}
+const actionPending = name => ({ type: 'PROMISE', status: 'PENDING', name })
+const actionResolved = (name, payload) => ({ type: 'PROMISE', status: 'RESOLVED', name, payload })
+const actionRejected = (name, error) => ({ type: 'PROMISE', status: 'REJECTED', name, error })
+const actionPromise = (name, promise) =>
+    async dispatch => {
+        dispatch(actionPending(name))
+        try {
+            let data = await promise
+            dispatch(actionResolved(name, data))
+            return data
+        }
+        catch (error) {
+            dispatch(actionRejected(name, error))
+        }
+    }
+
+
+const getGQL = url =>
+    async (query, variables = {}) => {
+        let obj = await fetch(url, {
+            method: 'POST',
+            headers: {
+                "Content-Type": "application/json",
+                Authorization: localStorage.authToken ? 'Bearer ' + localStorage.authToken : {},
+            },
+            body: JSON.stringify({ query, variables })
+        })
+        let a = await obj.json()
+        if (!a.data && a.errors)
+            throw new Error(JSON.stringify(a.errors))
+        return a.data[Object.keys(a.data)[0]]
+    }
+const backURL = 'http://shop-roles.asmer.fs.a-level.com.ua'
+const gql = getGQL(backURL + '/graphql');
+
+
+const actionRootCats = () =>
+    actionPromise('rootCats', gql(`query {
+            CategoryFind(query: "[{\\"parent\\":null}]"){
+                _id name
+            }
+        }`))
+
+
+const actionCatById = (_id) =>
+    actionPromise('catById', gql(`query catById($q: String){
+            CategoryFindOne(query: $q){
+                subCategories{name, _id}
+                _id name goods {
+                    _id name price images {
+                        url
+                    }
+                }
+            }
+        }`, { q: JSON.stringify([{ _id }]) }))
+
+
+
+const store = createStore(combineReducers({promise: promiseReducer, 
+										auth: authReducer,
+										cart: cartReducer}),
+										applyMiddleware(thunk))
+store.subscribe(()=>console.log(store.getState()))
+store.dispatch(actionRootCats())
+//store.dispatch(actionCatById('5dc49f4d5df9d670df48cc64'))
+
+store.dispatch(actionFullLogin('vladBraun4','123'))
+
+const Logo = ({logo=logoDefault}) =>
+    <a href='#' className='Logo'>
+        <img src={logo} />
+    </a>
+
+
+
+const KoshikGood = ({obj: {good: {_id, name, price, images}={}, count=1},  onCartChange, onCartRemove}) => {
+	console.log(name); 
+	console.log(count);
+	let [val, setVal] = useState(count)
+	return(
+		<div className='GoodCard2'>
+			<p>{name}</p>
+			{images && images[0] && images[0].url && <img src={backURL+'/'+images[0].url} />}
+			<p><input type='number' value={val} onChange={e=>setVal(e.target.value)}/></p>	
+			<p><strong>{price}</strong></p>
+		</div>
+	)
+}
+
+
+const KoshikGoods = ({goods}) =>{
+	console.log(goods);
+	return(
+		<div className='GoodCard'>
+			<h1>Корзина</h1>
+			{Object.entries(goods).map(good2 =>{
+				console.log(good2);
+				return(
+					<KoshikGood obj={good2[1]}/>
+				)
+			})}
+		</div>
+	)
+}	
+
+const CKoshikGoods = connect(state => ({goods: state.cart}))(KoshikGoods)
+
+
+
+
+const Koshik = ({cart}) =>{
+	let count = 0;
+	let sum = Object.entries(cart).map(([, val]) => val.count);
+    count = sum.reduce((a, b) => a + b, 0);
+    return(
+    	<div>
+    		<div className='Koshik'>{count}</div>
+    	</div>
+    )
+}
+const CKoshik = connect(({cart}) => ({cart}))(Koshik)
+
+const Header = ({logo=logoDefault}) =>
+    <header>
+        <Logo logo={logo} />
+        <CKoshik />
+        <CKoshikGoods />
+    </header>
+
+const Footer = ({logo=logoDefault}) =>
+    <footer>
+        <Logo logo={logo} /> />
+    </footer>
+
+const defaultRootCats =  [
+            {
+                "_id": "5dc49f4d5df9d670df48cc64",
+                "name": "Airconditions"
+            },
+            {
+                "_id": "5dc458985df9d670df48cc47",
+                "name": "     Smartphones"
+            },
+            {
+                "_id": "5dc4b2553f23b553bf354101",
+                "name": "Крупная бытовая техника"
+            },
+            {
+                "_id": "5dcac1b56d09c45440d14cf8",
+                "name": "Макароны"
+            }
+		]
+
+const RootCategory = ({cat:{_id,name}={}}) =>
+	<li>
+		<a href={`#/${_id}`}>{name}</a>
+	</li>
+
+const RootCategories = ({cats=defaultRootCats}) =>
+    <ul>
+    	{cats.map(cat=> <RootCategory cat={cat} />)}
+    </ul>
+
+const CRootCategories = connect(state=>({cats: state.promise.rootCats?.payload || []}))(RootCategories)
+
+
+const Aside =()=>
+    <aside>
+        <CRootCategories />
+    </aside>
+
+const Content =({children})=>
+    <div className='Content'>
+        {children}
+    </div>
+
+const defaultCat = {
+    "subCategories": null,
+    "_id": "5dc458985df9d670df48cc47",
+    "name": "     Smartphones",
+    "goods": [
+        {
+            "_id": "5dc4a3e15df9d670df48cc6b",
+            "name": "Apple iPhone 11 Pro Max 64GB Gold",
+            "price": 1500,
+            "images": [
+                {
+                    "url": "images/b599634ebfecf2a19d900e22434bedbd"
+                }
+            ]
+        },
+        {
+            "_id": "5dc4a4365df9d670df48cc6c",
+            "name": "Apple iPhone XS Max 256GB Gold",
+            "price": 1300,
+            "images": [
+                {
+                    "url": "images/63c4a052377862494e33746b375903f6"
+                }
+            ]
+        },
+        {
+            "_id": "61b1056cc750c12ba6ba4522",
+            "name": "iPhone ",
+            "price": 1000,
+            "images": [
+                {
+                    "url": "images/cc23c15a3ae1ac60582785ebf9b3d207"
+                }
+            ]
+        },
+        {
+            "_id": "61b105f9c750c12ba6ba4524",
+            "name": "iPhone ",
+            "price": 1200,
+            "images": [
+                {
+                    "url": "images/50842a3af34bfa28be037aa644910d07"
+                }
+            ]
+        },
+        {
+            "_id": "61b1069ac750c12ba6ba4526",
+            "name": "iPhone ",
+            "price": 1000,
+            "images": [
+                {
+                    "url": "images/d12b07d983dac81ccad404582a54d8be"
+                }
+            ]
+        },
+        {
+            "_id": "61b23f94c750c12ba6ba472a",
+            "name": "name1",
+            "price": 1214,
+            "images": [
+                {
+                    "url": null
+                }
+            ]
+        },
+        {
+            "_id": "61b23fbac750c12ba6ba472c",
+            "name": "smart",
+            "price": 1222,
+            "images": [
+                {
+                    "url": "images/871f4e6edbf86c35f70b72dcdebcd8b2"
+                }
+            ]
+        }
+    ]
+}
+
+const SubCategories = ({cats}) =>
+	<></>
+
+const GoodCard = ({good: {_id,name,price,images}={}, onCartAdd}) =>
+	<div className='GoodCard'>
+		<h2>{name}</h2>
+		{images && images[0] && images[0].url && <img src={backURL+'/'+images[0].url} />}
+		<strong>{price}</strong>
+		<button onClick={()=>onCartAdd({_id,name,price,images})}>+</button>
+	</div>
+
+const CGoodCard = connect(null, {onCartAdd: actionCartAdd})(GoodCard)
+
+const Category = ({cat:{_id,name,goods,price,subCategories}=defaultCat}) =>
+	<div className="Category">
+		<h1>{name}</h1>
+		{subCategories && <SubCategories cats={subCategories} />}
+		{goods.map(good=> <CGoodCard good={good} />)}
+	</div>
+
+const CCategory = connect(state=>({cat: state.promise.catById?.payload}))(Category)
+
+const CCart = connect()
+
+const Main = ()=>
+    <main>
+        <Aside />
+        <Content>
+            <CCategory />
+        </Content>
+    </main>
+
+const JSONTest = ({data}) =>
+	<pre>
+		{JSON.stringify(data,null,4)}
+	</pre>
+
+const ReduxJSON = connect(state => ({data:state.promise}))(JSONTest)
+
+const ListItem = ({item}) => 
+	<li>{item}</li> 
+
+const List = ({data=["пиво","чипсы","сиги"]}) =>
+	<ul>
+		{data.map(item=><ListItem item={item} />)}
+	</ul>
+
+const _ = React.createElement.bind(React);
+
+const List2 = ({data=["пиво","чипсы","сиги"]}) =>
+	_('h1',null,
+		data.map(item=> _(ListItem,{item}))
+	)
+
+const Input = () =>{
+	const [text, setText] = useState("text");
+	return(
+		<>
+			<h1>{text}</h1>
+			<h1>{text.toLowerCase()}</h1>
+			<h1>{text.length}</h1>
+			<input value={text} onChange={e=>setText(e.target.value)}/>
+		</>
+		
+	)
+}
+
+const RGBInput = () =>{
+	const [red, setRed] = useState(0)
+	const [green, setGreen] = useState(0)
+	const [blue, setBlue] = useState(0)
+	const color = `rgba(${red},${green},${blue})`
+	const bounds = x => x<0 ? 0 : ( x>255 ? 255 : x)
+	useEffect(()=>{
+		console.log('component didMount')
+		return ()=>{
+			console.log('component willUnMount')
+		}
+	},[red])
+	return(
+		<div style={{backgroundColor:color}}>
+			<input type='number' min='0' max='255' value={red} onChange={e=>setRed(bounds(+e.target.value))} />
+			<input type='number' min='0' max='255' value={green} onChange={e=>setGreen(bounds(+e.target.value))} />
+			<input type='number' min='0' max='255' value={blue} onChange={e=>setBlue(bounds(+e.target.value))} />
+		</div>
+	)
+}
+
+const Timer = ({ms=1000, onDelete}) => {
+	const [count, setCount] = useState(0);
+	const ref = useRef(0)
+	useEffect(() => {
+		console.log('+EFFECT');
+		const interval = setInterval(()=>{
+			setCount(count => count+1)
+			//console.log(count)
+		},ms)
+		return () =>{
+			console.log('-EFFECT')
+			clearInterval(interval)
+		} 
+	},[ms])
+	//console.log(ref.current++)
+	return(
+		<>
+			<h3>{count}</h3>
+			<button onClick={onDelete}>x</button>
+		</>
+	)
+}
+
+const Timers = () =>{
+	const [timers, setTimers] = useState([])
+	const [ms, setMS] = useState(1000)
+	console.log(timers)
+	return(
+		<>
+			<button onClick={()=>setMS(ms+100)}>+</button>{ms}
+			<button onClick={()=>setMS(ms-100)}>-</button>
+			<button onClick={()=>setTimers([Math.random(), ...timers])}>+</button>
+			{timers.map(i=> <Timer key={i} ms={ms}
+					onDelete={()=>setTimers(timers.filter(t=>t!==i))} />)}
+		</>
+	)
+}
+
+const LoginForm = ({onLogin}) =>{
+	const [login, setLogin] = useState(''); //braunvlad4
+	const [pass, setPass] = useState('');   //123
+	return( 
+		<div className='LoginForm'>
+			<input value={login} style={{backgroundColor: login.length>0 ? 'green' : 'red'}} 
+						placeholder='your login' onChange={e=>setLogin(e.target.value)} />
+			<input value={pass} style={{backgroundColor: pass.length>0 ? 'green' : 'red'}} 
+						placeholder='your pass' onChange={e=>setPass(e.target.value)} />
+			<button onClick={()=>onLogin(login,pass)} disabled={(login.length!==0 && pass.length!==0)?false:true }>Send</button>
+		</div>
+	)
+}
+
+const CLoginForm = connect(null, {onLogin: actionFullLogin})(LoginForm)
+
+
+const Spoiler = ({children}) => {
+	const [open, setOpen] = useState(false);
+	return(
+		<div >
+			<h3 onClick={e=>setOpen(!open)}>{open?'hide':'show'}</h3>
+			{open && children}
+		</div>
+	)
+}
+
+function App() {
+  return (
+  	<Provider store={store}>
+	    <div className="App">
+	    <Timers />
+	    
+	      <Header />
+	      <Main />
+	      <Footer />
+	    </div>
+	</Provider>
+  );
+}
+
+export default App;
+
+

+ 46 - 0
React/HW_React_3/InClass/src/App.scss

@@ -0,0 +1,46 @@
+
+.GoodCard{
+  border: 1px solid cyan;
+  border-radius: 15px;
+  img{
+    max-width: 50%;
+  }
+}
+
+.GoodCard2{
+  border: 1px solid cyan;
+  border-radius: 15px;
+  height: 300px;
+  margin: 40px;
+  img{
+    max-width: 15%;
+  }
+}
+
+.App {
+  header{
+      .Logo{
+          img{
+              max-height:100px;
+          }
+      }
+  }
+
+  footer{
+    background-color: #303030; 
+      .Logo{
+          img{
+              max-height:200px;
+          }
+      }
+  }
+
+  main{
+    display:flex;
+    flex-direction: row;
+    aside{
+      width:30%;
+      background-color: cyan;
+    }
+  }
+}

+ 8 - 0
React/HW_React_3/InClass/src/App.test.js

@@ -0,0 +1,8 @@
+import { render, screen } from '@testing-library/react';
+import App from './App';
+
+test('renders learn react link', () => {
+  render(<App />);
+  const linkElement = screen.getByText(/learn react/i);
+  expect(linkElement).toBeInTheDocument();
+});

+ 13 - 0
React/HW_React_3/InClass/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;
+}

+ 17 - 0
React/HW_React_3/InClass/src/index.js

@@ -0,0 +1,17 @@
+import React from 'react';
+import ReactDOM from 'react-dom';
+import './index.css';
+import App from './App';
+import reportWebVitals from './reportWebVitals';
+
+ReactDOM.render(
+  <React.StrictMode>
+    <App />
+  </React.StrictMode>,
+  document.getElementById('root')
+);
+
+// If you want to start measuring performance in your app, pass a function
+// to log results (for example: reportWebVitals(console.log))
+// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
+reportWebVitals();

File diff suppressed because it is too large
+ 1 - 0
React/HW_React_3/InClass/src/logo.svg


+ 13 - 0
React/HW_React_3/InClass/src/reportWebVitals.js

@@ -0,0 +1,13 @@
+const reportWebVitals = onPerfEntry => {
+  if (onPerfEntry && onPerfEntry instanceof Function) {
+    import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
+      getCLS(onPerfEntry);
+      getFID(onPerfEntry);
+      getFCP(onPerfEntry);
+      getLCP(onPerfEntry);
+      getTTFB(onPerfEntry);
+    });
+  }
+};
+
+export default reportWebVitals;

+ 5 - 0
React/HW_React_3/InClass/src/setupTests.js

@@ -0,0 +1,5 @@
+// jest-dom adds custom jest matchers for asserting on DOM nodes.
+// allows you to do things like:
+// expect(element).toHaveTextContent(/react/i)
+// learn more: https://github.com/testing-library/jest-dom
+import '@testing-library/jest-dom';