Spaces:
Running
Running
File size: 2,665 Bytes
5301c48 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
'use client'
import '../../styles/globals.css'
import { Inter } from "next/font/google";
import { useEffect, useState, useCallback } from 'react';
// import Auth from "../auth/components/Auth";
import NavBar from "../auth/components/NavBar";
import { Toaster } from "@/components/ui/toaster"
import Script from 'next/script';
const inter = Inter({ subsets: ["latin"] });
export default function RootLayout({
children,
}: {
children: React.ReactNode,
}) {
const [projects, setProjects] = useState([]);
const [isLoading, setIsLoading] = useState(false);
// Function to fetch projects
const fetchProjects = useCallback(async () => {
setIsLoading(true);
try {
const response = await fetch('/api/projects/list', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userId: "user_67890"
}),
});
if (!response.ok) {
throw new Error(`Failed to fetch projects: ${response.status}`);
}
const projectsData = await response.json();
setProjects(projectsData);
} catch (error) {
console.error('Error fetching projects:', error);
setProjects([]);
} finally {
setIsLoading(false);
}
}, []);
// Initial fetch on mount
useEffect(() => {
fetchProjects();
}, [fetchProjects]);
// Set up real-time updates with polling
useEffect(() => {
const interval = setInterval(() => {
fetchProjects();
}, 30000); // Refresh every 30 seconds
return () => clearInterval(interval);
}, [fetchProjects]);
// Add visibility change listener for real-time updates
useEffect(() => {
const handleVisibilityChange = () => {
if (!document.hidden) {
fetchProjects();
}
};
document.addEventListener('visibilitychange', handleVisibilityChange);
return () => document.removeEventListener('visibilitychange', handleVisibilityChange);
}, [fetchProjects]);
return (
<html lang="en">
<head>
<Script
src="https://getlaunchlist.com/js/widget-diy.js"
strategy="afterInteractive"
defer
/>
);
} |