From 3112890fd359c517d5014fc15dac810603e2de16 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Sun, 26 Apr 2020 20:48:01 +1000 Subject: [PATCH] Fixed settings update delay --- src/components/map/MapSettings.js | 26 +++----------------------- src/modals/SelectMapModal.js | 4 ++-- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/src/components/map/MapSettings.js b/src/components/map/MapSettings.js index 2ad0412..8c6b012 100644 --- a/src/components/map/MapSettings.js +++ b/src/components/map/MapSettings.js @@ -1,11 +1,8 @@ -import React, { useEffect, useState } from "react"; +import React from "react"; import { Flex, Box, Label, Input, Checkbox, IconButton } from "theme-ui"; import ExpandMoreIcon from "../../icons/ExpandMoreIcon"; -import useDebounce from "../../helpers/useDebounce"; -import usePrevious from "../../helpers/usePrevious"; - function MapSettings({ map, mapState, @@ -25,23 +22,6 @@ function MapSettings({ } } - // Create a local state for the map name to debounce calls to settings change - // and avoid performance issues with db access - const [localMapName, setLocalMapName] = useState(""); - const prevMap = usePrevious(map); - useEffect(() => { - // Check map changed - if (map && (!prevMap || map.id !== prevMap.id)) { - setLocalMapName(map.name); - } - }, [map]); - const debouncedLocalMapName = useDebounce(localMapName, 100); - useEffect(() => { - if (map) { - onSettingsChange("name", debouncedLocalMapName); - } - }, [debouncedLocalMapName]); - return ( @@ -115,8 +95,8 @@ function MapSettings({ setLocalMapName(e.target.value)} + value={(map && map.name) || ""} + onChange={(e) => onSettingsChange("name", e.target.value)} disabled={map === null || map.type === "default"} my={1} /> diff --git a/src/modals/SelectMapModal.js b/src/modals/SelectMapModal.js index df2aca9..0fe0915 100644 --- a/src/modals/SelectMapModal.js +++ b/src/modals/SelectMapModal.js @@ -244,7 +244,7 @@ function SelectMapModal({ const [showMoreSettings, setShowMoreSettings] = useState(false); async function handleMapSettingsChange(key, value) { - await db.table("maps").update(selectedMap.id, { [key]: value }); + db.table("maps").update(selectedMap.id, { [key]: value }); const newMap = { ...selectedMap, [key]: value }; setMaps((prevMaps) => { const newMaps = [...prevMaps]; @@ -258,7 +258,7 @@ function SelectMapModal({ } async function handleMapStateSettingsChange(key, value) { - await db.table("states").update(selectedMap.id, { [key]: value }); + db.table("states").update(selectedMap.id, { [key]: value }); setSelectedMapState((prevState) => ({ ...prevState, [key]: value })); }