This commit is contained in:
parent
cdaf16b157
commit
d4f7aec4a5
@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { createContext, useEffect, useState } from "react";
|
import { createContext, ReactNode, useEffect, useState } from "react";
|
||||||
import Database, { db } from "../../common/database/database";
|
import Database, { db } from "../../common/database/database";
|
||||||
import FullscreenLoader from "./fullscreen-loader";
|
import FullscreenLoader from "./fullscreen-loader";
|
||||||
import { useToast } from "@/hooks/use-toast";
|
import { useToast } from "@/hooks/use-toast";
|
||||||
@ -10,23 +10,27 @@ import { useToast } from "@/hooks/use-toast";
|
|||||||
*/
|
*/
|
||||||
export const DatabaseContext = createContext<Database | undefined>(undefined);
|
export const DatabaseContext = createContext<Database | undefined>(undefined);
|
||||||
|
|
||||||
type Props = {
|
type DatabaseLoaderProps = {
|
||||||
children: React.ReactNode;
|
/**
|
||||||
|
* The children to render.
|
||||||
|
*/
|
||||||
|
children: ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function DatabaseLoader({ children }: Props) {
|
export default function DatabaseLoader({ children }: DatabaseLoaderProps) {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const [database, setDatabase] = useState<Database | undefined>(undefined);
|
const [database, setDatabase] = useState<Database | undefined>(undefined);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const before = performance.now();
|
const before = performance.now();
|
||||||
setDatabase(db);
|
setDatabase(db);
|
||||||
console.log(`Loaded database in ${performance.now() - before}ms`);
|
|
||||||
|
|
||||||
db.on("ready", () => {
|
db.on("ready", () => {
|
||||||
|
const loadTime = (performance.now() - before).toFixed(0);
|
||||||
|
console.log(`Loaded database in ${loadTime}ms`);
|
||||||
toast({
|
toast({
|
||||||
title: "Database loaded",
|
title: "Database loaded",
|
||||||
description: `The database was loaded in ${performance.now() - before}ms.`,
|
description: `The database was loaded in ${loadTime}ms.`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, [toast]);
|
}, [toast]);
|
||||||
|
Reference in New Issue
Block a user