From 2dd97ee953beb93fe0dec451a024b95c7d1186fe Mon Sep 17 00:00:00 2001 From: z0ccc Date: Mon, 31 Oct 2022 01:26:50 -0400 Subject: [PATCH] Disable address autofill option --- src/Popup/Components/CheckBox.tsx | 3 ++- .../AutofillPage/handleAutofillAddress.ts | 17 ++++++++++++++ src/Popup/Pages/AutofillPage/index.tsx | 22 +++++++++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/Popup/Pages/AutofillPage/handleAutofillAddress.ts diff --git a/src/Popup/Components/CheckBox.tsx b/src/Popup/Components/CheckBox.tsx index c90f566..522fa61 100644 --- a/src/Popup/Components/CheckBox.tsx +++ b/src/Popup/Components/CheckBox.tsx @@ -1,8 +1,9 @@ +import { ChangeEvent } from 'react' import { Label, Checkbox } from 'theme-ui' interface CheckBoxProps { title: string - onChange?: () => void + onChange?: (e: ChangeEvent) => void checked?: boolean } diff --git a/src/Popup/Pages/AutofillPage/handleAutofillAddress.ts b/src/Popup/Pages/AutofillPage/handleAutofillAddress.ts new file mode 100644 index 0000000..e28a755 --- /dev/null +++ b/src/Popup/Pages/AutofillPage/handleAutofillAddress.ts @@ -0,0 +1,17 @@ +const handleAutofillAddress = (value: boolean) => { + console.log(!value) + chrome.privacy.services.autofillAddressEnabled.clear({}, () => { + chrome.privacy.services.autofillAddressEnabled.set( + { + value: !value, + }, + () => { + chrome.storage.local.set({ + autofillAddress: value, + }) + } + ) + }) +} + +export default handleAutofillAddress diff --git a/src/Popup/Pages/AutofillPage/index.tsx b/src/Popup/Pages/AutofillPage/index.tsx index e912d48..69d63fc 100644 --- a/src/Popup/Pages/AutofillPage/index.tsx +++ b/src/Popup/Pages/AutofillPage/index.tsx @@ -1,5 +1,5 @@ import { Text } from 'theme-ui' -import { useState, useEffect } from 'react' +import { useState, useEffect, ChangeEvent } from 'react' import Page from '../../Components/Page' import CheckBox from '../../Components/CheckBox' // import { autofillData } from '../../../types' @@ -8,6 +8,7 @@ import TableRow from '../../Components/TableRow' import { Button } from 'theme-ui' import addresses from '../../../utils/addresses' import FooterLink from '../../Components/FooterLink' +import handleAutofillAddress from './handleAutofillAddress' interface AutofillPageProps { tab: string @@ -16,6 +17,7 @@ interface AutofillPageProps { } const AutofillPage = ({ tab, autofillData }: AutofillPageProps) => { + const [autofillAddress, setAutofillAddress] = useState(false) const [country, setCountry] = useState('') const [city, setCity] = useState('') const [region, setRegion] = useState('') @@ -24,6 +26,12 @@ const AutofillPage = ({ tab, autofillData }: AutofillPageProps) => { const [phone, setPhone] = useState('9057814565') // const [configuration, setConfiguration] = useState('default') + useEffect(() => { + chrome.storage.local.get(['autofillAddress'], (storage) => { + storage.autofillAddress && setAutofillAddress(storage.autofillAddress) + }) + }, []) + useEffect(() => { // chrome.storage.local.get(['configuration', 'autofillData'], (storage) => { // storage.configuration && setConfiguration(storage.configuration) @@ -103,9 +111,19 @@ const AutofillPage = ({ tab, autofillData }: AutofillPageProps) => { // // } // } + const changeCheckBoxValue = (e: ChangeEvent) => { + console.log(e.target.checked) + handleAutofillAddress(e.target.checked) + setAutofillAddress(e.target.checked) + } + return ( - + {/* */}