import React, { memo, useEffect, useState } from 'react' import { InfoBlock } from '../info-block' import { GrUser } from 'react-icons/gr' import { useWebsiteContext } from '@app/components/providers/website' export const UserAgentBoxWrapper = ({ ua: agent, url, }: { url: string ua?: string }) => { const [ua, setUa] = useState(agent || '') const { updateWebsite } = useWebsiteContext() const onChangeUA = (e: React.ChangeEvent) => setUa(e?.target?.value) useEffect(() => { if (ua === agent) { return } const debounce = setTimeout(async () => { if (agent !== ua) { try { await updateWebsite({ variables: { url, ua }, }) } catch (e) { console.error(e) } } }, 2300) return () => clearTimeout(debounce) }, [ua, agent, url, updateWebsite]) const uaLabel = `${url}-ua-id` return ( }> ) } export const UserAgentBox = memo(UserAgentBoxWrapper)