From 648b804e72d4831e41e02dfd7d6b5a9ac7660b58 Mon Sep 17 00:00:00 2001
From: Tom van der Lee <tom@vanderlee.io>
Date: Fri, 30 Aug 2024 11:19:30 +0200
Subject: Added ui

---
 src/components/Frames/Frames.tsx | 75 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 src/components/Frames/Frames.tsx

(limited to 'src/components/Frames/Frames.tsx')

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<FramesProps>): JSX.Element {
+  const { darkMode } = useContext(DarkModeContext);
+  return (
+    <ListGroup variant="flush" as="ul" className={"flex-grow-1"}>
+      {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 (
+            <ListGroup.Item
+              as="li"
+              key={frame.payload.id}
+              className={classNames({
+                "border-bottom": true,
+              })}
+            >
+              <Row>
+                <Col className="flex-grow-0 d-flex align-items-center text-nowrap text-muted">
+                  {dayjs(frame.payload?.timestamp).format("HH:mm:ss.SSS")}
+                </Col>
+                <Col
+                  className={classNames(
+                    styles.arrow,
+                    "flex-grow-0 d-flex align-items-center flex-nowrap",
+                    {
+                      [styles.inbound]: inbound,
+                      [styles.outbound]: !inbound,
+                    }
+                  )}
+                >
+                  {inbound ? "▼" : "▲"}
+                </Col>
+                <Col className="flex-grow-1">{body}</Col>
+              </Row>
+            </ListGroup.Item>
+          );
+        })
+      ) : (
+        <div className={styles.noRequest}>
+          <p>No messages</p>
+        </div>
+      )}
+    </ListGroup>
+  );
+}
-- 
cgit v1.2.3

