import { useState } from "react"; import ReactGA from "react-ga4"; import { useRecoilState, useResetRecoilState } from "recoil"; import { ArrowCounterClockwise, CheckCircle, DiceFive, Link, } from "@phosphor-icons/react"; import { IconStyle } from "@phosphor-icons/core"; import { useTransientState } from "@/hooks"; import { iconWeightAtom, iconSizeAtom, iconColorAtom, resetSettingsSelector, } from "@/state"; import "./SettingsActions.css"; const SettingsActions = () => { const [weight, setWeight] = useRecoilState(iconWeightAtom); const [size, setSize] = useRecoilState(iconSizeAtom); const [color, setColor] = useRecoilState(iconColorAtom); const reset = useResetRecoilState(resetSettingsSelector); const [copied, setCopied] = useTransientState(false, 2000); const [booped, setBooped] = useState(false); const copyDeepLinkToClipboard = () => { const paramString = new URLSearchParams([ ["weight", weight.toString()], ["size", size.toString()], ["color", color.replace("#", "")], ]).toString(); void navigator.clipboard ?.writeText(`${window.location.host}?${paramString}`) .then(() => { setCopied(true); }) .catch(() => { alert("Clipboard permissions must be enabled to copy links!"); }); }; const randomizeSettings = () => { if (booped) setBooped(false); setBooped(true); const rWeight = Object.values(IconStyle).filter((w) => w !== weight)[ Math.floor(Math.random() * 5) ]; const rSize = 16 + Math.floor(Math.random() * 20 + 1) * 4; const rColor = "#" + Math.floor(Math.random() * (0xffffff + 1)) .toString(16) .padStart(6, "0"); setWeight(rWeight); setColor(rColor); setSize(rSize); ReactGA.event({ category: "Settings", action: "Random" }); }; return ( <> ); }; export default SettingsActions;