diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/App/App.tsx | 18 | ||||
| -rw-r--r-- | src/components/Content/Content.tsx | 19 | ||||
| -rw-r--r-- | src/components/Frames/Frames.tsx | 3 | ||||
| -rw-r--r-- | src/components/RequestList/RequestList.tsx | 4 | ||||
| -rw-r--r-- | src/components/RequestSummary/RequestSummary.tsx | 3 | ||||
| -rw-r--r-- | src/contexts/DarkMode.tsx | 41 | ||||
| -rw-r--r-- | src/contexts/Settings.tsx | 65 | ||||
| -rw-r--r-- | src/index.scss | 1 | ||||
| -rw-r--r-- | src/index.tsx | 6 | ||||
| -rw-r--r-- | src/types.ts | 4 |
10 files changed, 94 insertions, 70 deletions
diff --git a/src/components/App/App.tsx b/src/components/App/App.tsx index ad36add..85119e6 100644 --- a/src/components/App/App.tsx +++ b/src/components/App/App.tsx | |||
| @@ -1,25 +1,19 @@ | |||
| 1 | import * as React from "react"; | 1 | import * as React from "react"; |
| 2 | import { ReactElement, useContext, useEffect, useMemo, useState } from "react"; | 2 | import { ReactElement, useContext, useEffect } from "react"; |
| 3 | import useRequests from "~/hooks/useRequests"; | ||
| 4 | 3 | ||
| 5 | import styles from "~/components/App/App.module.scss"; | 4 | import styles from "~/components/App/App.module.scss"; |
| 6 | import RequestDetails from "~/components/RequestDetails/RequestDetails"; | 5 | import RequestDetails from "~/components/RequestDetails/RequestDetails"; |
| 7 | import { getHost } from "~/utils"; | ||
| 8 | import { Container, Nav, Navbar, NavDropdown } from "react-bootstrap"; | 6 | import { Container, Nav, Navbar, NavDropdown } from "react-bootstrap"; |
| 9 | import classNames from "classnames"; | 7 | import classNames from "classnames"; |
| 10 | import Sliders from "~/components/Icons/Sliders"; | 8 | import Sliders from "~/components/Icons/Sliders"; |
| 11 | import Sun from "~/components/Icons/Sun"; | 9 | import Sun from "~/components/Icons/Sun"; |
| 12 | import Moon from "~/components/Icons/Moon"; | 10 | import Moon from "~/components/Icons/Moon"; |
| 13 | import Trash from "~/components/Icons/Trash"; | 11 | import Trash from "~/components/Icons/Trash"; |
| 14 | import { DarkModeContext } from "~/contexts/DarkMode"; | 12 | import { SettingsContext } from "~/contexts/Settings"; |
| 15 | import RequestList from "~/components/RequestList/RequestList"; | 13 | import RequestList from "~/components/RequestList/RequestList"; |
| 16 | import { Call, ReadyState } from "~/types"; | 14 | import { ReadyState } from "~/types"; |
| 17 | import { ConnectionContext } from "~/contexts/Connection"; | 15 | import { ConnectionContext } from "~/contexts/Connection"; |
| 18 | 16 | ||
| 19 | interface Config { | ||
| 20 | url: string; | ||
| 21 | } | ||
| 22 | |||
| 23 | interface SettingsMenu { | 17 | interface SettingsMenu { |
| 24 | icon: ReactElement; | 18 | icon: ReactElement; |
| 25 | label: string; | 19 | label: string; |
| @@ -48,8 +42,8 @@ const statusTextMap: ReadyStateMap = { | |||
| 48 | }; | 42 | }; |
| 49 | 43 | ||
| 50 | export default function App() { | 44 | export default function App() { |
| 51 | const { darkMode, toggle } = useContext(DarkModeContext); | 45 | const { darkMode, setSetting } = useContext(SettingsContext); |
| 52 | const { config, selectedCall, setSelectedCall, readyState, clear } = | 46 | const { config, setSelectedCall, readyState, clear } = |
| 53 | useContext(ConnectionContext); | 47 | useContext(ConnectionContext); |
| 54 | 48 | ||
| 55 | useEffect(() => { | 49 | useEffect(() => { |
| @@ -59,7 +53,7 @@ export default function App() { | |||
| 59 | 53 | ||
| 60 | const settingsMenu: (SettingsMenu | null)[] = [ | 54 | const settingsMenu: (SettingsMenu | null)[] = [ |
| 61 | { | 55 | { |
| 62 | onClick: toggle, | 56 | onClick: () => setSetting("darkMode", !darkMode), |
| 63 | icon: darkMode ? <Sun /> : <Moon />, | 57 | icon: darkMode ? <Sun /> : <Moon />, |
| 64 | label: darkMode ? "Light mode" : "Dark mode", | 58 | label: darkMode ? "Light mode" : "Dark mode", |
| 65 | }, | 59 | }, |
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"; | |||
| 4 | import ReactJson from "react-json-view"; | 4 | import ReactJson from "react-json-view"; |
| 5 | import styles from "~/components/Content/Content.module.scss"; | 5 | import styles from "~/components/Content/Content.module.scss"; |
| 6 | import { Button, Col, Container, Row } from "react-bootstrap"; | 6 | import { Button, Col, Container, Row } from "react-bootstrap"; |
| 7 | import { DarkModeContext } from "~/contexts/DarkMode"; | 7 | import { SettingsContext } from "~/contexts/Settings"; |
| 8 | 8 | ||
| 9 | function getHeader( | 9 | function getHeader( |
| 10 | headers: Headers, | 10 | headers: Headers, |
| @@ -80,14 +80,14 @@ export default function Content({ | |||
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | function ContentBody({ data, raw = false }: Omit<ContentProps, "setRaw">) { | 82 | function ContentBody({ data, raw = false }: Omit<ContentProps, "setRaw">) { |
| 83 | const { darkMode } = useContext(DarkModeContext); | 83 | const { darkMode } = useContext(SettingsContext); |
| 84 | const contentType = useMemo(() => { | 84 | const contentType = useMemo(() => { |
| 85 | if (raw) { | 85 | if (raw) { |
| 86 | return ""; | 86 | return ""; |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | const type = getHeader(data.headers, "content-type"); | 89 | const type = getHeader(data.headers, "content-type"); |
| 90 | return type.toLowerCase().split(";")[0]; | 90 | return type?.toLowerCase().split(";")[0]; |
| 91 | }, [data, raw]); | 91 | }, [data, raw]); |
| 92 | 92 | ||
| 93 | if (raw) { | 93 | if (raw) { |
| @@ -98,7 +98,10 @@ function ContentBody({ data, raw = false }: Omit<ContentProps, "setRaw">) { | |||
| 98 | ); | 98 | ); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | if (["application/pdf", "text/html"].includes(contentType)) { | 101 | if ( |
| 102 | contentType !== undefined && | ||
| 103 | ["application/pdf", "text/html"].includes(contentType) | ||
| 104 | ) { | ||
| 102 | return ( | 105 | return ( |
| 103 | <iframe | 106 | <iframe |
| 104 | className="bg-white" | 107 | className="bg-white" |
| @@ -110,7 +113,7 @@ function ContentBody({ data, raw = false }: Omit<ContentProps, "setRaw">) { | |||
| 110 | ); | 113 | ); |
| 111 | } | 114 | } |
| 112 | 115 | ||
| 113 | if (contentType.startsWith("application/json")) { | 116 | if (contentType?.startsWith("application/json")) { |
| 114 | return ( | 117 | return ( |
| 115 | <ReactJson | 118 | <ReactJson |
| 116 | src={JSON.parse(atob(data.body))} | 119 | src={JSON.parse(atob(data.body))} |
| @@ -125,15 +128,15 @@ function ContentBody({ data, raw = false }: Omit<ContentProps, "setRaw">) { | |||
| 125 | ); | 128 | ); |
| 126 | } | 129 | } |
| 127 | 130 | ||
| 128 | if (contentType.startsWith("audio")) { | 131 | if (contentType?.startsWith("audio")) { |
| 129 | return <audio src={`data:${contentType};base64,${data.body}`} />; | 132 | return <audio src={`data:${contentType};base64,${data.body}`} />; |
| 130 | } | 133 | } |
| 131 | 134 | ||
| 132 | if (contentType.startsWith("video")) { | 135 | if (contentType?.startsWith("video")) { |
| 133 | return <video src={`data:${contentType};base64,${data.body}`} />; | 136 | return <video src={`data:${contentType};base64,${data.body}`} />; |
| 134 | } | 137 | } |
| 135 | 138 | ||
| 136 | if (contentType.startsWith("image")) { | 139 | if (contentType?.startsWith("image")) { |
| 137 | return <img src={`data:${contentType};base64,${data.body}`} alt="" />; | 140 | return <img src={`data:${contentType};base64,${data.body}`} alt="" />; |
| 138 | } | 141 | } |
| 139 | 142 | ||
diff --git a/src/components/Frames/Frames.tsx b/src/components/Frames/Frames.tsx index 83c4c96..1d31d92 100644 --- a/src/components/Frames/Frames.tsx +++ b/src/components/Frames/Frames.tsx | |||
| @@ -5,7 +5,7 @@ import classNames from "classnames"; | |||
| 5 | import styles from "./Frames.module.scss"; | 5 | import styles from "./Frames.module.scss"; |
| 6 | import dayjs from "dayjs"; | 6 | import dayjs from "dayjs"; |
| 7 | import ReactJson from "react-json-view"; | 7 | import ReactJson from "react-json-view"; |
| 8 | import { DarkModeContext } from "~/contexts/DarkMode"; | 8 | import { SettingsContext } from "~/contexts/Settings"; |
| 9 | 9 | ||
| 10 | function isJson(data: any): boolean { | 10 | function isJson(data: any): boolean { |
| 11 | try { | 11 | try { |
| @@ -23,7 +23,6 @@ interface FramesProps { | |||
| 23 | export default function Frames({ | 23 | export default function Frames({ |
| 24 | frames, | 24 | frames, |
| 25 | }: PropsWithChildren<FramesProps>): JSX.Element { | 25 | }: PropsWithChildren<FramesProps>): JSX.Element { |
| 26 | const { darkMode } = useContext(DarkModeContext); | ||
| 27 | return ( | 26 | return ( |
| 28 | <ListGroup variant="flush" as="ul" className={"flex-grow-1"}> | 27 | <ListGroup variant="flush" as="ul" className={"flex-grow-1"}> |
| 29 | {frames.length > 0 ? ( | 28 | {frames.length > 0 ? ( |
diff --git a/src/components/RequestList/RequestList.tsx b/src/components/RequestList/RequestList.tsx index 82a6b21..8217229 100644 --- a/src/components/RequestList/RequestList.tsx +++ b/src/components/RequestList/RequestList.tsx | |||
| @@ -12,7 +12,7 @@ import styles from "~/components/RequestList/RequestList.module.scss"; | |||
| 12 | import RequestSummary from "~/components/RequestSummary/RequestSummary"; | 12 | import RequestSummary from "~/components/RequestSummary/RequestSummary"; |
| 13 | import * as React from "react"; | 13 | import * as React from "react"; |
| 14 | import { useCallback, useContext, useEffect, useMemo, useState } from "react"; | 14 | import { useCallback, useContext, useEffect, useMemo, useState } from "react"; |
| 15 | import { DarkModeContext } from "~/contexts/DarkMode"; | 15 | import { SettingsContext } from "~/contexts/Settings"; |
| 16 | import Filter from "~/components/Icons/Filter"; | 16 | import Filter from "~/components/Icons/Filter"; |
| 17 | import { Call, Method } from "~/types"; | 17 | import { Call, Method } from "~/types"; |
| 18 | import { ConnectionContext } from "~/contexts/Connection"; | 18 | import { ConnectionContext } from "~/contexts/Connection"; |
| @@ -22,7 +22,7 @@ type EnabledMethods = { | |||
| 22 | }; | 22 | }; |
| 23 | 23 | ||
| 24 | export default function RequestList() { | 24 | export default function RequestList() { |
| 25 | const { darkMode } = useContext(DarkModeContext); | 25 | const { darkMode } = useContext(SettingsContext); |
| 26 | const { | 26 | const { |
| 27 | calls: requests, | 27 | calls: requests, |
| 28 | selectedCall, | 28 | selectedCall, |
diff --git a/src/components/RequestSummary/RequestSummary.tsx b/src/components/RequestSummary/RequestSummary.tsx index 4e97676..64ff475 100644 --- a/src/components/RequestSummary/RequestSummary.tsx +++ b/src/components/RequestSummary/RequestSummary.tsx | |||
| @@ -4,10 +4,11 @@ import classNames from "classnames"; | |||
| 4 | 4 | ||
| 5 | import { Badge, Col, Row } from "react-bootstrap"; | 5 | import { Badge, Col, Row } from "react-bootstrap"; |
| 6 | import dayjs from "dayjs"; | 6 | import dayjs from "dayjs"; |
| 7 | import { Call } from "~/types"; | ||
| 7 | 8 | ||
| 8 | interface RequestSummaryProps { | 9 | interface RequestSummaryProps { |
| 9 | selected?: boolean; | 10 | selected?: boolean; |
| 10 | requestResponse: Calls; | 11 | requestResponse: Call; |
| 11 | showTime?: boolean; | 12 | showTime?: boolean; |
| 12 | } | 13 | } |
| 13 | 14 | ||
diff --git a/src/contexts/DarkMode.tsx b/src/contexts/DarkMode.tsx deleted file mode 100644 index fd536b2..0000000 --- a/src/contexts/DarkMode.tsx +++ /dev/null | |||
| @@ -1,41 +0,0 @@ | |||
