feat: Replace random ID generation with UUID for log entries; improve log entry consistency

This commit is contained in:
Vishnu 2025-05-03 16:52:48 +05:30
parent 06fa09bb42
commit f8abd71116
1 changed files with 3 additions and 7 deletions

View File

@ -1,4 +1,5 @@
import React, { createContext, useContext, useState, useCallback, useMemo } from "react";
import { MathUtils } from "three";
export type LogType = "log" | "info" | "warning" | "error" | "success";
@ -30,22 +31,17 @@ export const LoggerProvider: React.FC<{ children: React.ReactNode }> = ({
const [logs, setLogs] = useState<LogEntry[]>([]);
const [isLogListVisible, setIsLogListVisible] = useState<boolean>(false);
const generateId = useCallback(
() => Math.random().toString(36).substring(2, 9),
[]
);
const addLog = useCallback(
(type: LogType, message: string) => {
const newLog: LogEntry = {
id: generateId(),
id: MathUtils.generateUUID(),
type,
message,
timestamp: new Date(),
};
setLogs((prevLogs) => [...prevLogs, newLog]);
},
[generateId]
[]
);
const loggerMethods: LoggerContextValue = useMemo(() => ({