From 35e2b2ece185b68d43ee5057f14be5061d25168f Mon Sep 17 00:00:00 2001 From: z0ccc Date: Tue, 12 Jul 2022 23:25:51 -0400 Subject: [PATCH] Added tab navigation --- src/pages/Popup/ConfigurationSelect.tsx | 1 - src/pages/Popup/HomePage.tsx | 68 +++++++++++++++++++++++ src/pages/Popup/LocationPage.tsx | 1 - src/pages/Popup/Page.tsx | 27 +++++++++ src/pages/Popup/Popup.tsx | 30 ++++------ src/pages/Popup/{Icon.tsx => TabItem.tsx} | 12 ++-- src/pages/Popup/UserAgentPage.tsx | 66 ++++++++++++++++++++++ src/theme.ts | 2 +- 8 files changed, 181 insertions(+), 26 deletions(-) create mode 100644 src/pages/Popup/HomePage.tsx create mode 100644 src/pages/Popup/Page.tsx rename src/pages/Popup/{Icon.tsx => TabItem.tsx} (64%) create mode 100644 src/pages/Popup/UserAgentPage.tsx diff --git a/src/pages/Popup/ConfigurationSelect.tsx b/src/pages/Popup/ConfigurationSelect.tsx index 1f18395..fac9aec 100644 --- a/src/pages/Popup/ConfigurationSelect.tsx +++ b/src/pages/Popup/ConfigurationSelect.tsx @@ -14,7 +14,6 @@ const ConfigurationSelect = ({ }: ConfigurationSelectProps) => { const changeConfiguration = (e: any) => { detachDebugger() - console.log(e.target.value) chrome.storage.sync.set({ configuration: e.target.value, }) diff --git a/src/pages/Popup/HomePage.tsx b/src/pages/Popup/HomePage.tsx new file mode 100644 index 0000000..2a27180 --- /dev/null +++ b/src/pages/Popup/HomePage.tsx @@ -0,0 +1,68 @@ +import React, { useState, useEffect } from 'react' +import { Box } from 'theme-ui' +import DataInput from './DataInput' +import ConfigurationSelect from './ConfigurationSelect' +import IPData from './IPData' +import getIP from '../../utils/getIP' + +const LocationPage = () => { + 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 ( + + Location + + {configuration === 'match' && } + + + + + + ) +} + +export default LocationPage diff --git a/src/pages/Popup/LocationPage.tsx b/src/pages/Popup/LocationPage.tsx index 03ed617..2a27180 100644 --- a/src/pages/Popup/LocationPage.tsx +++ b/src/pages/Popup/LocationPage.tsx @@ -11,7 +11,6 @@ const LocationPage = () => { useEffect(() => { chrome.storage.sync.get(['configuration', 'ipData'], (result) => { - console.log(result.configuration) result.configuration && setConfiguration(result.configuration) if (result.ipData) { setIP(result.ipData) diff --git a/src/pages/Popup/Page.tsx b/src/pages/Popup/Page.tsx new file mode 100644 index 0000000..b42a127 --- /dev/null +++ b/src/pages/Popup/Page.tsx @@ -0,0 +1,27 @@ +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 715dee3..32cc49d 100644 --- a/src/pages/Popup/Popup.tsx +++ b/src/pages/Popup/Popup.tsx @@ -2,20 +2,14 @@ import React, { useState, useEffect } from 'react' import { ThemeProvider, Flex } from 'theme-ui' import { theme } from '../../theme' import { Home, MapPin, Globe, Users, List } from 'react-feather' -import Icon from './Icon' -import LocationPage from './LocationPage' -// import Navbar from './Navbar' -// import IPData from './IPData' -// import ProfileSelect from './ProfileSelect' -// import DebugSettings from './DebugSettings' -// import UserAgentSettings from './UserAgentSettings' +import TabItem from './TabItem' +import Page from './Page' const Popup = () => { - // const [ip, setIP] = useState(null) - // const [profile, setProfile] = useState('default') - - // useEffect(() => {}, []) - + const [tab, setTab] = useState(0) + useEffect(() => { + console.log(tab) + }, [tab]) return ( { flexDirection: 'column', }} > - } /> - } /> - } /> - } /> - } /> + setTab(0)} /> + setTab(1)} /> + setTab(2)} /> + setTab(3)} /> + setTab(4)} /> - + ) diff --git a/src/pages/Popup/Icon.tsx b/src/pages/Popup/TabItem.tsx similarity index 64% rename from src/pages/Popup/Icon.tsx rename to src/pages/Popup/TabItem.tsx index d56af58..ff54809 100644 --- a/src/pages/Popup/Icon.tsx +++ b/src/pages/Popup/TabItem.tsx @@ -1,10 +1,11 @@ -import React, { useState, useEffect } from 'react' +import React from 'react' interface IconProps { - icon: React.ReactNode + Icon: React.ElementType + onClick: () => void } -const Icon = ({ icon }: IconProps) => { +const TabItem = ({ Icon, onClick }: IconProps) => { return (
{ backgroundColor: 'primaryDark', }, }} + onClick={onClick} > - {icon} +
) } -export default Icon +export default TabItem diff --git a/src/pages/Popup/UserAgentPage.tsx b/src/pages/Popup/UserAgentPage.tsx new file mode 100644 index 0000000..1be3575 --- /dev/null +++ b/src/pages/Popup/UserAgentPage.tsx @@ -0,0 +1,66 @@ +import React, { useState, useEffect } from 'react' +import { Box } from 'theme-ui' +import DataInput from './DataInput' +import ConfigurationSelect from './ConfigurationSelect' +import getIP from '../../utils/getIP' + +const LocationPage = () => { + 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 ( + + User Agent + + + + + + + ) +} + +export default LocationPage diff --git a/src/theme.ts b/src/theme.ts index c62c259..8b0d8fb 100644 --- a/src/theme.ts +++ b/src/theme.ts @@ -11,7 +11,7 @@ export const theme: Theme = { root: { backgroundColor: 'body', color: 'text', - fontSize: '16px', + fontSize: '18px', lineHeight: '22px', margin: '0', fontFamily: "'Segoe UI', Tahoma, sans-serif",