aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/src/components/BrowserViewPlaceholder.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/renderer/src/components/BrowserViewPlaceholder.tsx')
-rw-r--r--packages/renderer/src/components/BrowserViewPlaceholder.tsx40
1 files changed, 23 insertions, 17 deletions
diff --git a/packages/renderer/src/components/BrowserViewPlaceholder.tsx b/packages/renderer/src/components/BrowserViewPlaceholder.tsx
index c07ed15..b309c4d 100644
--- a/packages/renderer/src/components/BrowserViewPlaceholder.tsx
+++ b/packages/renderer/src/components/BrowserViewPlaceholder.tsx
@@ -20,28 +20,31 @@
20 20
21import Box from '@mui/material/Box'; 21import Box from '@mui/material/Box';
22import throttle from 'lodash-es/throttle'; 22import throttle from 'lodash-es/throttle';
23import { observer } from 'mobx-react-lite'; 23import React, { ReactNode, useCallback, useRef } from 'react';
24import React, { useCallback, useRef } from 'react';
25 24
26import { useStore } from './StoreProvider'; 25import Service from '../stores/Service.js';
27
28export default observer(() => {
29 const store = useStore();
30 26
27function BrowserViewPlaceholder({
28 service,
29 children,
30}: {
31 service: Service;
32 children?: ReactNode;
33}): JSX.Element {
31 // eslint-disable-next-line react-hooks/exhaustive-deps -- react-hooks doesn't support `throttle`. 34 // eslint-disable-next-line react-hooks/exhaustive-deps -- react-hooks doesn't support `throttle`.
32 const onResize = useCallback( 35 const onResize = useCallback(
33 throttle(([entry]: ResizeObserverEntry[]) => { 36 throttle(([entry]: ResizeObserverEntry[]) => {
34 if (entry) { 37 if (entry) {
35 const { x, y, width, height } = entry.target.getBoundingClientRect(); 38 const { x, y, width, height } = entry.target.getBoundingClientRect();
36 store.setBrowserViewBounds({ 39 service.setBrowserViewBounds({
37 x: Math.round(x), 40 x: Math.round(x),
38 y: Math.round(y), 41 y: Math.round(y),
39 width: Math.round(width), 42 width: Math.round(width),
40 height: Math.round(height), 43 height: Math.round(height),
41 }); 44 });
42 } 45 }
43 }, 40), 46 }, 100),
44 [store], 47 [service],
45 ); 48 );
46 49
47 const resizeObserverRef = useRef<ResizeObserver | undefined>(); 50 const resizeObserverRef = useRef<ResizeObserver | undefined>();
@@ -58,15 +61,18 @@ export default observer(() => {
58 resizeObserverRef.current = new ResizeObserver(onResize); 61 resizeObserverRef.current = new ResizeObserver(onResize);
59 resizeObserverRef.current.observe(element); 62 resizeObserverRef.current.observe(element);
60 }, 63 },
61 [onResize, resizeObserverRef], 64 [onResize],
62 ); 65 );
63 66
64 return ( 67 return (
65 <Box 68 <Box ref={ref} flex={1} overflow="auto">
66 sx={{ 69 {children}
67 flex: 1, 70 </Box>
68 }}
69 ref={ref}
70 />
71 ); 71 );
72}); 72}
73
74BrowserViewPlaceholder.defaultProps = {
75 children: undefined,
76};
77
78export default BrowserViewPlaceholder;