diff --git a/apps/extension/content/ContentApp.tsx b/apps/extension/content/ContentApp.tsx index 66985047..54e7928a 100644 --- a/apps/extension/content/ContentApp.tsx +++ b/apps/extension/content/ContentApp.tsx @@ -21,6 +21,7 @@ import { useToast } from "./ui/shadcn/use-toast"; import { Input } from "./ui/shadcn/input"; import { Label } from "./ui/shadcn/label"; import { Textarea } from "./ui/shadcn/textarea"; +import ShowCommandMenu from "./showCommandMenu"; const BACKEND_URL = "https://supermemory.ai"; @@ -96,6 +97,52 @@ export default function ContentApp({ } }; + const [timer, setTimer] = useState(null); + const [progress, setProgress] = useState(0); + const timerRef = useRef(null); + + useEffect(() => { + if (isPopoverOpen && !timer) { + startTimer(); + } + }, [isPopoverOpen]); + + const startTimer = () => { + setProgress(0); + // @ts-ignore + timerRef.current = setInterval(() => { + setProgress((prev) => { + if (prev >= 100) { + clearInterval(timerRef.current!); + saveContent(); + return prev; + } + return prev + 5; + }); + }, 100); + }; + + const stopTimer = () => { + clearInterval(timerRef.current!); + setTimer(null); + }; + + const saveContent = async () => { + await sendUrlToAPI(selectedSpace ? [selectedSpace] : []); + }; + + const handleInputChange = ( + e: React.ChangeEvent, + ) => { + setWebNote(e.target.value); + stopTimer(); + }; + + const handleSelectChange = (value: string) => { + setSelectedSpace(value); + stopTimer(); + }; + useEffect(() => { document.addEventListener("mousemove", (e) => { const percentageX = (e.clientX / window.innerWidth) * 100; @@ -309,7 +356,10 @@ export default function ContentApp({ ) : (
-