diff --git a/src/pages/Popup/DebugSettings.js b/src/pages/Popup/DebugSettings.js index d858c4c..f168c8b 100644 --- a/src/pages/Popup/DebugSettings.js +++ b/src/pages/Popup/DebugSettings.js @@ -1,16 +1,17 @@ import React, { useState, useEffect } from 'react' import profiles from '../../utils/profiles' +import countryLocales from '../../utils/countryLocales' const DebugSettings = ({ type, title, ip, profile, setProfile }) => { const [value, setValue] = useState('') useEffect(() => { if (profile === 'match') { - console.log(1) - if (ip) { - setValue(ip[type]) - chrome.storage.sync.set({ [type]: ip[type] }) + const ipTypeValue = + type === 'locale' ? countryLocales[ip.countryCode].locale : ip[type] + setValue(ipTypeValue) + chrome.storage.sync.set({ [type]: ipTypeValue }) } } else if (profile === 'custom') { console.log(2) diff --git a/src/pages/Popup/LocaleSettings.js b/src/pages/Popup/LocaleSettings.js deleted file mode 100644 index e27cdd9..0000000 --- a/src/pages/Popup/LocaleSettings.js +++ /dev/null @@ -1,71 +0,0 @@ -import React, { useState, useEffect, useRef } from 'react' -import countryLocales from '../../utils/countryLocales' -import detachDebugger from '../../utils/detachDebugger' - -const LocaleSettings = ({ ip }) => { - const [value, setValue] = useState('') - const [matchIP, setMatchIP] = useState(false) - const locale = useRef(null) - - useEffect(() => { - if (ip) { - locale.current = countryLocales[ip.countryCode].locale - - chrome.storage.sync.get(['locale', 'localeMatchIP'], (result) => { - result.localeMatchIP && setMatchIP(result.localeMatchIP) - - if (result.localeMatchIP) { - setValue(locale.current) - chrome.storage.sync.set({ locale: locale.current }) - } else if (result.locale) { - setValue(result.locale) - } - }) - } - }, [ip]) - - const changeTextValue = (e) => { - chrome.storage.sync.set({ locale: e.target.value }) - setValue(e.target.value) - if (matchIP) { - chrome.storage.sync.set({ localeMatchIP: !matchIP }) - setMatchIP(!matchIP) - } - detachDebugger() - } - - const toggleMatchIP = (e) => { - chrome.storage.sync.set({ locale: locale.current, localeMatchIP: !matchIP }) - !matchIP && setValue(locale.current) - setMatchIP(e.target.value) - } - - return ( -