From f50f22190e1a5b0206225dc585e2e71d9135f6d3 Mon Sep 17 00:00:00 2001 From: Ari Date: Mon, 16 May 2022 21:50:05 -0400 Subject: [PATCH] mobile mode --- .../AutomationList/index.mobile.css | 69 +++++++++++++++++++ .../src/components/AutomationList/index.tsx | 13 +++- webapp/src/components/SizeModal.tsx | 15 ++++ webapp/src/utils/useWindowSize.ts | 28 ++++---- 4 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 webapp/src/components/AutomationList/index.mobile.css create mode 100644 webapp/src/components/SizeModal.tsx diff --git a/webapp/src/components/AutomationList/index.mobile.css b/webapp/src/components/AutomationList/index.mobile.css new file mode 100644 index 0000000..ac292ce --- /dev/null +++ b/webapp/src/components/AutomationList/index.mobile.css @@ -0,0 +1,69 @@ +/* none-hidden */ +.automation-list--root.mobile { + flex-direction: column; +} + +.automation-list--root.mobile>.automation-list--list { + max-width: 100vw; + min-height: 100vh; +} + +.automation-list--root.mobile .automation-editor { + flex-direction: column; +} + +.automation-list--root.mobile .automation-list--list-hide { + transform: rotate(90deg); + left: 1.25em; +} + +.automation-list--root.mobile .automation-editor--info-box { + min-width: 100vw; + min-height: 100vh; + max-width: 100vw; + max-height: 100vh; + padding: 0; +} + +.automation-list--root.mobile .automation-editor--info-box-inner { + margin-top: 1.75em; + padding: 0.5em; + direction: rtl; +} + +.automation-list--root.mobile .automation-editor--info-box--icon { + left: 1.25em; + bottom: 1em; + background-color: var(--primary); + transform: rotate(90deg); +} + + +/* list hide */ +.automation-list--root.mobile .automation-list--list.hide { + width: 100vw; + min-height: 0; + max-height: 0; +} + +.automation-list--root.mobile .automation-list--list.hide .automation-list--list-hide { + transform: rotate(270deg); + position: fixed; + top: 0.75em; + z-index: 20; +} + +/* info box hide */ +.automation-list--root.mobile .automation-editor--info-box.hide { + width: 100vw; + min-height: 0; + max-height: 0; +} + +.automation-list--root.mobile .automation-editor--info-box.hide .automation-editor--info-box--icon { + transform: rotate(270deg); + position: fixed; + top: 0.75em; + background-color: var(--green-opaque); + z-index: 30; +} \ No newline at end of file diff --git a/webapp/src/components/AutomationList/index.tsx b/webapp/src/components/AutomationList/index.tsx index 8586201..62dc191 100644 --- a/webapp/src/components/AutomationList/index.tsx +++ b/webapp/src/components/AutomationList/index.tsx @@ -1,4 +1,5 @@ import "./index.css"; +import "./index.mobile.css"; import { AutomationEditor } from "components/AutomationEditor"; import { FC, useState } from "react"; import { AutomationData } from "types/automations"; @@ -8,6 +9,7 @@ import { ButtonIcon } from "components/Icons/ButtonIcons"; import { ApiService } from "apiService/core"; import { AutomationListBox } from "./AutomationListBox"; import { DAGAutomationFlowDims } from 'components/DAGFlow/types'; +import useWindowSize from "utils/useWindowSize"; interface AutomationListParams { @@ -29,12 +31,17 @@ export const AutomationList: FC = ({ // state const [hideList, setHideList] = useState(false); const [current, setCurrent] = useState(0); + const { isMobile } = useWindowSize(); // alias const currentAuto = automations.length > 0 ? automations[current] : null; - const automationListListCls = "automation-list--list" + (hideList ? " hide" : " show") + const automationListListCls = [ + "automation-list--list", + hideList ? "hide" : "show", + isMobile ? 'mobile' : '' + ].join(' ') // render - return
-
+ return
+
{ diff --git a/webapp/src/components/SizeModal.tsx b/webapp/src/components/SizeModal.tsx new file mode 100644 index 0000000..4736a3d --- /dev/null +++ b/webapp/src/components/SizeModal.tsx @@ -0,0 +1,15 @@ +import { FC } from "react"; +import useWindowSize from "utils/useWindowSize"; + + +export const SizeModal: FC = () => { + const size = useWindowSize(); + + return {size.width}/{size.height}={size.ratioWbh} ({size.isMobile ? 'm' : 'd'}) +} \ No newline at end of file diff --git a/webapp/src/utils/useWindowSize.ts b/webapp/src/utils/useWindowSize.ts index 8adabdd..50c0f39 100644 --- a/webapp/src/utils/useWindowSize.ts +++ b/webapp/src/utils/useWindowSize.ts @@ -5,27 +5,24 @@ interface Size { width: number; height: number; ratioWbh: number; + isMobile: boolean; } // Hook -export default function useWindowSize(): Size { +export default function useWindowSize(mobileRatioInd: number = 0.8): Size { + // Initialize state with undefined width/height so server and client renders match // Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/ - const [windowSize, setWindowSize] = useState({ - width: window.innerWidth, - height: window.innerHeight, - ratioWbh: window.innerWidth / window.innerHeight, - }); + const [windowSize, setWindowSize] = useState(makeUpdate(window, mobileRatioInd)); + + // alias + useEffect(() => { // Handler to call on window resize function handleResize() { // Set window width/height to state - setWindowSize({ - width: window.innerWidth, - height: window.innerHeight, - ratioWbh: window.innerWidth / window.innerHeight, - }); + setWindowSize(makeUpdate(window, mobileRatioInd)); } // Add event listener @@ -39,4 +36,11 @@ export default function useWindowSize(): Size { }, []); // Empty array ensures that effect is only run on mount return windowSize; -} \ No newline at end of file +} + +const makeUpdate = (w: Window, mobileRatioInd: number): Size => ({ + width: w.innerWidth, + height: w.innerHeight, + ratioWbh: w.innerWidth / w.innerHeight, + isMobile: w.innerWidth / w.innerHeight <= mobileRatioInd, +}) \ No newline at end of file