User agent tab setup
This commit is contained in:
parent
35e2b2ece1
commit
e1f1e92fef
9 changed files with 140 additions and 63 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import { Box } from 'theme-ui'
|
import { Box } from 'theme-ui'
|
||||||
import DataInput from './DataInput'
|
import LocationInput from './LocationInput'
|
||||||
import ConfigurationSelect from './ConfigurationSelect'
|
import ConfigurationSelect from './ConfigurationSelect'
|
||||||
import IPData from './IPData'
|
import IPData from './IPData'
|
||||||
import getIP from '../../utils/getIP'
|
import getIP from '../../utils/getIP'
|
||||||
|
|
@ -33,28 +33,28 @@ const LocationPage = () => {
|
||||||
setConfiguration={setConfiguration}
|
setConfiguration={setConfiguration}
|
||||||
/>
|
/>
|
||||||
{configuration === 'match' && <IPData ip={ip} setIP={setIP} />}
|
{configuration === 'match' && <IPData ip={ip} setIP={setIP} />}
|
||||||
<DataInput
|
<LocationInput
|
||||||
type="timezone"
|
type="timezone"
|
||||||
title="Timezone"
|
title="Timezone"
|
||||||
ip={ip}
|
ip={ip}
|
||||||
configuration={configuration}
|
configuration={configuration}
|
||||||
setConfiguration={setConfiguration}
|
setConfiguration={setConfiguration}
|
||||||
/>
|
/>
|
||||||
<DataInput
|
<LocationInput
|
||||||
type="locale"
|
type="locale"
|
||||||
title="Locale"
|
title="Locale"
|
||||||
ip={ip}
|
ip={ip}
|
||||||
configuration={configuration}
|
configuration={configuration}
|
||||||
setConfiguration={setConfiguration}
|
setConfiguration={setConfiguration}
|
||||||
/>
|
/>
|
||||||
<DataInput
|
<LocationInput
|
||||||
type="lat"
|
type="lat"
|
||||||
title="Latitude"
|
title="Latitude"
|
||||||
ip={ip}
|
ip={ip}
|
||||||
configuration={configuration}
|
configuration={configuration}
|
||||||
setConfiguration={setConfiguration}
|
setConfiguration={setConfiguration}
|
||||||
/>
|
/>
|
||||||
<DataInput
|
<LocationInput
|
||||||
type="lon"
|
type="lon"
|
||||||
title="Longitude"
|
title="Longitude"
|
||||||
ip={ip}
|
ip={ip}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import countryLocales from '../../utils/countryLocales'
|
||||||
import detachDebugger from '../../utils/detachDebugger'
|
import detachDebugger from '../../utils/detachDebugger'
|
||||||
import { Label, Input } from 'theme-ui'
|
import { Label, Input } from 'theme-ui'
|
||||||
|
|
||||||
interface DataInputProps {
|
interface LocationInputProps {
|
||||||
type: string
|
type: string
|
||||||
title: string
|
title: string
|
||||||
ip: any
|
ip: any
|
||||||
|
|
@ -12,13 +12,13 @@ interface DataInputProps {
|
||||||
setConfiguration: Dispatch<SetStateAction<string>>
|
setConfiguration: Dispatch<SetStateAction<string>>
|
||||||
}
|
}
|
||||||
|
|
||||||
const DataInput = ({
|
const LocationInput = ({
|
||||||
type,
|
type,
|
||||||
title,
|
title,
|
||||||
ip,
|
ip,
|
||||||
configuration,
|
configuration,
|
||||||
setConfiguration,
|
setConfiguration,
|
||||||
}: DataInputProps) => {
|
}: LocationInputProps) => {
|
||||||
const [value, setValue] = useState('')
|
const [value, setValue] = useState('')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -58,4 +58,4 @@ const DataInput = ({
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DataInput
|
export default LocationInput
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import { Box } from 'theme-ui'
|
import { Box } from 'theme-ui'
|
||||||
import DataInput from './DataInput'
|
import LocationInput from './LocationInput'
|
||||||
import ConfigurationSelect from './ConfigurationSelect'
|
import ConfigurationSelect from './ConfigurationSelect'
|
||||||
import IPData from './IPData'
|
import IPData from './IPData'
|
||||||
import getIP from '../../utils/getIP'
|
import getIP from '../../utils/getIP'
|
||||||
|
|
@ -33,28 +33,28 @@ const LocationPage = () => {
|
||||||
setConfiguration={setConfiguration}
|
setConfiguration={setConfiguration}
|
||||||
/>
|
/>
|
||||||
{configuration === 'match' && <IPData ip={ip} setIP={setIP} />}
|
{configuration === 'match' && <IPData ip={ip} setIP={setIP} />}
|
||||||
<DataInput
|
<LocationInput
|
||||||
type="timezone"
|
type="timezone"
|
||||||
title="Timezone"
|
title="Timezone"
|
||||||
ip={ip}
|
ip={ip}
|
||||||
configuration={configuration}
|
configuration={configuration}
|
||||||
setConfiguration={setConfiguration}
|
setConfiguration={setConfiguration}
|
||||||
/>
|
/>
|
||||||
<DataInput
|
<LocationInput
|
||||||
type="locale"
|
type="locale"
|
||||||
title="Locale"
|
title="Locale"
|
||||||
ip={ip}
|
ip={ip}
|
||||||
configuration={configuration}
|
configuration={configuration}
|
||||||
setConfiguration={setConfiguration}
|
setConfiguration={setConfiguration}
|
||||||
/>
|
/>
|
||||||
<DataInput
|
<LocationInput
|
||||||
type="lat"
|
type="lat"
|
||||||
title="Latitude"
|
title="Latitude"
|
||||||
ip={ip}
|
ip={ip}
|
||||||
configuration={configuration}
|
configuration={configuration}
|
||||||
setConfiguration={setConfiguration}
|
setConfiguration={setConfiguration}
|
||||||
/>
|
/>
|
||||||
<DataInput
|
<LocationInput
|
||||||
type="lon"
|
type="lon"
|
||||||
title="Longitude"
|
title="Longitude"
|
||||||
ip={ip}
|
ip={ip}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'
|
||||||
import Navbar from './Navbar'
|
import Navbar from './Navbar'
|
||||||
import IPData from './IPData'
|
import IPData from './IPData'
|
||||||
import ProfileSelect from './ConfigurationSelect'
|
import ProfileSelect from './ConfigurationSelect'
|
||||||
import DebugSettings from './DataInput'
|
import DebugSettings from './LocationInput'
|
||||||
import UserAgentSettings from './UserAgentSettings'
|
import UserAgentSettings from './UserAgentSettings'
|
||||||
|
|
||||||
const getIP = () =>
|
const getIP = () =>
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,19 @@
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { ThemeProvider, Flex } from 'theme-ui'
|
import { ThemeProvider, Flex } from 'theme-ui'
|
||||||
import { theme } from '../../theme'
|
import { theme } from '../../theme'
|
||||||
import { Home, MapPin, Globe, Users, List } from 'react-feather'
|
import { Home, MapPin, Globe, Command, List } from 'react-feather'
|
||||||
import TabItem from './TabItem'
|
import TabItem from './TabItem'
|
||||||
import Page from './Page'
|
import Page from './Page'
|
||||||
|
|
||||||
const Popup = () => {
|
const Popup = () => {
|
||||||
const [tab, setTab] = useState(0)
|
const [tab, setTab] = useState(2)
|
||||||
useEffect(() => {
|
|
||||||
console.log(tab)
|
|
||||||
}, [tab])
|
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={theme}>
|
<ThemeProvider theme={theme}>
|
||||||
<Flex
|
<Flex
|
||||||
sx={{
|
sx={{
|
||||||
width: '350px',
|
width: '350px',
|
||||||
height: '365px',
|
height: '368px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Flex
|
<Flex
|
||||||
|
|
@ -29,8 +27,8 @@ const Popup = () => {
|
||||||
<TabItem Icon={Home} onClick={() => setTab(0)} />
|
<TabItem Icon={Home} onClick={() => setTab(0)} />
|
||||||
<TabItem Icon={MapPin} onClick={() => setTab(1)} />
|
<TabItem Icon={MapPin} onClick={() => setTab(1)} />
|
||||||
<TabItem Icon={Globe} onClick={() => setTab(2)} />
|
<TabItem Icon={Globe} onClick={() => setTab(2)} />
|
||||||
<TabItem Icon={List} onClick={() => setTab(3)} />
|
<TabItem Icon={Command} onClick={() => setTab(3)} />
|
||||||
<TabItem Icon={Users} onClick={() => setTab(4)} />
|
<TabItem Icon={List} onClick={() => setTab(4)} />
|
||||||
</Flex>
|
</Flex>
|
||||||
<Page tab={tab} />
|
<Page tab={tab} />
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,34 @@
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import { Box } from 'theme-ui'
|
import { Box, Label, Radio, Flex, Input } from 'theme-ui'
|
||||||
import DataInput from './DataInput'
|
import userAgents from '../../utils/userAgents'
|
||||||
import ConfigurationSelect from './ConfigurationSelect'
|
import detachDebugger from '../../utils/detachDebugger'
|
||||||
import getIP from '../../utils/getIP'
|
|
||||||
|
|
||||||
const LocationPage = () => {
|
const LocationPage = () => {
|
||||||
const [ip, setIP] = useState(null)
|
const [type, setType] = useState('desktop')
|
||||||
const [configuration, setConfiguration] = useState('default')
|
const [userAgent, setUserAgent] = useState('')
|
||||||
|
// const [configuration, setConfiguration] = useState('default')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
chrome.storage.sync.get(['configuration', 'ipData'], (result) => {
|
chrome.storage.sync.get(['type', 'userAgent'], (result) => {
|
||||||
result.configuration && setConfiguration(result.configuration)
|
result.type && setType(result.type)
|
||||||
if (result.ipData) {
|
result.userAgent && setUserAgent(result.userAgent)
|
||||||
setIP(result.ipData)
|
|
||||||
} else {
|
|
||||||
Promise.resolve(getIP()).then((ipData) => setIP(ipData))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
const changeType = (e: any) => {
|
||||||
|
detachDebugger()
|
||||||
|
chrome.storage.sync.set({ type: e.target.value })
|
||||||
|
setType(e.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const changeUserAgent = (e: any) => {
|
||||||
|
detachDebugger()
|
||||||
|
chrome.storage.sync.set({ userAgent: e.target.value })
|
||||||
|
chrome.storage.sync.set({ type: 'custom' })
|
||||||
|
setUserAgent(e.target.value)
|
||||||
|
setType('custom')
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
|
|
@ -27,38 +37,54 @@ const LocationPage = () => {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box sx={{ fontSize: '20px', mb: '8px' }}>User Agent</Box>
|
<Box sx={{ fontSize: '20px', mb: '8px' }}>User Agent</Box>
|
||||||
<ConfigurationSelect
|
<Flex mt={'12px'} mb={'8px'}>
|
||||||
|
<Label>
|
||||||
|
<Radio
|
||||||
|
name="type"
|
||||||
|
value="desktop"
|
||||||
|
onChange={changeType}
|
||||||
|
checked={type === 'desktop'}
|
||||||
|
/>{' '}
|
||||||
|
Desktop
|
||||||
|
</Label>
|
||||||
|
<Label>
|
||||||
|
<Radio
|
||||||
|
name="type"
|
||||||
|
value="mobile"
|
||||||
|
onChange={changeType}
|
||||||
|
checked={type === 'mobile'}
|
||||||
|
/>{' '}
|
||||||
|
Mobile
|
||||||
|
</Label>
|
||||||
|
<Label>
|
||||||
|
<Radio
|
||||||
|
name="type"
|
||||||
|
value="custom"
|
||||||
|
onChange={changeType}
|
||||||
|
checked={type === 'custom'}
|
||||||
|
/>{' '}
|
||||||
|
Custom
|
||||||
|
</Label>
|
||||||
|
</Flex>
|
||||||
|
{/* <UserAgentSelect
|
||||||
|
title="Operating System"
|
||||||
configuration={configuration}
|
configuration={configuration}
|
||||||
setConfiguration={setConfiguration}
|
setConfiguration={setConfiguration}
|
||||||
/>
|
/>
|
||||||
<DataInput
|
<UserAgentSelect
|
||||||
type="timezone"
|
title="Browser"
|
||||||
title="Timezone"
|
configuration={configuration}
|
||||||
|
setConfiguration={setConfiguration}
|
||||||
|
/> */}
|
||||||
|
{/* <LocationInput
|
||||||
|
type="userAgent"
|
||||||
|
title="User Agent"
|
||||||
ip={ip}
|
ip={ip}
|
||||||
configuration={configuration}
|
configuration={configuration}
|
||||||
setConfiguration={setConfiguration}
|
setConfiguration={setConfiguration}
|
||||||
/>
|
/> */}
|
||||||
<DataInput
|
<Label htmlFor="userAgent">User Agent</Label>
|
||||||
type="locale"
|
<Input name="userAgent" value={userAgent} onChange={changeUserAgent} />
|
||||||
title="Locale"
|
|
||||||
ip={ip}
|
|
||||||
configuration={configuration}
|
|
||||||
setConfiguration={setConfiguration}
|
|
||||||
/>
|
|
||||||
<DataInput
|
|
||||||
type="lat"
|
|
||||||
title="Latitude"
|
|
||||||
ip={ip}
|
|
||||||
configuration={configuration}
|
|
||||||
setConfiguration={setConfiguration}
|
|
||||||
/>
|
|
||||||
<DataInput
|
|
||||||
type="lon"
|
|
||||||
title="Longitude"
|
|
||||||
ip={ip}
|
|
||||||
configuration={configuration}
|
|
||||||
setConfiguration={setConfiguration}
|
|
||||||
/>
|
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
50
src/pages/Popup/UserAgentSelect.tsx
Normal file
50
src/pages/Popup/UserAgentSelect.tsx
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
import React, { Dispatch, SetStateAction } from 'react'
|
||||||
|
import { Label, Select } from 'theme-ui'
|
||||||
|
import configurations from '../../utils/configurations'
|
||||||
|
import detachDebugger from '../../utils/detachDebugger'
|
||||||
|
|
||||||
|
interface ConfigurationSelectProps {
|
||||||
|
title: string
|
||||||
|
configuration: string
|
||||||
|
setConfiguration: Dispatch<SetStateAction<string>>
|
||||||
|
}
|
||||||
|
|
||||||
|
const ConfigurationSelect = ({
|
||||||
|
title,
|
||||||
|
configuration,
|
||||||
|
setConfiguration,
|
||||||
|
}: ConfigurationSelectProps) => {
|
||||||
|
const changeConfiguration = (e: any) => {
|
||||||
|
detachDebugger()
|
||||||
|
chrome.storage.sync.set({
|
||||||
|
configuration: e.target.value,
|
||||||
|
})
|
||||||
|
setConfiguration(e.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Label htmlFor="configuration">{title}</Label>
|
||||||
|
<Select
|
||||||
|
name="configuration"
|
||||||
|
id="configuration"
|
||||||
|
value={configuration}
|
||||||
|
onChange={changeConfiguration}
|
||||||
|
mb={'8px'}
|
||||||
|
>
|
||||||
|
<option value="none">None</option>
|
||||||
|
<option value="match">Match IP</option>
|
||||||
|
<option value="custom">Custom</option>
|
||||||
|
<optgroup label="Locations">
|
||||||
|
{Object.keys(configurations).map((key) => (
|
||||||
|
<option value={key} key={key}>
|
||||||
|
{configurations[key].name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</optgroup>
|
||||||
|
</Select>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ConfigurationSelect
|
||||||
|
|
@ -36,6 +36,9 @@ export const theme: Theme = {
|
||||||
outline: 'none',
|
outline: 'none',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// radio: {
|
||||||
|
// userSelect: 'none',
|
||||||
|
// },
|
||||||
},
|
},
|
||||||
buttons: {
|
buttons: {
|
||||||
primary: {
|
primary: {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue