From a80d6007904a09bc8dcb9a7a94ad60a3f907c5f8 Mon Sep 17 00:00:00 2001 From: z0ccc Date: Fri, 22 Jul 2022 00:49:11 -0400 Subject: [PATCH] New tab navigation setup --- src/pages/Popup/LocationPage.tsx | 3 +- src/pages/Popup/Page.tsx | 27 ------------ src/pages/Popup/Popup.tsx | 16 ++++--- src/pages/Popup/UserAgentPage.tsx | 5 ++- src/pages/Popup/WhitelistPage.tsx | 69 +++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 36 deletions(-) delete mode 100644 src/pages/Popup/Page.tsx create mode 100644 src/pages/Popup/WhitelistPage.tsx diff --git a/src/pages/Popup/LocationPage.tsx b/src/pages/Popup/LocationPage.tsx index 1f048a4..2af0781 100644 --- a/src/pages/Popup/LocationPage.tsx +++ b/src/pages/Popup/LocationPage.tsx @@ -5,7 +5,7 @@ import ConfigurationSelect from './ConfigurationSelect' import IPData from './IPData' import getIP from '../../utils/getIP' -const LocationPage = () => { +const LocationPage = ({ tab }: any) => { const [ip, setIP] = useState(null) const [configuration, setConfiguration] = useState('default') @@ -25,6 +25,7 @@ const LocationPage = () => { sx={{ m: '12px', width: '100%', + display: tab === 'location' ? 'block' : 'none', }} > Location diff --git a/src/pages/Popup/Page.tsx b/src/pages/Popup/Page.tsx deleted file mode 100644 index b42a127..0000000 --- a/src/pages/Popup/Page.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import React from 'react' -import HomePage from './HomePage' -import LocationPage from './LocationPage' -import UserAgentPage from './UserAgentPage' - -interface PageProps { - tab: number -} - -const Page = ({ tab }: PageProps) => { - switch (tab) { - case 0: - return - case 1: - return - case 2: - return - case 3: - return - case 4: - return - default: - return - } -} - -export default Page diff --git a/src/pages/Popup/Popup.tsx b/src/pages/Popup/Popup.tsx index d6e31b3..f2d954e 100644 --- a/src/pages/Popup/Popup.tsx +++ b/src/pages/Popup/Popup.tsx @@ -3,10 +3,12 @@ import { ThemeProvider, Flex } from 'theme-ui' import { theme } from '../../theme' import { Home, MapPin, Globe, Command, List, ExternalLink } from 'react-feather' import TabItem from './TabItem' -import Page from './Page' +import LocationPage from './LocationPage' +import UserAgentPage from './UserAgentPage' +import WhitelistPage from './WhitelistPage' const Popup = () => { - const [tab, setTab] = useState(1) + const [tab, setTab] = useState('location') return ( @@ -25,16 +27,18 @@ const Popup = () => { }} > {/* setTab(0)} /> */} - setTab(1)} /> - setTab(2)} /> + setTab('location')} /> + setTab('useragent')} /> {/* setTab(3)} /> */} - setTab(3)} /> + setTab('whitelist')} /> window.open('https://vytal.io')} /> - + + + ) diff --git a/src/pages/Popup/UserAgentPage.tsx b/src/pages/Popup/UserAgentPage.tsx index 554484c..146a89a 100644 --- a/src/pages/Popup/UserAgentPage.tsx +++ b/src/pages/Popup/UserAgentPage.tsx @@ -3,7 +3,7 @@ import { Box, Label, Radio, Flex, Input, Select } from 'theme-ui' import userAgents from '../../utils/userAgents' import detachDebugger from '../../utils/detachDebugger' -const LocationPage = () => { +const UserAgentPage = ({ tab }: any) => { const [type, setType] = useState('None') const [operatingSystem, setOperatingSystem] = useState('Windows') const [browser, setBrowser] = useState('Chrome') @@ -62,6 +62,7 @@ const LocationPage = () => { sx={{ m: '12px', width: '100%', + display: tab === 'useragent' ? 'block' : 'none', }} > User Agent @@ -141,4 +142,4 @@ const LocationPage = () => { ) } -export default LocationPage +export default UserAgentPage diff --git a/src/pages/Popup/WhitelistPage.tsx b/src/pages/Popup/WhitelistPage.tsx new file mode 100644 index 0000000..08bc692 --- /dev/null +++ b/src/pages/Popup/WhitelistPage.tsx @@ -0,0 +1,69 @@ +import React, { useState, useEffect } from 'react' +import { Box } from 'theme-ui' +import LocationInput from './LocationInput' +import ConfigurationSelect from './ConfigurationSelect' +import IPData from './IPData' +import getIP from '../../utils/getIP' + +const WhitelistPage = ({ tab }: any) => { + const [ip, setIP] = useState(null) + const [configuration, setConfiguration] = useState('default') + + useEffect(() => { + chrome.storage.sync.get(['configuration', 'ipData'], (result) => { + result.configuration && setConfiguration(result.configuration) + if (result.ipData) { + setIP(result.ipData) + } else { + Promise.resolve(getIP()).then((ipData) => setIP(ipData)) + } + }) + }, []) + + return ( + + Whitelist + + {configuration === 'match' && } + + + + + + ) +} + +export default WhitelistPage