Files
Dwinzo_dev/app/src/components/ui/log/LogList.tsx

82 lines
2.4 KiB
TypeScript
Raw Normal View History

2025-05-02 17:14:36 +05:30
// LogList.tsx
import React, { useState } from "react";
import { LogListIcon, CloseIcon } from "../../icons/ExportCommonIcons"; // Adjust path as needed
2025-05-02 17:14:36 +05:30
import { useLogger } from "./LoggerContext";
import { GetLogIcon } from "../../footer/getLogIcons";
2025-05-02 17:14:36 +05:30
const LogList: React.FC = () => {
const { logs, clear, setIsLogListVisible } = useLogger();
const [selectedTab, setSelectedTab] = useState<
"all" | "info" | "warning" | "error" | "log" | "success"
2025-05-02 17:14:36 +05:30
>("all");
const formatTimestamp = (date: Date) => new Date(date).toLocaleTimeString();
const filteredLogs =
selectedTab === "all"
? [...logs].reverse()
: [...logs].filter((log) => log.type === selectedTab).reverse();
return (
// eslint-disable-next-line
<div
className="log-list-container"
onClick={() => setIsLogListVisible(false)}
>
<div
className="log-list-wrapper"
onClick={(e) => {
e.stopPropagation();
}}
>
2025-05-02 17:14:36 +05:30
<div className="log-header">
<div className="log-header-wrapper">
<div className="icon">
<LogListIcon />
</div>
<div className="head">Log List</div>
</div>
<button
title="close-btn"
className="close"
onClick={() => setIsLogListVisible(false)}
>
<CloseIcon />
</button>
2025-05-02 17:14:36 +05:30
</div>
{/* Tabs */}
<div className="log-nav-wrapper">
{["all", "info", "warning", "error"].map((type) => (
<button
title="log-type"
2025-05-02 17:14:36 +05:30
key={type}
className={`log-nav ${selectedTab === type ? "active" : ""}`}
onClick={() => setSelectedTab(type as any)}
>
{`${type.charAt(0).toUpperCase() + type.slice(1)} Logs`}
</button>
2025-05-02 17:14:36 +05:30
))}
</div>
{/* Log Entries */}
<div className="log-entry-wrapper">
{filteredLogs.map((log) => (
<div key={log.id} className={`log-entry ${log.type}`}>
<div className="log-icon">{GetLogIcon(log.type)}</div>
<div className="log-entry-message-container">
<div className="log-entry-message">{log.message}</div>
<div className="message-time">
{formatTimestamp(log.timestamp)}
</div>
2025-05-02 17:14:36 +05:30
</div>
</div>
))}
</div>
</div>
</div>
);
};
export default LogList;