This commit is contained in:
parent
cdaf16b157
commit
d4f7aec4a5
@ -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<Database | undefined>(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<Database | undefined>(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]);
|
||||
|
Reference in New Issue
Block a user