import { useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { IconChevronDown } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { Drawer, DrawerClose, DrawerContent, DrawerHeader, DrawerTitle, DrawerTrigger, } from "@kandev/ui/drawer"; import { PresetsSidebar, type PresetsSidebarProps } from "./presets-sidebar"; import { MobileConfirmationHost, MobileConfirmationHostBody, } from "@/components/confirmation/mobile-confirmation-host"; export function MobileViewsPicker({ title, onSelect, onSaveCurrent, ...props }: PresetsSidebarProps & { title: string }) { const { t } = useTranslation(); const [open, setOpen] = useState(false); const saveAfterClose = useRef(false); const saveFrame = useRef(0); useEffect( () => () => { saveAfterClose.current = false; cancelAnimationFrame(saveFrame.current); }, [], ); return ( {({ contentProps }) => ( { if (!saveAfterClose.current) return; saveAfterClose.current = false; saveFrame.current = requestAnimationFrame(onSaveCurrent); }} > {t("github:views")} { onSelect(selection); if (selection.source !== "kind-switch") setOpen(false); }} onSaveCurrent={() => { saveAfterClose.current = true; setOpen(false); }} /> )} ); }