Commit ff7f80ea authored by Nurasyl's avatar Nurasyl

Initial commit

parents
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
# Logs
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?
# React + TypeScript + 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 updating the configuration to enable type aware lint rules:
- Configure the top-level `parserOptions` property like this:
```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
<!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 + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "webinar",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@reduxjs/toolkit": "^2.2.5",
"axios": "^1.7.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^9.1.2",
"sass": "^1.77.4"
},
"devDependencies": {
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"typescript": "^5.2.2",
"vite": "^5.2.0"
}
}
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
\ No newline at end of file
.App {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 100vh;
}
\ No newline at end of file
import { Product } from "./Components/Product/Product"
import { Order } from "./Components/Order/Order"
import { useState } from "react"
import { TProduct } from "./Interfaces/product"
import { useGetProductsQuery } from "./Store/Services/product.service"
import { parseProducts } from "./Helpers/parseProducts"
export const App = () => {
const {data, isSuccess} = useGetProductsQuery('')
const [order, setOrder] = useState<TProduct[]>([])
const onClickProduct = (id: string) => {
}
const onClickOrder = () => {
}
return (
<div className={"App"}>
<Product
products={isSuccess ? parseProducts(data) : null}
onClick={onClickProduct}
/>
<Order
products={order}
onClick={onClickOrder}
/>
</div>
)
}
\ No newline at end of file
.Order {
width: 35%;
height: max-content;
border-radius: 15px;
padding: 15px;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
& .Order_list {
display: flex;
flex-direction: column;
align-items: center;
}
& .Order_btn {
width: 80%;
height: 40px;
border: 5px;
border: none;
background-color: gray;
color: white;
display: flex;
align-items: center;
justify-content: center;
}
}
\ No newline at end of file
import { OrderItem } from "./OrderItem/OrderItem"
import { TProduct } from "../../Interfaces/product"
import "./Order.scss"
type TProps = {
products: TProduct[] | null,
onClick: VoidFunction
}
export const Order = ({products, onClick}: TProps) => {
return (
<div className={"Order"}>
<div className={"Order_list"}>
{
products?.map(item => (
<OrderItem
key={item.id}
name={item.name}
price={item.price}
/>
))
}
</div>
<hr />
<button className={"Order_btn"} onClick={onClick}>
Place order
</button>
</div>
)
}
\ No newline at end of file
.OrderItem {
width: 100%;
height: 50px;
display: flex;
align-items: center;
justify-content: space-between;
margin: 10px 0;
& p {
font-size: 20px;
margin: 0;
}
}
\ No newline at end of file
import "./OrderItem.scss"
type TProps = {
name: string,
price: number
}
export const OrderItem = ({name, price}: TProps) => {
return (
<div className={"OrderItem"}>
<p>{name}</p>
<p>{price}</p>
</div>
)
}
\ No newline at end of file
.Product {
width: 40%;
height: 500px;
border-radius: 15px;
padding: 15px;
display: flex;
flex-direction: column;
align-items: center;
overflow-y: auto;
overflow-x: auto;
}
\ No newline at end of file
import "./Product.scss"
import type { TProduct } from "../../Interfaces/product"
import { ProductItem } from "./ProductItem/ProductItem"
type TProps = {
products: TProduct[] | null,
onClick: (id: string) => void
}
export const Product = ({products, onClick}: TProps) => {
return (
<div className={"Product"}>
{
products?.map(item => (
<ProductItem
url={item.url}
name={item.name}
price={item.price}
onClick={() => onClick(item.id)}
/>
))
}
</div>
)
}
\ No newline at end of file
.ProductItem {
width: 100%;
height: 90px;
border-radius: 15px;
padding: 15px;
display: flex;
align-items: center;
margin: 15px 0;
& .ProductItem_img {
width: 90px;
height: 90px;
& img {
width: 100%;
height: 100%;
}
}
& .ProductItem_info {
display: flex;
align-items: flex-start;
justify-content: space-between;
& h2 {
font-size: 25px;
font-weight: 400;
}
& p {
margin: 0;
font-size: 30px;
font-weight: 600;
}
}
& .ProductItem_btn {
height: 80px;
width: 120px;
border-radius: 5px;
border: none;
background-color: gray;
color: white;
font-size: 20px;
}
}
\ No newline at end of file
import "./ProductItem.scss"
type TProps = {
url: string,
name: string,
price: number,
onClick: VoidFunction
}
export const ProductItem = ({url, name, price, onClick}: TProps) => {
return (
<div className={"ProductItem"}>
<div className={"ProductItem_img"}>
<img src={url} alt={"product"} />
</div>
<div className={"ProductItem_info"}>
<h2>{name}</h2>
<p>{price} KZT</p>
</div>
<button className={"ProductItem_btn"} onClick={onClick}>
Add to cart
</button>
</div>
)
}
\ No newline at end of file
import { IGetProduct, TProduct } from "../Interfaces/product";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const parseProducts = (data: IGetProduct<{[key: string]: any}>): TProduct[] => {
return Object.keys(data).map(id => {
return {
id: "asdasdad",
name: data[id]?.name,
price: data[id]?.price,
url: data[id]?.url
}
})
}
\ No newline at end of file
export type TContact = {
address: string,
fullName: string,
telNum: string
}
\ No newline at end of file
export interface IGetProduct<T> {
[key: string]: T
}
export type TProduct = {
id: string,
name: string,
price: number,
url: string
}
\ No newline at end of file
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
export const ProductService = createApi({
reducerPath: "product-query",
baseQuery: fetchBaseQuery({
baseUrl: "https://burger-278a4-default-rtdb.firebaseio.com"
}),
endpoints: (builder) => ({
getProducts: builder.query({
query: () => "/products.json"
})
})
})
export const {useGetProductsQuery} = ProductService
\ No newline at end of file
import { createSlice } from "@reduxjs/toolkit";
import type { TContact } from "../../Interfaces/contcat";
import type { TProduct } from "../../Interfaces/product";
type TState = {
order: {
contact: TContact,
products: TProduct[]
} | null
}
const initialState: TState = {
order: null
}
export const BasketSlice = createSlice({
name: "basket",
initialState,
reducers: {
}
})
\ No newline at end of file
import { createSlice } from "@reduxjs/toolkit";
import { TProduct } from './../../Interfaces/product';
type TState = {
products: TProduct[] | null
}
const initialState: TState = {
products: null
}
export const ProductSlice = createSlice({
name: "product",
initialState,
reducers: {
}
})
\ No newline at end of file
import { configureStore, combineReducers } from "@reduxjs/toolkit";
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
import { ProductSlice } from "./Slices/product.slice";
import { BasketSlice } from "./Slices/basket.slice";
import { ProductService } from "./Services/product.service";
const rootReducer = combineReducers({
product: ProductSlice.reducer,
basket: BasketSlice.reducer,
[ProductService.reducerPath]: ProductService.reducer
});
export const store = configureStore({
reducer: rootReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(ProductService.middleware),
});
type RootState = ReturnType<typeof store.getState>;
type AppDispatch = typeof store.dispatch;
export const useAppDispatch: () => AppDispatch = useDispatch
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
\ No newline at end of file
import ReactDOM from 'react-dom/client'
import { Provider } from 'react-redux'
import { store } from './Store/index.ts'
import {App} from './App.tsx'
ReactDOM.createRoot(document.getElementById('root')!).render(
<Provider store={store}>
<App />
</Provider>
)
/// <reference types="vite/client" />
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"strict": true
},
"include": ["vite.config.ts"]
}
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment