From a087494f6809a7a8ea8e6c27a105d8c8f0f3839e Mon Sep 17 00:00:00 2001
From: Tom van der Lee <tom@vanderlee.io>
Date: Wed, 4 Sep 2024 10:27:24 +0200
Subject: Updated the libraries

---
 src/components/Content/Content.tsx | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

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

diff --git a/src/components/Content/Content.tsx b/src/components/Content/Content.tsx
index e670376..94fca32 100644
--- a/src/components/Content/Content.tsx
+++ b/src/components/Content/Content.tsx
@@ -4,7 +4,7 @@ import { Headers, RequestPayload, ResponsePayload } from "~hooks/useRequests";
 import ReactJson from "react-json-view";
 import styles from "~/components/Content/Content.module.scss";
 import { Button, Col, Container, Row } from "react-bootstrap";
-import { DarkModeContext } from "~/contexts/DarkMode";
+import { SettingsContext } from "~/contexts/Settings";
 
 function getHeader(
   headers: Headers,
@@ -80,14 +80,14 @@ export default function Content({
 }
 
 function ContentBody({ data, raw = false }: Omit<ContentProps, "setRaw">) {
-  const { darkMode } = useContext(DarkModeContext);
+  const { darkMode } = useContext(SettingsContext);
   const contentType = useMemo(() => {
     if (raw) {
       return "";
     }
 
     const type = getHeader(data.headers, "content-type");
-    return type.toLowerCase().split(";")[0];
+    return type?.toLowerCase().split(";")[0];
   }, [data, raw]);
 
   if (raw) {
@@ -98,7 +98,10 @@ function ContentBody({ data, raw = false }: Omit<ContentProps, "setRaw">) {
     );
   }
 
-  if (["application/pdf", "text/html"].includes(contentType)) {
+  if (
+    contentType !== undefined &&
+    ["application/pdf", "text/html"].includes(contentType)
+  ) {
     return (
       <iframe
         className="bg-white"
@@ -110,7 +113,7 @@ function ContentBody({ data, raw = false }: Omit<ContentProps, "setRaw">) {
     );
   }
 
-  if (contentType.startsWith("application/json")) {
+  if (contentType?.startsWith("application/json")) {
     return (
       <ReactJson
         src={JSON.parse(atob(data.body))}
@@ -125,15 +128,15 @@ function ContentBody({ data, raw = false }: Omit<ContentProps, "setRaw">) {
     );
   }
 
-  if (contentType.startsWith("audio")) {
+  if (contentType?.startsWith("audio")) {
     return <audio src={`data:${contentType};base64,${data.body}`} />;
   }
 
-  if (contentType.startsWith("video")) {
+  if (contentType?.startsWith("video")) {
     return <video src={`data:${contentType};base64,${data.body}`} />;
   }
 
-  if (contentType.startsWith("image")) {
+  if (contentType?.startsWith("image")) {
     return <img src={`data:${contentType};base64,${data.body}`} alt="" />;
   }
 
-- 
cgit v1.2.3

