|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
767 bytes
|
| Line | |
|---|
| 1 | import { useEffect, useState } from 'react';
|
|---|
| 2 | import { useAppDispatch, useAppSelector } from '../state/hooks';
|
|---|
| 3 | import { selectContainerScale } from '../state/selectors/containerSelectors';
|
|---|
| 4 | import { setScale } from '../state/layoutSlice';
|
|---|
| 5 | import { isWellBehavedNumber } from './isWellBehavedNumber';
|
|---|
| 6 | export function useReportScale() {
|
|---|
| 7 | var dispatch = useAppDispatch();
|
|---|
| 8 | var [ref, setRef] = useState(null);
|
|---|
| 9 | var scale = useAppSelector(selectContainerScale);
|
|---|
| 10 | useEffect(() => {
|
|---|
| 11 | if (ref == null) {
|
|---|
| 12 | return;
|
|---|
| 13 | }
|
|---|
| 14 | var rect = ref.getBoundingClientRect();
|
|---|
| 15 | var newScale = rect.width / ref.offsetWidth;
|
|---|
| 16 | if (isWellBehavedNumber(newScale) && newScale !== scale) {
|
|---|
| 17 | dispatch(setScale(newScale));
|
|---|
| 18 | }
|
|---|
| 19 | }, [ref, dispatch, scale]);
|
|---|
| 20 | return setRef;
|
|---|
| 21 | } |
|---|
Note:
See
TracBrowser
for help on using the repository browser.