This commit is contained in:
ilia 2023-02-18 17:44:04 +03:00
parent 101fce0027
commit f3e676e163
25 changed files with 5329 additions and 129 deletions

2246
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,8 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@ant-design/icons": "^5.0.1",
"@reduxjs/toolkit": "^1.9.2",
"@testing-library/jest-dom": "^5.16.5", "@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0", "@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
@ -10,9 +12,15 @@
"@types/node": "^16.18.12", "@types/node": "^16.18.12",
"@types/react": "^18.0.28", "@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11", "@types/react-dom": "^18.0.11",
"antd": "^5.2.1",
"chart.js": "^4.2.1",
"mapbox-gl": "^2.12.1",
"react": "^18.2.0", "react": "^18.2.0",
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-redux": "^8.0.5",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"redux": "^4.2.1",
"typescript": "^4.9.5", "typescript": "^4.9.5",
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4"
}, },
@ -39,5 +47,8 @@
"last 1 firefox version", "last 1 firefox version",
"last 1 safari version" "last 1 safari version"
] ]
},
"devDependencies": {
"@types/mapbox-gl": "^2.7.10"
} }
} }

View File

@ -29,6 +29,17 @@
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div> <div id="root"></div>
<style>
*::-webkit-scrollbar{
display: none;
margin: 0;
padding: 0;
}
html, body {
margin: 0;
padding: 0;
}
</style>
<!-- <!--
This HTML file is a template. This HTML file is a template.
If you open it directly in the browser, you will see an empty page. If you open it directly in the browser, you will see an empty page.

View File

