From d461af86e820d188fb4b5d51adcdb173ede41042 Mon Sep 17 00:00:00 2001 From: z0ccc Date: Fri, 15 Apr 2022 17:49:49 -0400 Subject: [PATCH] Fixed issues with reloading match ip's --- src/pages/Popup/DebugSettings.js | 39 +++++++++++++++++++++++++------- src/pages/Popup/Popup.jsx | 2 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/pages/Popup/DebugSettings.js b/src/pages/Popup/DebugSettings.js index 82477b2..e9fd662 100644 --- a/src/pages/Popup/DebugSettings.js +++ b/src/pages/Popup/DebugSettings.js @@ -15,27 +15,50 @@ const DebugSettings = ({ type, ip }) => { const [matchIP, setMatchIP] = useState(false) const matchIPStorage = `${type}MatchIP` + // useEffect(() => { + // console.log(value, matchIP) + // }, [value, matchIP]) + useEffect(() => { chrome.storage.sync.get([type, matchIPStorage], (result) => { - setMatchIP(result[matchIPStorage]) + console.log(1, result) - if (result[matchIPStorage] && !result[type]) { + // result[matchIPStorage] && setMatchIP(result[matchIPStorage]) + + if (result[matchIPStorage]) { setValue(ip[type]) chrome.storage.sync.set({ [type]: ip[type] }) - } else { - setValue(result[type]) + // if (!result[type]) { + // console.log(2, result) + + // setValue(ip[type]) + // chrome.storage.sync.set({ [type]: ip[type] }) + // } else { + // console.log(3, result[type]) + // chrome.storage.sync.set({ [type]: ip[type] }) + + // result[type] && setValue(ip[type]) + // } } }) }, [ip, matchIPStorage, type]) const toggleMatchIP = () => { chrome.storage.sync.set({ [matchIPStorage]: !matchIP }) - - if (!matchIP) setValue(ip[type]) - + !matchIP && setValue(ip[type]) setMatchIP(!matchIP) } + const changeTextValue = (e) => { + console.log(e.target.value) + chrome.storage.sync.set({ [type]: e.target.value }) + setValue(e.target.value) + if (matchIP) { + chrome.storage.sync.set({ [matchIPStorage]: !matchIP }) + setMatchIP(!matchIP) + } + } + return (
{ setMatchIP(!matchIP)} + onChange={(e) => changeTextValue(e)} style={{ width: '120px', margin: '0 5px 0 0', diff --git a/src/pages/Popup/Popup.jsx b/src/pages/Popup/Popup.jsx index e553954..89456a3 100644 --- a/src/pages/Popup/Popup.jsx +++ b/src/pages/Popup/Popup.jsx @@ -12,7 +12,7 @@ const getIP = () => }) const Popup = () => { - const [ip, setIP] = useState() + const [ip, setIP] = useState('') useEffect(() => { chrome.storage.sync.get(['ipData'], (result) => {