diff --git a/package-lock.json b/package-lock.json index b30800c..04a03e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "hashfrog_tracker", - "version": "0.7.1", + "version": "0.7.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "hashfrog_tracker", - "version": "0.7.1", + "version": "0.7.2", "dependencies": { "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.3.0", diff --git a/package.json b/package.json index b524a27..e3c5908 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hashfrog_tracker", - "version": "0.7.1", + "version": "0.7.2", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.16.4", diff --git a/src/components/CustomReactSelect.js b/src/components/CustomReactSelect.js index 81041ee..8ee28a8 100644 --- a/src/components/CustomReactSelect.js +++ b/src/components/CustomReactSelect.js @@ -1,6 +1,8 @@ -import { useCallback, useEffect, useMemo, useState } from "react"; +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import Select from "react-select"; +import { useHintEntry } from "../context/trackerContext"; + const CustomReactSelect = props => { const { id = "960b29a364ca444abb5969c97580d973", @@ -15,6 +17,10 @@ const CustomReactSelect = props => { const [inputValue, setInputValue] = useState(""); const [hueRotate, setHueRotate] = useState(0); + const { setHintEntry, savedHintEntry } = useHintEntry(id); + const hintRestoredRef = useRef(false); + const isMountRef = useRef(true); + const customStyles = useMemo(() => { return { control: provided => ({ @@ -101,6 +107,25 @@ const CustomReactSelect = props => { onValueCallback(value); }, [onValueCallback, value]); + // Persist hint changes. Skip the initial mount so an empty input doesn't + // clobber a saved entry before the resume restore below can apply it. + useEffect(() => { + if (isMountRef.current) { + isMountRef.current = false; + return; + } + setHintEntry(value ? value.value : null); + }, [value, setHintEntry]); + + // Restore a saved hint once, after a resumed session populates it. + useEffect(() => { + if (hintRestoredRef.current) { return; } + if (savedHintEntry !== null) { + setValue({ label: savedHintEntry, value: savedHintEntry }); + hintRestoredRef.current = true; + } + }, [savedHintEntry]); + return (