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,4 +1,4 @@
import React, { useRef, useState, useContext, useEffect } from "react";
import React, { useRef, useState, useEffect } from "react";
import { Button, Flex, Label } from "theme-ui";
import shortid from "shortid";
import Case from "case";
@@ -17,16 +17,16 @@ import { resizeImage } from "../helpers/image";
import { useSearch, useGroup, handleItemSelect } from "../helpers/select";
import {
getGridDefaultInset,
getGridSize,
getGridSizeFromImage,
gridSizeVaild,
} from "../helpers/grid";
import Vector2 from "../helpers/Vector2";
import useKeyboard from "../hooks/useKeyboard";
import useResponsiveLayout from "../hooks/useResponsiveLayout";
import MapDataContext from "../contexts/MapDataContext";
import AuthContext from "../contexts/AuthContext";
import { useMapData } from "../contexts/MapDataContext";
import { useAuth } from "../contexts/AuthContext";
import { useKeyboard } from "../contexts/KeyboardContext";
const defaultMapProps = {
showGrid: false,
@@ -54,7 +54,7 @@ function SelectMapModal({
// The map currently being view in the map screen
currentMap,
}) {
const { userId } = useContext(AuthContext);
const { userId } = useAuth();
const {
ownedMaps,
mapStates,
@@ -64,7 +64,7 @@ function SelectMapModal({
updateMap,
updateMaps,
mapsLoading,
} = useContext(MapDataContext);
} = useMapData();
/**
* Search
@@ -152,7 +152,7 @@ function SelectMapModal({
}
if (!gridSize) {
gridSize = await getGridSize(image);
gridSize = await getGridSizeFromImage(image);
}
// Remove file extension
@@ -207,10 +207,9 @@ function SelectMapModal({
grid: {
size: gridSize,
inset: getGridDefaultInset(
{ size: { x: gridSize.x, y: gridSize.y }, type: "square" },
image.width,
image.height,
gridSize.x,
gridSize.y
image.height
),
type: "square",
},