Skip to content

Instantly share code, notes, and snippets.

@olawanlejoel
Last active July 31, 2025 20:14
Show Gist options
  • Select an option

  • Save olawanlejoel/4f0717654f01e99a83575b7459ff2dca to your computer and use it in GitHub Desktop.

Select an option

Save olawanlejoel/4f0717654f01e99a83575b7459ff2dca to your computer and use it in GitHub Desktop.
// ...existing code...
useEffect(() => {
if (typeof window === 'undefined') return; // Prevent SSR issues
if (hasRestored.current) return;
const activeJobId = localStorage.getItem("spidra-active-job");
if (activeJobId) {
try {
const parsed = JSON.parse(activeJobId);
if (parsed?.jobId && parsed?.formData) {
setFormData(parsed.formData);
setAiMode(parsed.formData.aiMode ?? false);
setCurrentJobId(parsed.jobId);
setIsLoading(true);
setProgress({ message: "Resuming scrape...", percentage: 0 });
addToast({ message: "Restored previous job", type: "info" });
hasRestored.current = true;
}
} catch (err) {
console.error("Failed to parse saved scrape data", err);
localStorage.removeItem("spidra-active-job");
}
}
}, []);
// ...existing code...
// Add this helper function at the top of the component
const getStoredJobData = () => {
if (typeof window === 'undefined') return null;
try {
const activeJobId = localStorage.getItem("spidra-active-job");
return activeJobId ? JSON.parse(activeJobId) : null;
} catch {
return null;
}
};
const setStoredJobData = (data: any) => {
if (typeof window === 'undefined') return;
localStorage.setItem("spidra-active-job", JSON.stringify(data));
};
const removeStoredJobData = () => {
if (typeof window === 'undefined') return;
localStorage.removeItem("spidra-active-job");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment