import {useDispatch, useSelector} from "react-redux";
import {AppState} from "../../../store/store";
import React, {useCallback, useEffect, useRef, useState} from "react";
import useComponentResizeListener from "../../../hooks/componentResizeListener";
import styles from "./Cup.module.css";
import cupDrawer from "./Cup.drawer";
import cupTools from "./Cup.tools";
import cupOptions from "./Cup.options";
import {CupItem} from "../../../hooks/rustWsServer";
import {IconButton, useTheme} from "@mui/material";
import {AddRounded, RemoveRounded, SettingsRounded} from "@mui/icons-material";
import {setCupParams} from "../../../store/cupSlice";
import {CupProps} from "./Cup.props";
This code is a React component called Cup that renders a trading cup chart. It uses a web worker (cupWorkerRef.current) to handle the logic and calculations for drawing the chart. The chart is rendered on a canvas element (canvasRef.current).
There are several state variables and props used in this component:
: Redux state variable that stores the parameters for the cup chart.
Когда dollarsVolume true - перемножать quantity на price при отрисовке строк стакана. И в воркере максимальный объем определять тоже путем перемножения цены на кол-во
cupParams
dpiScale: State variable that stores the scale factor for the device's pixel density.
canvasSize: State variable that stores the size of the canvas.
containerRef: Ref to the container div element.
canvasRef: Ref to the canvas element.
zoom: State variable that stores the zoom level of the chart.
isLoaded: State variable that stores whether the cup data has been loaded.
size: Custom hook that returns the size of the canvas.
darkMode: Boolean that stores whether the theme is set to dark mode.
dispatch: Redux dispatch function.
There are also several helper functions used in this component:
cupSubscribe: Function that subscribes to cup data for a given symbol and zoom level.
cupUnsubscribe: Function that unsubscribes from cup data for a given symbol.
sendSettings: Function that sends the cup chart settings to the web worker.
wheelHandler: Event handler for zooming the chart using the mouse wheel.
zoomAdd: Function that increases the zoom level.
zoomSub: Function that decreases the zoom level.
The component has several useEffect hooks that handle the initialization and cleanup of the web worker, as well as the rendering of the cup chart on the canvas. The settings and symbol are listened for changes, and the cup chart is subscribed to and unsubscribed from based on these changes.
When settings.dollarsVolume is true, the quantity is multiplied by the price when rendering the cup chart rows. The maximum volume is also determined by multiplying the price by the quantity in the web worker.
Overall, this component is responsible for rendering and updating the cup chart based on the selected symbol and settings.