Fixed issues with reloading match ip's

This commit is contained in:
z0ccc 2022-04-15 17:49:49 -04:00
parent 6e2372b28d
commit 9f7754641e
2 changed files with 32 additions and 9 deletions

View file

@ -15,27 +15,50 @@ const DebugSettings = ({ type, ip }) => {
const [matchIP, setMatchIP] = useState(false) const [matchIP, setMatchIP] = useState(false)
const matchIPStorage = `${type}MatchIP` const matchIPStorage = `${type}MatchIP`
// useEffect(() => {
// console.log(value, matchIP)
// }, [value, matchIP])
useEffect(() => { useEffect(() => {
chrome.storage.sync.get([type, matchIPStorage], (result) => { 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]) setValue(ip[type])
chrome.storage.sync.set({ [type]: ip[type] }) chrome.storage.sync.set({ [type]: ip[type] })
} else { // if (!result[type]) {
setValue(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]) }, [ip, matchIPStorage, type])
const toggleMatchIP = () => { const toggleMatchIP = () => {
chrome.storage.sync.set({ [matchIPStorage]: !matchIP }) chrome.storage.sync.set({ [matchIPStorage]: !matchIP })
!matchIP && setValue(ip[type])
if (!matchIP) setValue(ip[type])
setMatchIP(!matchIP) 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 ( return (
<div <div
style={{ style={{
@ -48,7 +71,7 @@ const DebugSettings = ({ type, ip }) => {
<input <input
type="text" type="text"
value={value} value={value}
// onChange={() => setMatchIP(!matchIP)} onChange={(e) => changeTextValue(e)}
style={{ style={{
width: '120px', width: '120px',
margin: '0 5px 0 0', margin: '0 5px 0 0',

View file

@ -12,7 +12,7 @@ const getIP = () =>
}) })
const Popup = () => { const Popup = () => {
const [ip, setIP] = useState() const [ip, setIP] = useState('')
useEffect(() => { useEffect(() => {
chrome.storage.sync.get(['ipData'], (result) => { chrome.storage.sync.get(['ipData'], (result) => {