From cb3bdf9e9291f815c9a4db17149df0f4b14d4010 Mon Sep 17 00:00:00 2001 From: z0ccc Date: Sun, 8 May 2022 20:42:38 -0400 Subject: [PATCH] Added locale to new profile selection for match ip --- src/pages/Popup/DebugSettings.js | 9 ++-- src/pages/Popup/LocaleSettings.js | 71 ------------------------------- src/pages/Popup/Popup.jsx | 8 +++- 3 files changed, 12 insertions(+), 76 deletions(-) delete mode 100644 src/pages/Popup/LocaleSettings.js 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 ( -
- - -
- ) -} - -export default LocaleSettings diff --git a/src/pages/Popup/Popup.jsx b/src/pages/Popup/Popup.jsx index 44aab15..60bcc9c 100644 --- a/src/pages/Popup/Popup.jsx +++ b/src/pages/Popup/Popup.jsx @@ -106,6 +106,13 @@ const Popup = () => { profile={profile} setProfile={setProfile} /> + { profile={profile} setProfile={setProfile} /> - {/* */}