diff --git a/src/components/log-item.tsx b/src/components/log-item.tsx new file mode 100644 index 0000000000..89e6629ad5 --- /dev/null +++ b/src/components/log-item.tsx @@ -0,0 +1,21 @@ +import { styled, Box } from "@mui/material"; + +const LogItem = styled(Box)(({ theme }) => ({ + padding: "8px 0", + margin: "0 12px", + lineHeight: 1.35, + borderBottom: `1px solid ${theme.palette.divider}`, + "& .time": {}, + "& .type": { + display: "inline-block", + width: 50, + margin: "0 4px", + textAlign: "center", + borderRadius: 2, + textTransform: "uppercase", + fontWeight: "600", + }, + "& .data": {}, +})); + +export default LogItem; diff --git a/src/pages/log.tsx b/src/pages/log.tsx index cf4cd6a71d..cf265667ac 100644 --- a/src/pages/log.tsx +++ b/src/pages/log.tsx @@ -1,21 +1,69 @@ -import { useEffect } from "react"; -import { Box, Typography } from "@mui/material"; +import dayjs from "dayjs"; +import { useEffect, useRef, useState } from "react"; +import { Box, Button, Paper, Typography } from "@mui/material"; +import { Virtuoso } from "react-virtuoso"; +import LogItem from "../components/log-item"; import services from "../services"; +let logCache: any[] = []; + const LogPage = () => { + const [logData, setLogData] = useState(logCache); + useEffect(() => { - const sourcePromise = services.getLogs(console.log); + const sourcePromise = services.getLogs((t) => { + const time = dayjs().format("MM-DD HH:mm:ss"); + const item = { ...t, time }; + setLogData((l) => (logCache = [...l, item])); + }); return () => { - sourcePromise.then((src) => src.cancel()); + sourcePromise.then((src) => src.cancel("cancel")); }; }, []); return ( - + Logs + + + + + { + return ( + + {logItem.time} + {logItem.type} + {logItem.payload} + + ); + }} + followOutput={"smooth"} + /> + ); };