Skip to content

Volodymyr-react-w2 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions week1/project/ecommerce/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chore: please remove week1 files from this commit (but not from the project itself)

logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
14 changes: 14 additions & 0 deletions week1/project/ecommerce/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend using TypeScript and enable type-aware lint rules. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.

<!-- link to my App: jovial-nougat-94c98a.netlify.app -->
33 changes: 33 additions & 0 deletions week1/project/ecommerce/components/Categories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { useState } from 'react';
import Category from './Category.jsx';
import allCategories from '../src/fake-data/all-categories.js';
import products from '../src/fake-data/all-products.js';
import css from './Categories.module.css';

const Categories = () => {
const [filtered, setFiltered] = useState(products);

const handlerProduct = (category) => {
const cleanCategory = category.replace(/^FAKE:\s*/, '');
const filteredArr = products.filter((product) => {
return product.category === cleanCategory;
});
setFiltered(filteredArr);
};

return (
<>
<Category arr={allCategories} onClick={handlerProduct} />
<ul className={css.gridContainer}>
{filtered.map((product) => (
<li className={css.item} key={product.id}>
<img className={css.img} src={product.image} alt={product.title} />
<p className={css.title}>{product.title}</p>
</li>
))}
</ul>
</>
);
};

export default Categories;
17 changes: 17 additions & 0 deletions week1/project/ecommerce/components/Categories.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.gridContainer {
display: grid;
gap: 1rem;
grid-template-columns: 1fr;
}

@media (min-width: 600px) {
.gridContainer {
grid-template-columns: repeat(2, 1fr);
}
}

@media (min-width: 1000px) {
.gridContainer {
grid-template-columns: repeat(3, 1fr);
}
}
24 changes: 24 additions & 0 deletions week1/project/ecommerce/components/Category.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import css from './Category.module.css';

const Category = ({ arr, onClick }) => {
return (
<div className={css.container}>
{arr.map((category) => {
return (
<>
<button
className={css.button}
key={category.index}
onClick={() => onClick(category)}
>
{category}
</button>
</>
);
})}
</div>
);
};

export default Category;
24 changes: 24 additions & 0 deletions week1/project/ecommerce/components/Category.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.container {
display: flex;
gap: 5px;
}

/*
.button {
background-color: lightgray;
}

.button.hover {
background-color: darkgray;
} */

.button {
background-color: lightgray;
color: black;
transition: 0.3s ease;
}

.button:hover {
background-color: darkgray;
color: white;
}
12 changes: 12 additions & 0 deletions week1/project/ecommerce/components/Products.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import Categories from './Categories';

const Products = () => {
return (
<div>
<Categories />
</div>
);
};

export default Products;
33 changes: 33 additions & 0 deletions week1/project/ecommerce/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'

export default [
{ ignores: ['dist'] },
{
files: ['**/*.{js,jsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...js.configs.recommended.rules,
...reactHooks.configs.recommended.rules,
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
]
13 changes: 13 additions & 0 deletions week1/project/ecommerce/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
Loading