From 648b804e72d4831e41e02dfd7d6b5a9ac7660b58 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Fri, 30 Aug 2024 11:19:30 +0200 Subject: Added ui --- src/components/Frames/Frames.module.scss | 9 ++++ src/components/Frames/Frames.tsx | 75 ++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/components/Frames/Frames.module.scss create mode 100644 src/components/Frames/Frames.tsx (limited to 'src/components/Frames') diff --git a/src/components/Frames/Frames.module.scss b/src/components/Frames/Frames.module.scss new file mode 100644 index 0000000..821f0b8 --- /dev/null +++ b/src/components/Frames/Frames.module.scss @@ -0,0 +1,9 @@ +.arrow { + &.outbound { + color: green; + } + + &.inbound { + color: red; + } +} diff --git a/src/components/Frames/Frames.tsx b/src/components/Frames/Frames.tsx new file mode 100644 index 0000000..83c4c96 --- /dev/null +++ b/src/components/Frames/Frames.tsx @@ -0,0 +1,75 @@ +import { Frame } from "~/types"; +import React, { PropsWithChildren, useContext } from "react"; +import { Col, ListGroup, Row } from "react-bootstrap"; +import classNames from "classnames"; +import styles from "./Frames.module.scss"; +import dayjs from "dayjs"; +import ReactJson from "react-json-view"; +import { DarkModeContext } from "~/contexts/DarkMode"; + +function isJson(data: any): boolean { + try { + JSON.parse(data); + return true; + } catch { + return false; + } +} + +interface FramesProps { + frames: Frame[]; +} + +export default function Frames({ + frames, +}: PropsWithChildren): JSX.Element { + const { darkMode } = useContext(DarkModeContext); + return ( + + {frames.length > 0 ? ( + frames.map((frame) => { + // Inbound relative to the client + const inbound = frame.type !== "websocket_inbound"; + + const body = + frame.type !== "websocket_disconnect" + ? atob(frame.payload.body) + : null; + + return ( + + + + {dayjs(frame.payload?.timestamp).format("HH:mm:ss.SSS")} + + + {inbound ? "▼" : "▲"} + + {body} + + + ); + }) + ) : ( +
+

No messages

+
+ )} +
+ ); +} -- cgit v1.2.3