diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/App/App.tsx | 3 | ||||
| -rw-r--r-- | src/components/RequestDetails/RequestDetails.tsx | 2 | ||||
| -rw-r--r-- | src/components/RequestList/RequestList.tsx | 2 | ||||
| -rw-r--r-- | src/hooks/useRequests.tsx | 70 | ||||
| -rw-r--r-- | src/types.ts | 119 |
5 files changed, 137 insertions, 59 deletions
diff --git a/src/components/App/App.tsx b/src/components/App/App.tsx index b1a4501..5e17388 100644 --- a/src/components/App/App.tsx +++ b/src/components/App/App.tsx | |||
| @@ -1,6 +1,6 @@ | |||
| 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, useMemo, useState } from "react"; |
| 3 | import useRequests, { ReadyState, RequestResponse } from "~/hooks/useRequests"; | 3 | import useRequests from "~/hooks/useRequests"; |
| 4 | 4 | ||
| 5 | import styles from "~/components/App/App.module.scss"; | 5 | import styles from "~/components/App/App.module.scss"; |
| 6 | import RequestDetails from "~/components/RequestDetails/RequestDetails"; | 6 | import RequestDetails from "~/components/RequestDetails/RequestDetails"; |
| @@ -13,6 +13,7 @@ import Moon from "~/components/Icons/Moon"; | |||
| 13 | import Trash from "~/components/Icons/Trash"; | 13 | import Trash from "~/components/Icons/Trash"; |
| 14 | import { DarkModeContext } from "~/contexts/DarkMode"; | 14 | import { DarkModeContext } from "~/contexts/DarkMode"; |
| 15 | import RequestList from "~/components/RequestList/RequestList"; | 15 | import RequestList from "~/components/RequestList/RequestList"; |
| 16 | import { ReadyState, RequestResponse } from "~/types"; | ||
| 16 | 17 | ||
| 17 | interface Config { | 18 | interface Config { |
| 18 | url: string; | 19 | url: string; |
diff --git a/src/components/RequestDetails/RequestDetails.tsx b/src/components/RequestDetails/RequestDetails.tsx index f34ef6f..9000220 100644 --- a/src/components/RequestDetails/RequestDetails.tsx +++ b/src/components/RequestDetails/RequestDetails.tsx | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | import * as React from "react"; | 1 | import * as React from "react"; |
| 2 | import { useCallback, useMemo, useState } from "react"; | 2 | import { useCallback, useMemo, useState } from "react"; |
| 3 | import { Headers, RequestResponse } from "~/hooks/useRequests"; | ||
| 4 | import styles from "~/components/RequestDetails/RequestDetails.module.scss"; | 3 | import styles from "~/components/RequestDetails/RequestDetails.module.scss"; |
| 5 | import RequestSummary from "~/components/RequestSummary/RequestSummary"; | 4 | import RequestSummary from "~/components/RequestSummary/RequestSummary"; |
| 6 | import Content from "~/components/Content/Content"; | 5 | import Content from "~/components/Content/Content"; |
| 7 | import { getHost } from "~/utils"; | 6 | import { getHost } from "~/utils"; |
| 8 | import { Button, Card, Col, Container, Nav, Row, Table } from "react-bootstrap"; | 7 | import { Button, Card, Col, Container, Nav, Row, Table } from "react-bootstrap"; |
| 8 | import { Headers, RequestResponse } from "~/types"; | ||
| 9 | 9 | ||
| 10 | interface TimingProps { | 10 | interface TimingProps { |
| 11 | timing: number; | 11 | timing: number; |
diff --git a/src/components/RequestList/RequestList.tsx b/src/components/RequestList/RequestList.tsx index acef47a..a4e9a0e 100644 --- a/src/components/RequestList/RequestList.tsx +++ b/src/components/RequestList/RequestList.tsx | |||
| @@ -12,9 +12,9 @@ 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, useMemo, useState } from "react"; | 14 | import { useCallback, useContext, useMemo, useState } from "react"; |
| 15 | import { Method, RequestResponse } from "~/hooks/useRequests"; | ||
| 16 | import { DarkModeContext } from "~/contexts/DarkMode"; | 15 | import { DarkModeContext } from "~/contexts/DarkMode"; |
| 17 | import Filter from "~/components/Icons/Filter"; | 16 | import Filter from "~/components/Icons/Filter"; |
| 17 | import { Method, RequestResponse } from "~/types"; | ||
| 18 | 18 | ||
| 19 | interface ListProps { | 19 | interface ListProps { |
| 20 | requests: RequestResponse[]; | 20 | requests: RequestResponse[]; |
diff --git a/src/hooks/useRequests.tsx b/src/hooks/useRequests.tsx index 1361949..dfc3b80 100644 --- a/src/hooks/useRequests.tsx +++ b/src/hooks/useRequests.tsx | |||
| @@ -1,61 +1,15 @@ | |||
| 1 | import { useCallback, useEffect, useMemo, useState } from "react"; | 1 | import { useCallback, useEffect, useMemo, useState } from "react"; |
| 2 | import { getHost } from "~/utils"; | 2 | import { getHost } from "~/utils"; |
| 3 | 3 | import { | |
| 4 | export type Headers = [string, string][]; | 4 | Historic, |
| 5 | export type Method = | 5 | ReadyState, |
| 6 | | "GET" | 6 | Request, |
| 7 | | "HEAD" | 7 | RequestPayload, |
| 8 | | "POST" | 8 | RequestResponse, |
| 9 | | "PUT" | 9 | Response, |
| 10 | | "DELETE" | 10 | ResponsePayload, |
| 11 | | "CONNECT" | 11 | WebsocketType, |
| 12 | | "OPTIONS" | 12 | } from "~/types"; |
| 13 | | "TRACE" | ||
| 14 | | "PATCH"; | ||
| 15 | |||
| 16 | export interface RequestPayload { | ||
| 17 | id: string; | ||
| 18 | timestamp: string; | ||
| 19 | body: string; | ||
| 20 | headers: Headers; | ||
| 21 | method: Method; | ||
| 22 | path: string; | ||
| 23 | } | ||
| 24 | |||
| 25 | interface Request { | ||
| 26 | type: "request"; | ||
| 27 | payload: RequestPayload; | ||
| 28 | } | ||
| 29 | |||
| 30 | export interface ResponsePayload { | ||
| 31 | id: string; | ||
| 32 | timing: number; | ||
| 33 | body: string; | ||
| 34 | headers: Headers; | ||
| 35 | status: number; | ||
| 36 | } | ||
| 37 | |||
| 38 | interface Response { | ||
| 39 | type: "response"; | ||
| 40 | payload: ResponsePayload; | ||
| 41 | } | ||
| 42 | |||
| 43 | interface Historic { | ||
| 44 | type: "historic"; | ||
| 45 | payload: (Request | Response)[]; | ||
| 46 | } | ||
| 47 | |||
| 48 | export interface RequestResponse { | ||
| 49 | request: RequestPayload; | ||
| 50 | response?: ResponsePayload; | ||
| 51 | } | ||
| 52 | |||
| 53 | export enum ReadyState { | ||
| 54 | CONNECTING = 0, | ||
| 55 | OPEN = 1, | ||
| 56 | CLOSING = 2, | ||
| 57 | CLOSED = 3, | ||
| 58 | } | ||
| 59 | 13 | ||
| 60 | export interface useRequestsProps { | 14 | export interface useRequestsProps { |
| 61 | onConnect: () => Promise<void>; | 15 | onConnect: () => Promise<void>; |
| @@ -75,6 +29,8 @@ export default function useRequests({ | |||
| 75 | const [initialConnection, setInitialConnection] = useState(true); | 29 | const [initialConnection, setInitialConnection] = useState(true); |
| 76 | const [requests, setRequests] = useState<RequestPayload[]>([]); | 30 | const [requests, setRequests] = useState<RequestPayload[]>([]); |
| 77 | const [responses, setResponses] = useState<ResponsePayload[]>([]); | 31 | const [responses, setResponses] = useState<ResponsePayload[]>([]); |
| 32 | const [websocketFrames, setWebsocketFrames] = | ||
| 33 | useState<WebsocketType["payload"]>(); | ||
| 78 | 34 | ||
| 79 | const connect = useCallback( | 35 | const connect = useCallback( |
| 80 | () => new WebSocket(`ws://${wsHost}/inspect/`), | 36 | () => new WebSocket(`ws://${wsHost}/inspect/`), |
| @@ -102,6 +58,8 @@ export default function useRequests({ | |||
| 102 | | Request | 58 | | Request |
| 103 | | Response; | 59 | | Response; |
| 104 | 60 | ||
| 61 | console.debug(type, payload); | ||
| 62 | |||
| 105 | switch (type) { | 63 | switch (type) { |
| 106 | case "historic": | 64 | case "historic": |
| 107 | if (initialConnection) { | 65 | if (initialConnection) { |
diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..84b95e3 --- /dev/null +++ b/src/types.ts | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | export type Headers = [string, string][]; | ||
| 2 | export type Method = | ||
| 3 | | "GET" | ||
| 4 | | "HEAD" | ||
| 5 | | "POST" | ||
| 6 | | "PUT" | ||
| 7 | | "DELETE" | ||
| 8 | | "CONNECT" | ||
| 9 | | "OPTIONS" | ||
| 10 | | "TRACE" | ||
| 11 | | "PATCH"; | ||
| 12 | |||
| 13 | export interface RequestPayload { | ||
| 14 | id: string; | ||
| 15 | timestamp: string; | ||
| 16 | body: string; | ||
| 17 | headers: Headers; | ||
| 18 | method: Method; | ||
| 19 | path: string; | ||
| 20 | } | ||
| 21 | |||
| 22 | export interface Request { | ||
| 23 | type: "request"; | ||
| 24 | payload: RequestPayload; | ||
| 25 | } | ||
| 26 | |||
| 27 | export interface ResponsePayload { | ||
| 28 | id: string; | ||
| 29 | timing: number; | ||
| 30 | body: string; | ||
| 31 | headers: Headers; | ||
| 32 | status: number; | ||
| 33 | } | ||
| 34 | |||
| 35 | export interface Response { | ||
| 36 | type: "response"; | ||
| 37 | payload: ResponsePayload; | ||
| 38 | } | ||
| 39 | |||
| 40 | type RequestResponseType = Request | Response; | ||
| 41 | |||
| 42 | interface WebsocketConnectPayload { | ||
| 43 | id: string; | ||
| 44 | headers: Headers; | ||
| 45 | path: string; | ||
| 46 | timestamp: string; | ||
| 47 | } | ||
| 48 | |||
| 49 | interface WebsocketConnect { | ||
| 50 | type: "websocket_connect"; | ||
| 51 | payload: WebsocketConnectPayload; | ||
| 52 | } | ||
| 53 | |||
| 54 | interface WebsocketConnectedPayload { | ||
| 55 | id: string; | ||
| 56 | timing: number; | ||
| 57 | } | ||
| 58 | |||
| 59 | interface WebsocketConnected { | ||
| 60 | type: "websocket_connected"; | ||
| 61 | payload: WebsocketConnectedPayload; | ||
| 62 | } | ||
| 63 | |||
| 64 | interface WebsocketInboundPayload { | ||
| 65 | id: string; | ||
| 66 | timestamp: string; | ||
| 67 | body: string; | ||
| 68 | } | ||
| 69 | |||
| 70 | interface WebsocketInbound { | ||
| 71 | type: "websocket_inbound"; | ||
| 72 | payload: WebsocketInboundPayload; | ||
| 73 | } | ||
| 74 | |||
| 75 | interface WebsocketOutboundPayload { | ||
| 76 | id: string; | ||
| 77 | timestamp: string; | ||
| 78 | body: string; | ||
| 79 | } | ||
| 80 | |||
| 81 | interface WebsocketOutbound { | ||
| 82 | type: "websocket_outbound"; | ||
| 83 | payload: WebsocketOutboundPayload; | ||
| 84 | } | ||
| 85 | |||
| 86 | interface WebsocketDisconnectPayload { | ||
| 87 | id: string; | ||
| 88 | timestamp: string; | ||
