feat: Replace random ID generation with UUID for log entries; improve log entry consistency
This commit is contained in:
parent
06fa09bb42
commit
f8abd71116
app/src/components/ui/log
|
@ -1,4 +1,5 @@
|
||||||
import React, { createContext, useContext, useState, useCallback, useMemo } from "react";
|
import React, { createContext, useContext, useState, useCallback, useMemo } from "react";
|
||||||
|
import { MathUtils } from "three";
|
||||||
|
|
||||||
export type LogType = "log" | "info" | "warning" | "error" | "success";
|
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 [logs, setLogs] = useState<LogEntry[]>([]);
|
||||||
const [isLogListVisible, setIsLogListVisible] = useState<boolean>(false);
|
const [isLogListVisible, setIsLogListVisible] = useState<boolean>(false);
|
||||||
|
|
||||||
const generateId = useCallback(
|
|
||||||
() => Math.random().toString(36).substring(2, 9),
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
const addLog = useCallback(
|
const addLog = useCallback(
|
||||||
(type: LogType, message: string) => {
|
(type: LogType, message: string) => {
|
||||||
const newLog: LogEntry = {
|
const newLog: LogEntry = {
|
||||||
id: generateId(),
|
id: MathUtils.generateUUID(),
|
||||||
type,
|
type,
|
||||||
message,
|
message,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
};
|
};
|
||||||
setLogs((prevLogs) => [...prevLogs, newLog]);
|
setLogs((prevLogs) => [...prevLogs, newLog]);
|
||||||
},
|
},
|
||||||
[generateId]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const loggerMethods: LoggerContextValue = useMemo(() => ({
|
const loggerMethods: LoggerContextValue = useMemo(() => ({
|
||||||
|
|
Loading…
Reference in New Issue