Skip to content

Commit

Permalink
fix escape issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ritch committed Aug 29, 2022
1 parent 6f60985 commit dda2a84
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
3 changes: 0 additions & 3 deletions app/packages/app/src/components/Modal/Looker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ const Looker = ({ lookerRef, onClose, onNext, onPrevious }: LookerProps) => {
if (showJSON === true) {
jsonPanel.open(sample);
}
if (showJSON === false) {
jsonPanel.close();
}
});

onClose && useEventHandler(looker, "close", onClose);
Expand Down
14 changes: 11 additions & 3 deletions app/packages/looker-3d/src/Looker3d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function Polyline({
selected,
onClick,
tooltip,
label
label,
}) {
if (filled) {
// filled not yet supported
Expand Down Expand Up @@ -395,6 +395,15 @@ function Looker3dCore({ sampleOverride: sample }) {
useHotkey(
"Escape",
({ get, set }) => {
if (get(jsonPanel.stateAtom).isOpen) {
set(jsonPanel.stateAtom, (s) => ({ ...s, isOpen: false }));
return false;
}
if (get(helpPanel.stateAtom).isOpen) {
set(helpPanel.stateAtom, (s) => ({ ...s, isOpen: false }));
return false;
}

const selectedLabels = get(fos.selectedLabels);
if (selectedLabels && Object.keys(selectedLabels).length > 0) {
set(fos.selectedLabels, {});
Expand All @@ -404,10 +413,9 @@ function Looker3dCore({ sampleOverride: sample }) {
const changed = onChangeView("top");
if (changed) return;

if (jsonPanel.isOpen) return;
set(fos.modal, null);
},
[jsonPanel.isOpen, selectedLabels, hovering]
[jsonPanel.isOpen, helpPanel.isOpen, selectedLabels, hovering]
);

useEffect(() => {
Expand Down
7 changes: 6 additions & 1 deletion app/packages/state/src/hooks/useClearModal.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { useRecoilTransaction_UNSTABLE } from "recoil";

import * as fos from "../recoil";

import useJSONPanel from "./useJSONPanel";
import useHelpPanel from "./useHelpPanel";
export default () => {
const jsonPanel = useJSONPanel();
const helpPanel = useHelpPanel();
return useRecoilTransaction_UNSTABLE(
({ set, get }) =>
() => {
if (get(jsonPanel.stateAtom).isOpen) return;
if (get(helpPanel.stateAtom).isOpen) return;
const fullscreen = get(fos.fullscreen);
if (fullscreen) {
return;
Expand Down
1 change: 1 addition & 0 deletions app/packages/state/src/hooks/useHelpPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ export default function useHelpPanel() {
},
items,
isOpen,
stateAtom: helpPanelState,
};
}
12 changes: 1 addition & 11 deletions app/packages/state/src/hooks/useJSONPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ export default function useJSONPanel() {
setState((s) => ({ ...s, isOpen: false }));
}

function handleEscape(e) {
if (e.key === "Escape") close();
}

useEffect(() => {
if (isOpen) {
window.addEventListener("keydown", handleEscape);
}
return () => window.removeEventListener("keydown", handleEscape);
}, [isOpen]);

return {
open(sample) {
setState((s) => ({ ...s, sample, isOpen: true }));
Expand All @@ -67,5 +56,6 @@ export default function useJSONPanel() {
sample,
json,
jsonHTML,
stateAtom: jsonPanelState,
};
}

0 comments on commit dda2a84

Please sign in to comment.