Using redux selector in layer rather than viewport.

This commit is contained in:
Eric van der Vlist 2022-09-12 09:01:54 +02:00
parent ec0883ac54
commit d4f3e96743
2 changed files with 10 additions and 11 deletions

View File

@ -1,21 +1,25 @@
import react from 'react'; import react from 'react';
import { useSelector } from 'react-redux';
import { ViewportState } from './viewport'; import { ViewportState } from './viewport';
import '../theme/layer.css'; import '../theme/layer.css';
const Layer: react.FC<{ const Layer: react.FC<{
viewportState: ViewportState;
children?: JSX.Element; children?: JSX.Element;
}> = (props: { viewportState: ViewportState; children?: JSX.Element }) => { }> = (props: { children?: JSX.Element }) => {
const { children: children, ...argProps } = props; const viewportState = useSelector(
console.log(`--- Rendering layer, props: ${JSON.stringify(argProps)} ---`); (state: { slippy: ViewportState }) => state.slippy
);
console.log(
`--- Rendering layer, viewportState: ${JSON.stringify(viewportState)} ---`
);
return ( return (
<div <div
className='background' className='background'
style={{ style={{
transform: `translate(${props.viewportState.translation.x}px, ${props.viewportState.translation.y}px) scale(${props.viewportState.scale})`, transform: `translate(${viewportState.translation.x}px, ${viewportState.translation.y}px) scale(${viewportState.scale})`,
}} }}
> >
{props.children} {props.children}

View File

@ -24,7 +24,6 @@ export interface Scale {
}; };
} }
interface ViewportProps { interface ViewportProps {
children: any; children: any;
} }
@ -37,16 +36,12 @@ export interface ViewportState {
const Viewport: react.FC<ViewportProps> = (props: ViewportProps) => { const Viewport: react.FC<ViewportProps> = (props: ViewportProps) => {
//console.log(`--- Rendering viewport, props: ${JSON.stringify(props)} ---`); //console.log(`--- Rendering viewport, props: ${JSON.stringify(props)} ---`);
const state = useSelector(
(globalState: { slippy: ViewportState }) => globalState.slippy
);
return ( return (
<div className='viewport'> <div className='viewport'>
<MouseHandler> <MouseHandler>
<SingleTouchHandler> <SingleTouchHandler>
<DoubleTouchHandler> <DoubleTouchHandler>
<Layer viewportState={state}>{props.children}</Layer> <Layer>{props.children}</Layer>
</DoubleTouchHandler> </DoubleTouchHandler>
</SingleTouchHandler> </SingleTouchHandler>
</MouseHandler> </MouseHandler>