From d4f7aec4a50df619b96fe53ccacce5dc37312b6a Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 1 Oct 2024 16:28:22 +0100 Subject: [PATCH] fix load time --- src/components/loaders/database-loader.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/loaders/database-loader.tsx b/src/components/loaders/database-loader.tsx index f28e3cf..1f263d9 100644 --- a/src/components/loaders/database-loader.tsx +++ b/src/components/loaders/database-loader.tsx @@ -1,6 +1,6 @@ "use client"; -import { createContext, useEffect, useState } from "react"; +import { createContext, ReactNode, useEffect, useState } from "react"; import Database, { db } from "../../common/database/database"; import FullscreenLoader from "./fullscreen-loader"; import { useToast } from "@/hooks/use-toast"; @@ -10,23 +10,27 @@ import { useToast } from "@/hooks/use-toast"; */ export const DatabaseContext = createContext(undefined); -type Props = { - children: React.ReactNode; +type DatabaseLoaderProps = { + /** + * The children to render. + */ + children: ReactNode; }; -export default function DatabaseLoader({ children }: Props) { +export default function DatabaseLoader({ children }: DatabaseLoaderProps) { const { toast } = useToast(); const [database, setDatabase] = useState(undefined); useEffect(() => { const before = performance.now(); setDatabase(db); - console.log(`Loaded database in ${performance.now() - before}ms`); db.on("ready", () => { + const loadTime = (performance.now() - before).toFixed(0); + console.log(`Loaded database in ${loadTime}ms`); toast({ title: "Database loaded", - description: `The database was loaded in ${performance.now() - before}ms.`, + description: `The database was loaded in ${loadTime}ms.`, }); }); }, [toast]);