import React, { useState, useCallback, useRef, useEffect } from 'react'; import { Label, Button, OGDialog, OGDialogTrigger, Spinner } from '~/components'; import OGDialogTemplate from '~/components/ui/OGDialogTemplate'; import { useOnClickOutside, useLocalize } from '~/hooks'; export const DeleteCache = ({ disabled = false }: { disabled?: boolean }) => { const localize = useLocalize(); const [open, setOpen] = useState(false); const [isCacheEmpty, setIsCacheEmpty] = useState(true); const [confirmClear, setConfirmClear] = useState(false); const [isLoading, setIsLoading] = useState(false); const contentRef = useRef(null); useOnClickOutside(contentRef, () => confirmClear && setConfirmClear(false), []); const checkCache = useCallback(async () => { const cache = await caches.open('tts-responses'); const keys = await cache.keys(); setIsCacheEmpty(keys.length === 0); }, []); useEffect(() => { checkCache(); }, [checkCache]); const revokeAllUserKeys = useCallback(async () => { setIsLoading(true); const cache = await caches.open('tts-responses'); await cache.keys().then((keys) => Promise.all(keys.map((key) => cache.delete(key)))); setIsLoading(false); }, []); return (