diff --git a/app/[slug]/dashboard/website/page.tsx b/app/[slug]/dashboard/website/page.tsx index b298101..989e3f1 100644 --- a/app/[slug]/dashboard/website/page.tsx +++ b/app/[slug]/dashboard/website/page.tsx @@ -13,15 +13,25 @@ export default function Page() { const api = new AbstractApi(); const serializer = new WebsiteSerializer(); + const [timeoutId, setTimeoutId] = useState(null); + useEffect(() => { api.get(serializer, undefined, (loadedWebsite) => { setWebsite(loadedWebsite); - console.log('Website loaded:', loadedWebsite); }); }, []); const updateWebsite = (newContent: string) => { - api.update(serializer, new Website('', newContent), () => { }); + // Debounce API update: send after 500ms of no further changes + if (timeoutId) { + clearTimeout(timeoutId); + } + + setTimeoutId( + setTimeout(() => { + api.update(serializer, new Website('', newContent), () => { }); + }, 500) + ); } return (