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

View File

@@ -1,9 +1,10 @@
import React, { useContext, useEffect, useState, useRef } from "react";
import React, { useEffect, useState, useRef } from "react";
import { Rect, Text } from "react-konva";
import { useSpring, animated } from "react-spring/konva";
import AuthContext from "../../contexts/AuthContext";
import MapInteractionContext from "../../contexts/MapInteractionContext";
import { useAuth } from "../../contexts/AuthContext";
import { useMapInteraction } from "../../contexts/MapInteractionContext";
import { useGrid } from "../../contexts/GridContext";
import { snapNodeToGrid } from "../../helpers/grid";
import colors from "../../helpers/colors";
@@ -22,12 +23,11 @@ function Note({
onNoteDragEnd,
fadeOnHover,
}) {
const { userId } = useContext(AuthContext);
const { mapWidth, mapHeight, setPreventMapInteraction } = useContext(
MapInteractionContext
);
const { userId } = useAuth();
const { mapWidth, mapHeight, setPreventMapInteraction } = useMapInteraction();
const { gridCellPixelSize } = useGrid();
const noteWidth = map && (mapWidth / map.grid.size.x) * note.size;
const noteWidth = gridCellPixelSize.width * note.size;
const noteHeight = noteWidth;
const notePadding = noteWidth / 10;

View File

@@ -1,4 +1,4 @@
import React, { useEffect, useState, useContext } from "react";
import React, { useEffect, useState } from "react";
import { Box, Flex, Text, IconButton, Textarea } from "theme-ui";
import Slider from "../Slider";
@@ -16,7 +16,7 @@ import HideIcon from "../../icons/TokenHideIcon";
import NoteIcon from "../../icons/NoteToolIcon";
import TextIcon from "../../icons/NoteTextIcon";
import AuthContext from "../../contexts/AuthContext";
import { useAuth } from "../../contexts/AuthContext";
const defaultNoteMaxSize = 6;
@@ -28,7 +28,7 @@ function NoteMenu({
onNoteChange,
map,
}) {
const { userId } = useContext(AuthContext);
const { userId } = useAuth();
const wasOpen = usePrevious(isOpen);