import { useEffect } from "react";

import useToggle from "../useToggle";

/**
 * A small hook for checking if the app is currently being interacted with
 * by a keyboard.
 *
 * @return true if the app is in keyboard mode
 * @private
 */
export default function useKeyboardDetection(): boolean {
  const [enabled, enable, disable] = useToggle(false);

  useEffect(() => {
    if (enabled) {
      return;
    }

    window.addEventListener("keydown", enable, true);

    return () => {
      window.removeEventListener("keydown", enable, true);
    };
  }, [enabled, enable]);

  useEffect(() => {
    if (!enabled) {
      return;
    }

    window.addEventListener("wheel", disable, true);
    window.addEventListener("mousedown", disable, true);
    window.addEventListener("touchstart", disable, true);

    return () => {
      window.removeEventListener("wheel", disable, true);
      window.removeEventListener("mousedown", disable, true);
      window.removeEventListener("touchstart", disable, true);
    };
  }, [enabled, disable]);

  return enabled;
}

import { useEffect } from "react";

import useToggle from "../useToggle";

/**
 * A small hook for checking if the app is currently being interacted with
 * by a keyboard.
 *
 * @return true if the app is in keyboard mode
 * @private
 */
export default function useKeyboardDetection(): boolean {
  const [enabled, enable, disable] = useToggle(false);

  useEffect(() => {
    if (enabled) {
      return;
    }

    window.addEventListener("keydown", enable, true);

    return () => {
      window.removeEventListener("keydown", enable, true);
    };
  }, [enabled, enable]);

  useEffect(() => {
    if (!enabled) {
      return;
    }

    window.addEventListener("mousedown", disable, true);
    window.addEventListener("touchstart", disable, true);

    return () => {
      window.removeEventListener("mousedown", disable, true);
      window.removeEventListener("touchstart", disable, true);
    };
  }, [enabled, disable]);

  return enabled;
}

Revert "Fixed interaction mode for shift+mousewheel"
Revert "Fixed interaction mode for shift+mousewheel"

This reverts commit a57ce970ce26de7474c987a2d2482d3bc01e406e.

This doesn't seem like good behavior after playing with it a bit more.
It would work much better if the shift key was being pressed while the
wheel event was triggered instead, but I don't think it's worth the
extra event listeners/work right now to implement.
