From bcb77d979d817e1e609adb4d007bbbcc3f61efbd Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Thu, 30 Dec 2021 09:51:00 +0100 Subject: Prepare for github --- src/components/Details/Details.module.scss | 84 ++++++++++++++++ src/components/Details/Details.tsx | 148 +++++++++++++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 src/components/Details/Details.module.scss create mode 100644 src/components/Details/Details.tsx (limited to 'src/components/Details') diff --git a/src/components/Details/Details.module.scss b/src/components/Details/Details.module.scss new file mode 100644 index 0000000..32197f0 --- /dev/null +++ b/src/components/Details/Details.module.scss @@ -0,0 +1,84 @@ +.details { + height: 100%; + display: flex; + flex-flow: column nowrap; + align-items: stretch; + overflow: hidden; +} + +.header { + flex-shrink: 0; + flex-grow: 0; +} + +.content { + flex-grow: 1; + flex-shrink: 1; + overflow-y: auto; +} + +.summary { + font-size: 2em; +} + +.tabs { + display: flex; + border-bottom: 1px solid black; + + &:last-child { + flex-grow: 1; + } +} + +.tab { + background-color: white; + border: none; + border-top: 1px solid black; + border-right: 1px solid black; + border-radius: 0; + color: black; + font-size: 1.2em; + padding: 0.5em; + + &.selected { + background-color: black; + color: white; + } +} + +.emptySpace { + flex-grow: 1; + display: flex; + justify-content: flex-end; + align-items: center; + font-size: 1.2em; + padding: 0.5em; +} + +.resend { + margin-left: 1em; +} + +.headers { + display: grid; + grid-template-columns: auto 1fr; + border: 1px solid black; + margin: 1em; + overflow-x: auto; + + h2 { + grid-column: 1/ span 2; + background-color: black; + color: white; + padding: 0.5em; + } + + > div { + line-break: auto; + padding: 0.5em; + + &:nth-of-type(4n), &:nth-of-type(4n - 1) { + background-color: lightgray; + } + } +} diff --git a/src/components/Details/Details.tsx b/src/components/Details/Details.tsx new file mode 100644 index 0000000..c4a23f4 --- /dev/null +++ b/src/components/Details/Details.tsx @@ -0,0 +1,148 @@ +import * as React from "react"; +import { + RequestPayload, + RequestResponse, + ResponsePayload +} from "~hooks/useRequests"; +import {useCallback, useEffect, useMemo, useState} from "react"; +import styles from "./Details.module.scss"; +import RequestSummary from "../RequestSummary/RequestSummary"; +import classNames from 'classnames'; +import Content from "../Content/Content"; +import {getHost} from "../../utils"; + + +interface TimingProps { + timing: number; +} + + +function Timing({ timing }: TimingProps) { + const value = useMemo(() => (Math.round(timing * 1000) / 1000), [timing]); + const showSeconds = useMemo(() => value > 1, [value]); + + return !Number.isNaN(value) + ? ( + <> + {`${showSeconds ? value : value * 1000}${ showSeconds ? 's' : 'ms' }`} + + ) + : null; +} + +interface HeadersProps { + title: string + headers: { + [key: string]: string + } +} + +function Headers({ title, headers }: HeadersProps) { + return ( +
+

{ title }

+ { + Object.entries(headers).map(([key, value]) => ( + <> +
{key}
+
{value}
+ + )) + } +
+ ) +} + +interface DetailsProps { + requestResponse: RequestResponse +} + +type Tab = 'headers' | 'request' | 'response' + +export default function Details({ requestResponse }: DetailsProps) { + const [tab, selectTab] = useState('headers'); + const [raw, setRaw] = useState(false); + + const resend = useCallback(async () => fetch( + `http://${getHost()}/resend/`, + { + method: 'POST', + body: JSON.stringify({ + ...requestResponse.request, + id: undefined + }) + } + ), [requestResponse]); + + return ( +
+
+ + +
+ + + + +
+ + +
+
+
+
+ { + tab === 'headers' && ( + <> + + { + requestResponse.response && ( + + ) + } + + ) + } + { + tab === 'request' && ( + + ) + } + { + tab === 'response' && requestResponse.response !== undefined && ( + + ) + } +
+
+ ) +} -- cgit v1.2.3