@ -1,25 +1,75 @@
{ {
"short_name": "React App", "type": "FeatureCollection",
"name": "Create React App Sample", "features": [
"icons": [
{ {
"src": "favicon.ico", "type": "Feature",
"sizes": "64x64 32x32 24x24 16x16", "properties": {},
"type": "image/x-icon" "geometry": {
}, "coordinates": [
{ [
"src": "logo192.png", [
"type": "image/png", 38.97435150857382,
"sizes": "192x192" 45.03685091234638
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
], ],
"start_url": ".", [
"display": "standalone", 38.97472067652055,
"theme_color": "#000000", 45.03502477072638
"background_color": "#ffffff" ],
} [
38.97909795361895,
45.0348756953683
],
[
38.97779707608811,
45.03800619633563
],
[
38.97458004111226,
45.03887574954416
],
[
38.97435150857382,
45.03685091234638
]
]
],
"type": "Polygon"
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"coordinates": [
[
[
38.98086009242405,
45.04116708161084
],
[
38.98239972998363,
45.03441672335501
],
[
38.996921311506526,
45.032908292697954
],
[
39.001680191235636,
45.040079165613804
],
[
38.988383321406275,
45.04541964565914
],
[
38.98086009242405,
45.04116708161084
]
]
],
"type": "Polygon"
}
}
]
}

421
public/schema.geojson Normal file
View File

@ -0,0 +1,421 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "ЖК Смородина"
},
"geometry": {
"coordinates": [
[
[
39.119253721819206,
45.05896785426384
],
[
39.11925847801547,
45.05893557216024
],
[
39.11924317547289,
45.058933965358335
],
[
39.11924586375724,
45.058905773279434
],
[
39.119142468204586,
45.05890022250583
],
[
39.119153491687,
45.05882204109608
],
[
39.11935135882666,
45.0588342302938
],
[
39.11933475708844,
45.05897220025676
],
[
39.119253721819206,
45.05896785426384
]
]
],
"type": "Polygon"
}
},
{
"type": "Feature",
"properties": {
"name": "ЖК The Grand Palace"
},
"geometry": {
"coordinates": [
[
[
39.04465483733625,
45.03246383780905
],
[
39.0446209797575,
45.0326313290482
],
[
39.04435223522407,
45.03260291539016
],
[
39.04441254403736,
45.032294102884066
],
[
39.045520321696074,
45.03240626258261
],
[
39.04545260653853,
45.03271582221035
],
[
39.04519126835203,
45.03268666086754
],
[
39.045227242029,
45.03251991751969
],
[
39.04465483733625,
45.03246383780905
]
]
],
"type": "Polygon"
}
},
{
"type": "Feature",
"properties": {
"name": "ЖК AVrorA"
},
"geometry": {
"coordinates": [
[
[
38.9740593901287,
45.06526204827489
],
[
38.974200885421595,
45.06535463805176
],
[
38.97357039904412,
45.06581758468678
],
[
38.97293388082494,
45.065241836272264
],
[
38.97327765735611,
45.06455846912701
],
[
38.973454837791195,
45.064612452891964
],
[
38.97315606294069,
45.06522099362306
],
[
38.97359380283771,
45.06561605087191
],
[
38.9740593901287,
45.06526204827489
]
]
],
"type": "Polygon"
}
},
{
"type": "Feature",
"properties": {
"name": "ЖК Зеленодар"
},
"geometry": {
"coordinates": [
[
[
38.97791761543695,
45.130320921601594
],
[
38.97868373474017,
45.13025771337027
],
[
38.978897663041266,
45.13038670968649
],
[
38.978914191362236,
45.131278879355904
],
[
38.97870376482973,
45.131277112062094
],
[
38.978731320684886,
45.13045884894731
],
[
38.978613582029595,
45.130400527370114
],
[
38.97795725165406,
45.130460616267044
],
[
38.97791761543695,
45.130320921601594
]
]
],
"type": "Polygon"
}
},
{
"type": "Feature",
"properties": {
"name": "ЖК Fresh"
},
"geometry": {
"coordinates": [
[
[
39.015984458166514,
45.05472419130953
],
[
39.01600884332123,
45.054558817331184
],
[
39.016155154247855,
45.05456915321906
],
[
39.01611613800094,
45.054731081881584
],
[
39.015984458166514,
45.05472419130953
]
]
],
"type": "Polygon"
}
},
{
"type": "Feature",
"properties": {
"name": "ЖК Novella"
},
"geometry": {
"coordinates": [
[
[
38.95407026619753,
45.10308630860189
],
[
38.952945728338506,
45.10105232285309
],
[
38.95419075239644,
45.100740485879584
],
[
38.955104439408245,
45.10279574364566
],
[
38.95407026619753,
45.10308630860189
]
]
],
"type": "Polygon"
}
},
{
"type": "Feature",
"properties": {
"name": "ЖК Role clef"
},
"geometry": {
"coordinates": [
[
[
38.96527640192815,
45.01414715205041
],
[
38.96495135814928,
45.01420005191696
],
[
38.96487185103783,
45.013948777114734
],
[
38.96500981925976,
45.01368592926687
],
[
38.96492797370448,
45.01345118362832
],
[
38.96512674148235,
45.013424733355265
],
[
38.96521326392687,
45.01372229822351
],
[
38.9651010185936,
45.01393389896731
],
[
38.96513843370474,
45.01402812717154
],
[
38.9652366483717,
45.01401159591862
],
[
38.96527640192815,
45.01414715205041
]
]
],
"type": "Polygon"
}
},
{
"type": "Feature",
"properties": {
"name": "ЖК Спортивный парк"
},
"geometry": {
"coordinates": [
[
[
39.112477183311626,
45.046570607767535
],
[
39.112470082077266,
45.045741083410064
],
[
39.11263341047115,
45.045717669241355
],
[
39.11263577755025,
45.04659402158711
],
[
39.112477183311626,
45.046570607767535
]
]
],
"type": "Polygon"
}
},
{
"type": "Feature",
"properties": {
"name": "ЖК Небо"
},
"geometry": {
"coordinates": [
[
[
38.94051954028302,
45.045570933567035
],
[
38.94047619059887,
45.04543237605418
],
[
38.940612432463126,
45.04541487402872
],
[
38.94065991068891,
45.04555051458601
],
[
38.94051954028302,
45.045570933567035
]
]
],
"type": "Polygon"
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"coordinates": [
[
[
39.08629056911201,
45.004181745134645
],
[
39.08654245944271,
45.00339903557091
],
[
39.08678772108004,
45.00344590470792
],
[
39.08650931597873,
45.004228613631284
],
[
39.08629056911201,
45.004181745134645
]
]
],
"type": "Polygon"
}
}
]
}

View File

@ -1,38 +0,0 @@
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

View File

@ -1,9 +0,0 @@
import React from 'react';
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();
});

View File

