Browse Source

Re-add the first homework and add the second React homework

Bonyant 2 years ago
commit
19beee8055

+ 23 - 0
1/.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
1/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
+ 12937 - 0
1/package-lock.json


+ 47 - 0
1/package.json

@@ -0,0 +1,47 @@
+{
+  "name": "18",
+  "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",
+    "bootstrap": "^5.1.3",
+    "react": "^17.0.2",
+    "react-bootstrap": "^2.0.3",
+    "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"
+    ]
+  },
+  "devDependencies": {
+    "node-sass": "^7.0.0",
+    "sass-loader": "^12.4.0"
+  }
+}

BIN
1/public/favicon.ico


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


BIN
1/public/logo512.png


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

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

+ 634 - 0
1/src/App.js

@@ -0,0 +1,634 @@
+/* eslint-disable jsx-a11y/alt-text */
+import React, { useState } from "react";
+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 "../node_modules/bootstrap/dist/css/bootstrap.min.css";
+import { Button } from "react-bootstrap";
+
+const jwtDecode = (token) => {
+  try {
+    let arrToken = token.split(".");
+    let base64Token = atob(arrToken[1]);
+    return JSON.parse(base64Token);
+  } catch (e) {
+    console.log("Error JWT: " + e);
+  }
+};
+
+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 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 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 actionLogin = (login, password) =>
+  actionPromise(
+    "login",
+    gql(
+      `query NameForMe1($login:String, $password:String){
+            login(login:$login, password:$password)
+        }`,
+      { login, password }
+    )
+  );
+
+const actionFullLogin = (login, password) => async (dispatch) => {
+  // console.log(login, password);
+  let token = await dispatch(actionLogin(login, password));
+  // console.log(token);
+  if (token) {
+    dispatch(actionAuthLogin(token));
+  }
+};
+
+const actionAuthLogin = (token) => ({ type: "AUTH_LOGIN", token });
+const actionAuthLogout = () => ({ type: "AUTH_LOGOUT" });
+
+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,
+});
+
+const actionCartChange = (good, count) => ({
+  type: "CART_CHANGE",
+  good,
+  count,
+});
+
+const actionCartRemove = (good) => ({ type: "CART_REMOVE", good });
+
+const actionCartClear = () => ({ type: "CART_CLEAR" });
+
+function promiseReducer(state = {}, { type, status, payload, error, name }) {
+  if (type === "PROMISE") {
+    return {
+      ...state,
+      [name]: { status, payload, error },
+    };
+  }
+  return state;
+}
+
+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 store = createStore(
+  combineReducers({
+    promise: promiseReducer,
+    auth: authReducer,
+    cart: cartReducer,
+  }),
+  applyMiddleware(thunk)
+);
+
+store.subscribe(() => console.log(store.getState()));
+store.dispatch(actionRootCats());
+store.dispatch(actionCatById("5dc458985df9d670df48cc47"));
+
+const Logo = ({ logo = logoDefault }) => (
+  <a href="https://www.google.com.ua/?hl=ru" className="Logo">
+    <img src={logo} />
+  </a>
+);
+
+const Cart = ({ cart }) => {
+  let count = 0;
+  let sum = Object.entries(cart).map(([, val]) => val.count);
+  count = sum.reduce((a, b) => a + b, 0);
+  return <div className="Cart">Товаров в корзине: {count}</div>;
+};
+
+const CCart = connect(({ cart }) => ({ cart }))(Cart);
+
+const Header = ({ logo = logoDefault }) => (
+  <header>
+    <Logo logo={logo} />
+    <CCart />
+  </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 className="RootCategories">
+    {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: "5dc45c3d5df9d670df48cc4a",
+      name: "AABBA",
+      price: 1000,
+      images: [
+        {
+          url: "images/1b2b030516d2c7c5b43d5b5b5ec0e25a",
+        },
+      ],
+    },
+    {
+      _id: "5dc45d0b5df9d670df48cc4b",
+      name: "Apple iPhone X 64GB Space Gray",
+      price: 5000,
+      images: [
+        {
+          url: "images/00505f5f08ac113874318dee67975aa9",
+        },
+      ],
+    },
+    {
+      _id: "5dc4617c5df9d670df48cc4c",
+      name: "Apple iPhone XR 64Gb Black",
+      price: 750,
+      images: [
+        {
+          url: "images/0671607428c0cb401a899a469395fe2f",
+        },
+      ],
+    },
+    {
+      _id: "5dc49faf5df9d670df48cc66",
+      name: "Xiaomi Redmi Note 7 4/64GB Neptune Bluel",
+      price: 3150,
+      images: [
+        {
+          url: "images/a915392b85ccad7f8572f7a597a9104d",
+        },
+      ],
+    },
+    {
+      _id: "5dc4a06e5df9d670df48cc67",
+      name: "Xiaomi Mi A3 4/128GB Not just Blue",
+      price: 220,
+      images: [
+        {
+          url: "images/32ea31cc1251b10314bfce25c4c81419",
+        },
+      ],
+    },
+    {
+      _id: "5dc4a1535df9d670df48cc68",
+      name: "Samsung Galaxy S10e 128GB Yellow",
+      price: 700,
+      images: [
+        {
+          url: "images/dee2c46e1ffafe70083831e5e631b43a",
+        },
+      ],
+    },
+    {
+      _id: "5dc4a1e35df9d670df48cc69",
+      name: "Samsung Galaxy A80 2019 8/128GB Black",
+      price: 600,
+      images: [
+        {
+          url: "images/d62dc5e3446f427f59a8b5fe922e4ac6",
+        },
+      ],
+    },
+    {
+      _id: "5dc4a26c5df9d670df48cc6a",
+      name: "Samsung Galaxy S10e 128GB Black",
+      price: 700,
+      images: [
+        {
+          url: "images/298583a975a33311c3f55cd325586a77",
+        },
+      ],
+    },
+    {
+      _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",
+        },
+      ],
+    },
+  ],
+};
+
+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
+      variant="primary"
+      onClick={() => onCartAdd({ _id, name, price, images })}
+    >
+      +
+    </Button>
+  </div>
+);
+
+const CGoodCard = connect(null, { onCartAdd: actionCartAdd })(GoodCard);
+
+const Category = ({
+  cat: { _id, name, goods, 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 CartGood = ({
+  cartGood: { good, count },
+  removeCartGood,
+  changeCartGood,
+}) => (
+  <div className="CartGood">
+    <div className="GoodImgBlock">
+      {good.images && good.images[0].url && (
+        <img src={backURL + "/" + good.images[0].url} />
+      )}
+    </div>
+    <div className="GoodInfoBlock">
+      <h2>{good.name}</h2>
+      <p>Цена: {good.price * count}$</p>
+      <p>Всего: {count} шт.</p>
+    </div>
+    <div className="GoodEditBlock">
+      <Button
+        variant="warning"
+        id="DeleteBtn"
+        onClick={() => removeCartGood(good)}
+      >
+        Delete
+      </Button>
+      <label for="CountField">Change count</label>
+      <input
+        type="number"
+        value={count}
+        min="1"
+        id="CountField"
+        onInput={(e) => changeCartGood(good, e.currentTarget.value)}
+      />
+    </div>
+  </div>
+);
+
+const CCartGood = connect(null, {
+  removeCartGood: actionCartRemove,
+  changeCartGood: actionCartChange,
+})(CartGood);
+
+const CartPage = ({ cart, clearCart }) => (
+  <div className="CartMain">
+    <h1>Корзина</h1>
+
+    {Object.entries(cart).map(([, cartGood]) => (
+      <CCartGood cartGood={cartGood} />
+    ))}
+
+    {Object.keys(cart).length === 0 ? (
+      <h2>Your cart is empty!</h2>
+    ) : (
+      <Button variant="danger" id="ClearBtn" onClick={() => clearCart()}>
+        Clear Cart
+      </Button>
+    )}
+  </div>
+);
+
+const CCartPage = connect((state) => ({ cart: state.cart }), {
+  clearCart: actionCartClear,
+})(CartPage);
+
+const LoginForm = ({ onLogin }) => {
+  const [login, setLogin] = useState("");
+  const [password, setPassword] = useState("");
+  return (
+    <div className="LoginForm">
+      <input
+        style={{ borderColor: login.length < 1 ? "red" : "" }}
+        type="text"
+        onChange={(e) => setLogin(e.target.value)}
+        placeholder="Login"
+      />
+      <input
+        style={{ borderColor: password.length < 1 ? "red" : "" }}
+        type="password"
+        onChange={(e) => setPassword(e.target.value)}
+        placeholder="Password"
+      />
+      {
+        <button
+          disabled={login.length < 1 || password.length < 1 ? true : false}
+          onClick={() => onLogin(login, password)}
+        >
+          Login
+        </button>
+      }
+    </div>
+  );
+};
+
+const CLoginForm = connect(null, { onLogin: actionFullLogin })(LoginForm);
+
+const Main = () => (
+  <main>
+    <Aside />
+    <Content>
+      <CCategory />
+    </Content>
+  </main>
+);
+
+// const JSONTest = ({ data }) => (
+//   <pre>
+//     {JSON.stringify(data, null, 4)}
+//     {Math.random() > 0.5 && <h1>Hello</h1>}
+//   </pre>
+// );
+
+// const ReduxJSON = connect((state) => ({ data: state }))(JSONTest);
+
+const ListItem = ({ item }) => <li>{item}</li>;
+
+const List = ({ data = ["пиво", "чипсы", "сиги"] }) => (
+  <ul>
+    {data.map((item) => (
+      <ListItem item={item} />
+    ))}
+  </ul>
+);
+
+const LowerCase = ({ children }) => <>{children.toLowerCase()}</>;
+
+const Input = () => {
+  const [text, setText] = useState("text");
+  // text !== "Another text" && setTimeout(() => setText("Another text"), 2000);
+  return (
+    <>
+      <h1>{text}</h1>
+      <h1>
+        <LowerCase>{text}</LowerCase>
+      </h1>
+      <h1>Length: {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},1)`;
+  const bounds = (x) => (x < 0 ? 0 : x > 255 ? 255 : x);
+  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>
+  );
+};
+
+function App() {
+  return (
+    <Provider store={store}>
+      <div className="App">
+        <CLoginForm />
+        <RGBInput />
+        <Header />
+        <Main />
+        <CCartPage />
+        <Footer />
+      </div>
+    </Provider>
+  );
+}
+
+export default App;

+ 53 - 0
1/src/App.scss

@@ -0,0 +1,53 @@
+.Logo {
+  img {
+    max-height: 100px;
+  }
+}
+
+.GoodCard {
+  border: 1px solid cyan;
+  border-radius: 15px;
+  img {
+    max-width: 50%;
+  }
+}
+
+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;
+    }
+  }
+}
+
+.CartGood {
+  display: flex;
+  justify-content: space-between;
+  img {
+    max-height: 200px;
+  }
+}
+
+.GoodCard {
+  img {
+    max-width: 40vh;
+  }
+}

+ 13 - 0
1/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;
+}

+ 11 - 0
1/src/index.js

@@ -0,0 +1,11 @@
+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")
+);

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


+ 23 - 0
2/.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
2/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
+ 12591 - 0
2/package-lock.json


+ 40 - 0
2/package.json

@@ -0,0 +1,40 @@
+{
+  "name": "2",
+  "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",
+    "node-scss": "^7.0.3",
+    "react": "^17.0.2",
+    "react-dom": "^17.0.2",
+    "react-scripts": "5.0.0",
+    "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
2/public/favicon.ico


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


BIN
2/public/logo512.png


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

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

+ 111 - 0
2/src/App.js

@@ -0,0 +1,111 @@
+import React, { useState } from "react";
+import "./App.scss";
+
+// Spoiler
+const Spoiler = ({ header = <h4>+</h4>, open, children }) => {
+  const [visible, setVisible] = useState(open);
+  return (
+    <div className="Spoiler">
+      <div className="header" onClick={() => setVisible(!visible)}>
+        {header}
+      </div>
+      <div className={visible ? "visible" : "hidden"}>{children}</div>
+    </div>
+  );
+};
+
+// RangeInput
+
+const RangeInput = ({ min = 1, max = 10 }) => {
+  const [len, setLen] = useState(min);
+  return (
+    <div className="RangeInput">
+      <label htmlFor="myInput">
+        {len < min ? `The length should be min: ${min}` : ""}
+        {len > max ? `The length should be max: ${max}` : ""}
+      </label>
+      <input
+        style={{ borderColor: len < min || len > max ? "red" : "" }}
+        type="text"
+        onInput={(e) => setLen(e.target.value.length)}
+        placeholder="Type your text"
+        id="myInput"
+      />
+    </div>
+  );
+};
+
+// PasswordConfirm
+
+const PasswordConfirm = ({ min = 4 }) => {
+  const [len, setLen] = useState(min);
+  const [firstPass, setFirstPass] = useState("");
+  const [secondPass, setSecondPass] = useState("");
+  return (
+    <div className="PasswordConfirm">
+      <label htmlFor="passFirst">
+        {len < min
+          ? `The length should be min: ${min}`
+          : !/[A-Z]/g.test(firstPass)
+          ? "The password must contain at least one capital letter"
+          : "Enter your password"}
+      </label>
+      <input
+        style={{ borderColor: len < min ? "red" : "" }}
+        type="password"
+        onInput={(e) => setLen(e.target.value.length)}
+        onChange={(e) => setFirstPass(e.target.value)}
+        id="passFirst"
+      />
+      <label htmlFor="passSecond">
+        {firstPass !== secondPass
+          ? "Passwords must match"
+          : "Repeat your password"}
+      </label>
+      <input
+        style={{
+          borderColor: len < min || firstPass !== secondPass ? "red" : "",
+        }}
+        type="password"
+        onInput={(e) => setLen(e.target.value.length)}
+        onChange={(e) => setSecondPass(e.target.value)}
+        id="passSecond"
+      />
+    </div>
+  );
+};
+
+function App() {
+  return (
+    <div className="App">
+      <Spoiler header={<h1>Заголовок</h1>} open>
+        <h2>Контент 1</h2>
+        <p>
+          Lorem ipsum dolor sit amet consectetur adipisicing elit. Laudantium
+          eveniet pariatur ut debitis harum modi. Nesciunt magnam, reiciendis
+          ipsa soluta reprehenderit iste necessitatibus fugiat non obcaecati
+          officia delectus asperiores eaque numquam quae rem esse neque. Dolorum
+          provident doloribus voluptate neque ea nostrum maxime enim. Magni
+          debitis saepe nulla pariatur consequuntur.
+        </p>
+      </Spoiler>
+      <Spoiler>
+        <h2>Контент 2</h2>
+        <p>
+          Lorem ipsum, dolor sit amet consectetur adipisicing elit. Amet quo
+          enim iusto quibusdam? Maxime amet asperiores numquam, eaque,
+          reprehenderit hic provident, a praesentium iure aperiam sapiente?
+          Earum aperiam sed odio facere, optio dignissimos debitis provident
+          pariatur expedita iure obcaecati ut alias beatae, delectus
+          accusantium, atque animi numquam. Aspernatur, placeat beatae!
+        </p>
+      </Spoiler>
+
+      <RangeInput min={2} max={10} />
+
+      <PasswordConfirm min={4} />
+    </div>
+  );
+}
+
+export default App;

+ 37 - 0
2/src/App.scss

@@ -0,0 +1,37 @@
+.Spoiler {
+  .header {
+    border: 1px solid black;
+    padding-left: 1.5em;
+    transition: opacity 0.15s linear;
+    -khtml-user-select: none;
+    user-select: none;
+    :hover {
+      text-decoration: underline;
+      cursor: pointer;
+    }
+  }
+  .visible {
+    display: block;
+  }
+  .hidden {
+    display: none;
+  }
+}
+.RangeInput {
+  label {
+    display: block;
+  }
+  input {
+    display: block;
+    outline: none;
+  }
+}
+.PasswordConfirm {
+  label {
+    display: block;
+  }
+  input {
+    display: block;
+    outline: none;
+  }
+}

+ 13 - 0
2/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;
+}

+ 11 - 0
2/src/index.js

@@ -0,0 +1,11 @@
+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")
+);

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