diff --git a/desktop-app/src/renderer/components/Previewer/Device/Toolbar.tsx b/desktop-app/src/renderer/components/Previewer/Device/Toolbar.tsx index 03bbe5ea..60b5226b 100644 --- a/desktop-app/src/renderer/components/Previewer/Device/Toolbar.tsx +++ b/desktop-app/src/renderer/components/Previewer/Device/Toolbar.tsx @@ -7,32 +7,28 @@ import { Device } from 'common/deviceList'; import WebPage from 'main/screenshot/webpage'; import screenshotSfx from 'renderer/assets/sfx/screenshot.mp3'; -import { selectRotate, setRotate } from 'renderer/store/features/renderer'; -import { useDispatch, useSelector } from 'react-redux'; interface Props { webview: Electron.WebviewTag | null; - deviceID: string; device: Device; setScreenshotInProgress: (value: boolean) => void; openDevTools: () => void; + onRotate: (state: boolean) => void; } const Toolbar = ({ webview, - deviceID, device, setScreenshotInProgress, openDevTools, - + onRotate, }: Props) => { const [eventMirroringOff, setEventMirroringOff] = useState(false); const [playScreenshotDone] = useSound(screenshotSfx, { volume: 0.5 }); const [screenshotLoading, setScreenshotLoading] = useState(false); const [fullScreenshotLoading, setFullScreenshotLoading] = useState(false); - const rotatedDevices = useSelector(selectRotate); - const dispatch = useDispatch(); + const [rotated, setRotated] = useState(false); const toggleEventMirroring = async () => { if (webview == null) { @@ -118,21 +114,8 @@ const Toolbar = ({ }; const rotate = async () => { - try { - if (rotatedDevices[deviceID]) { - const obj = {...rotatedDevices}; - - obj[deviceID] = { - inSingle: !(obj[deviceID].inSingle), - rotate: !(obj[deviceID].rotate) - }; - - dispatch(setRotate({...obj})); - } - } catch (error) { - // eslint-disable-next-line no-console - console.error('Error while rotate single screen', error); - } + setRotated(!rotated); + onRotate(!rotated); }; return ( @@ -171,17 +154,11 @@ const Toolbar = ({ - diff --git a/desktop-app/src/renderer/components/Previewer/Device/index.tsx b/desktop-app/src/renderer/components/Previewer/Device/index.tsx index 9845e4a0..71f15e25 100644 --- a/desktop-app/src/renderer/components/Previewer/Device/index.tsx +++ b/desktop-app/src/renderer/components/Previewer/Device/index.tsx @@ -41,7 +41,6 @@ import Toolbar from './Toolbar'; import { appendHistory } from './utils'; interface Props { - id: string; device: IDevice; isPrimary: boolean; } @@ -51,28 +50,31 @@ interface ErrorState { description: string; } -const Device = ({ isPrimary, device, id }: Props) => { - const rotatedDevices = useSelector(selectRotate); - let { height, width } = device; - if (rotatedDevices[id]?.rotate) { - const temp = width; - width = height; - height = temp; - } - const address = useSelector(selectAddress); +const Device = ({ isPrimary, device }: Props) => { + const [singleRotated, setSingleRotated] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [screenshotInProgress, setScreenshotInProgess] = useState(false); - const dispatch = useDispatch(); + const address = useSelector(selectAddress); const zoomfactor = useSelector(selectZoomFactor); const isInspecting = useSelector(selectIsInspecting); + const rotateDevices = useSelector(selectRotate); const isDevtoolsOpen = useSelector(selectIsDevtoolsOpen); const devtoolsOpenForWebviewId = useSelector(selectDevtoolsWebviewId); + const dispatch = useDispatch(); const dockPosition = useSelector(selectDockPosition); const ref = useRef(null); + let { height, width } = device; + + if (rotateDevices || singleRotated) { + const temp = width; + width = height; + height = temp; + } + const registerNavigationHandlers = useCallback(() => { webViewPubSub.subscribe(NAVIGATION_EVENTS.RELOAD, () => { if (ref.current) { @@ -184,6 +186,8 @@ const Device = ({ isPrimary, device, id }: Props) => { ] ); + const onRotateHandler = (state: boolean) => setSingleRotated(state); + useEffect(() => { if (!ref.current) { return; @@ -383,11 +387,11 @@ const Device = ({ isPrimary, device, id }: Props) => { {loading ? : null}
{ const activeSuite = useSelector(selectActiveSuite); @@ -18,11 +17,6 @@ const Previewer = () => { const dockPosition = useSelector(selectDockPosition); const isDevtoolsOpen = useSelector(selectIsDevtoolsOpen); const layout = useSelector(selectLayout); - const dispatch = useDispatch(); - - useEffect(() => { - dispatch(setRotate(devices.reduce((acc, device) => ({ ...acc, [device.name]: { inSingle: false, rotate: false } }), {}))); - }, []); return (
@@ -37,16 +31,9 @@ const Previewer = () => { 'flex-wrap': layout === PREVIEW_LAYOUTS.FLEX, })} > - {devices.map((device, idx) => { - return ( - - ); - })} + {devices.map((device, idx) => ( + + ))}
{isDevtoolsOpen && dockPosition !== DOCK_POSITION.UNDOCKED ? ( diff --git a/desktop-app/src/renderer/components/ToolBar/index.tsx b/desktop-app/src/renderer/components/ToolBar/index.tsx index e70eac16..8c0c61d0 100644 --- a/desktop-app/src/renderer/components/ToolBar/index.tsx +++ b/desktop-app/src/renderer/components/ToolBar/index.tsx @@ -12,13 +12,11 @@ import Button from '../Button'; import AddressBar from './AddressBar'; import ColorSchemeToggle from './ColorSchemeToggle'; import { PreviewSuiteSelector } from './PreviewSuiteSelector'; -import { useState } from 'react'; const Divider = () =>
; const ToolBar = () => { - const rotatedDevices = useSelector(selectRotate); - const [ allDevicesRotated, setAllDevicesRotated ] = useState(false); + const rotateDevices = useSelector(selectRotate); const isInspecting = useSelector(selectIsInspecting); const dispatch = useDispatch(); @@ -27,27 +25,13 @@ const ToolBar = () => {