@ -1,24 +1,18 @@
import React from 'react'; import React from 'react';
import logo from './logo.svg'; import { Sidebar } from './components/Sidebar';
import './App.css'; import { TheMap } from './components/TheMap';
import {Provider} from 'react-redux'
import store from './store';
import 'antd/dist/reset.css';
function App() { function App() {
return ( return (
<div className="App"> <div className="App">
<header className="App-header"> <Provider store={store}>
<img src={logo} className="App-logo" alt="logo" /> <TheMap />
<p> <Sidebar />
Edit <code>src/App.tsx</code> and save to reload. </Provider>
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div> </div>
); );
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
import react from 'react'
import {Typography, Button} from 'antd'
import { TheChart } from '../../TheLine'
import {CloseOutlined} from '@ant-design/icons'
import './style.css'
import { useDispatch } from 'react-redux/es/hooks/useDispatch'
import { setActive, setName } from '../../../store/slices/sidebarSlice'
export const BuildingSection: react.FC = () => {
const dispatch = useDispatch();
return <div className='building-section__container'>
<div className="cross">
<Button
icon={<CloseOutlined />}
type='text'
onClick={() => {
dispatch(setActive(false));
dispatch(setName(''))
}}
/>
<Typography.Title level={5} style={{margin: 0}}>Статистика по ЖК</Typography.Title>
</div>
<Typography.Text>Количество квартир: <strong>315</strong></Typography.Text>
<Typography.Text>Медиана кв.м: <strong>25 кв.м</strong></Typography.Text>
<Typography.Text>Кто застройщик: <strong>ООО "Рога и копыта"</strong></Typography.Text>
<div style={{marginTop: 15}}>
<Typography.Text strong>Предсказание средней цены квартиры</Typography.Text>
<TheChart data={[1.2, 2.4, 5]} />
</div>
</div>
}

View File

@ -0,0 +1,19 @@
.building-section__container{
height: 50vh;
padding-top: 30px;
padding-left: 10px;
display: flex;
flex-direction: column;
gap: 10px;
background-color: white;
padding: 20px;
border-radius: 10px;
margin-bottom: 20px;
margin-top: 20px;
}
.cross{
display: flex;
align-items: center;
gap: 10px;
}

View File

@ -0,0 +1,22 @@
import {Typography} from 'antd';
import Divider from 'antd/es/divider';
import react from 'react'
import { TheChart } from '../../TheLine';
import './style.css'
export const FlatSection: react.FC = () => {
return <div className='flat__container'>
<Typography.Title level={5}>Статистика по квартире</Typography.Title>
<Typography.Text>Площадь: <strong>35.2 кв.м</strong></Typography.Text>
<Typography.Text>Цена: <strong>3.5 млн. руб</strong></Typography.Text>
<Typography.Text>Этаж: <strong>3-10</strong></Typography.Text>
<Typography.Text>Дата сдачи: <strong>Сдан</strong></Typography.Text>
<div style={{marginTop: 15}}>
<Typography.Text strong>Предсказание цены</Typography.Text>
<TheChart data={[1.1, 4.3, 9]}/>
</div>
</div>
}

View File

@ -0,0 +1,10 @@
.flat__container{
padding-left: 10px;
display: flex;
flex-direction: column;
gap: 5px;
background-color: white;
padding: 20px;
border-radius: 10px;
}

View File

@ -0,0 +1,19 @@
import { Divider } from 'antd'
import react from 'react'
import { useSelector } from 'react-redux/es/hooks/useSelector'
import { getActive } from '../../store/slices/sidebarSlice'
import { BuildingSection } from './BuildingSection'
import { FlatSection } from './FlatSection'
import './style.css'
export const Sidebar: react.FC = () => {
const opened = useSelector(getActive)
return <>
{opened ? <div className='sidebar__container'>
<BuildingSection />
<FlatSection />
</div> : <></>}
</>
}

View File

@ -0,0 +1,9 @@
.sidebar__container{
position: absolute;
left: 10px;
top: 0px;
height: 100vh;
z-index: 10000;
width: 360px;
}

View File

@ -0,0 +1,55 @@
import 'chart.js/auto';
import react, {useRef} from 'react'
import { Line } from "react-chartjs-2";
interface IChart{
data: number[]
}
export const TheChart: react.FC<IChart> = (props) => {
const ref = useRef();
const data = {
labels: ['1 мес.', '2 мес.', '3 мес.'],
datasets: [
{
data: props.data,
fill: true,
backgroundColor: 'rgba(75,192,192,0.2)',
borderColor: 'rgba(75,192,192,1)'
},
],
};
return <div style={{width: 340,
height: 170,}}>
<Line
data={data}
ref={ref}
style={{
width: 340,
height: 170,
transform: 'translateX(-10px)'
}}
options={{
scales: {
y: {
beginAtZero: true,
title: {
text: "млн. руб",
display: true
}
}
},
responsive: true,
maintainAspectRatio: true,
plugins: {
legend: {
display: false
}
}
}
}></Line>
</div>
}

View File

@ -0,0 +1,68 @@
import react, {useRef, useState, useEffect} from 'react'
import * as mapboxgl from 'mapbox-gl';
import 'mapbox-gl/dist/mapbox-gl.css';
import { useDispatch } from 'react-redux/es/exports';
import { setActive, setName } from '../../store/slices/sidebarSlice';
(mapboxgl as any).accessToken = 'pk.eyJ1IjoiaWxpYXZhcyIsImEiOiJjazcwdXU0dHkwMGViM21ta3VxaHB2YWNqIn0.yHEDUiatwp4dy4MM3ywnOQ';
export const TheMap: react.FC = () => {
const mapContainer = useRef(null);
const map = useRef(null as any);
const [lng, setLng] = useState(38.960);
const [lat, setLat] = useState(45.035);
const [zoom, setZoom] = useState(9);
const dispatch = useDispatch();
useEffect(() => {
if (map.current) return; // initialize map only once
map.current = new mapboxgl.Map({
container: mapContainer.current as any,
style: 'mapbox://styles/iliavas/cle9o5pi3000501kn1o6myhxp',
center: [lng, lat],
zoom: zoom
});
map.current.on('load', () => {
map.current.addSource('buildings', {
type: 'geojson',
// Use a URL for the value for the `data` property.
data: '/schema.geojson'
});
map.current.addLayer({
'id': 'buildings-layer',
'type': 'fill',
'source': 'buildings',
'paint': {
'fill-color': 'rgba(75,192,192,0.3)'
}
});
map.current.addLayer({
'id': 'buildings-layer-outline',
'type': 'line',
'source': 'buildings',
'paint': {
'line-color': 'rgba(75,192,192,1)',
'line-width': 2
}
});
map.current.on('click', 'buildings-layer', (e: any) => {
console.log(e.features[0].properties.name)
dispatch(setActive(true));
dispatch(setName(e.features[0].properties.name))
});
map.current.on('mouseenter', 'buildings-layer', () => {
map.current.getCanvas().style.cursor = 'pointer';
});
map.current.on('mouseleave', 'buildings-layer', () => {
map.current.getCanvas().style.cursor = '';
});
})
});
return <div ref={mapContainer} className="map-container" style={{width: '100vw', height: '100vh'}}/>
}

View File

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

View File

@ -1,8 +1,6 @@
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom/client'; import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App'; import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement document.getElementById('root') as HTMLElement
@ -12,8 +10,3 @@ root.render(
<App /> <App />
</React.StrictMode> </React.StrictMode>
); );
// 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();

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -1 +0,0 @@
/// <reference types="react-scripts" />

View File

@ -1,15 +0,0 @@
import { ReportHandler } from 'web-vitals';
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
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;

View File

@ -1,5 +0,0 @@
// 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';

8
src/store/index.ts Normal file
View File

@ -0,0 +1,8 @@
import { configureStore } from "@reduxjs/toolkit";
import sidebar from './slices/sidebarSlice'
const store = configureStore({reducer: {sidebar}})
export default store;
export type RootState = ReturnType<typeof store.getState>

View File

@ -0,0 +1,31 @@
import {createSlice, createSelector, PayloadAction} from '@reduxjs/toolkit'
import { RootState } from '../..';
interface ISidebarSlice{
name?: string;
active?: boolean;
}
const initialState: ISidebarSlice = {
name: '',
active: false
}
const sidebarSlice = createSlice({
name: 'sidebar',
initialState,
reducers: {
setName(state, payload: PayloadAction<string>) {
state.name = payload.payload;
},
setActive(state, payload: PayloadAction<boolean>) {
state.active = payload.payload;
}
}
})
export default sidebarSlice.reducer;
export const {setName, setActive} = sidebarSlice.actions;
export const getActive = createSelector((store: RootState) => store.sidebar.active, (a) => a)