Added shared grid context and moved away from calling useContext directly

This commit is contained in:
Mitchell McCaffrey
2021-02-06 13:32:38 +11:00
parent 8991be923e
commit f20173de35
60 changed files with 672 additions and 460 deletions
-30
View File
@@ -1,30 +0,0 @@
import { useEffect, useContext } from "react";
import KeyboardContext from "../contexts/KeyboardContext";
/**
* @param {KeyboardEvent} onKeyDown
* @param {KeyboardEvent} onKeyUp
*/
function useKeyboard(onKeyDown, onKeyUp) {
const { keyEmitter } = useContext(KeyboardContext);
useEffect(() => {
if (onKeyDown) {
keyEmitter.on("keyDown", onKeyDown);
}
if (onKeyUp) {
keyEmitter.on("keyUp", onKeyUp);
}
return () => {
if (onKeyDown) {
keyEmitter.off("keyDown", onKeyDown);
}
if (onKeyUp) {
keyEmitter.off("keyUp", onKeyUp);
}
};
});
}
export default useKeyboard;
+2 -4
View File
@@ -1,16 +1,14 @@
import { useContext } from "react";
import get from "lodash.get";
import set from "lodash.set";
import SettingsContext from "../contexts/SettingsContext";
import { useSettings } from "../contexts/SettingsContext";
/**
* Helper to get and set nested settings that are saved in local storage
* @param {String} path The path to the setting within the Settings object provided by the SettingsContext
*/
function useSetting(path) {
const { settings, setSettings } = useContext(SettingsContext);
const { settings, setSettings } = useSettings();
const setting = get(settings, path);