summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/components/RequestList/RequestList.tsx47
-rw-r--r--src/hooks/useRequests.tsx11
-rw-r--r--tsconfig.json3
3 files changed, 33 insertions, 28 deletions
diff --git a/src/components/RequestList/RequestList.tsx b/src/components/RequestList/RequestList.tsx
index 6980738..a925c3b 100644
--- a/src/components/RequestList/RequestList.tsx
+++ b/src/components/RequestList/RequestList.tsx
@@ -38,23 +38,31 @@ export default function RequestList({
38 38
39 const [methods, setMethods] = useState<EnabledMethods>({ 39 const [methods, setMethods] = useState<EnabledMethods>({
40 GET: true, 40 GET: true,
41 HEAD: true,
41 POST: true, 42 POST: true,
42 PUT: true, 43 PUT: true,
43 PATCH: true,
44 DELETE: true, 44 DELETE: true,
45 CONNECT: true,
46 OPTIONS: true,
47 TRACE: true,
48 PATCH: true,
45 }); 49 });
46 50
47 const toggleMethods = useCallback((method: Method | null) => { 51 const toggleMethods = useCallback((method: Method | null) => {
48 const enabled = method == null; 52 const enabled = method == null;
49 const methods = { 53 const methods: EnabledMethods = {
50 GET: enabled, 54 GET: enabled,
55 HEAD: enabled,
51 POST: enabled, 56 POST: enabled,
52 PUT: enabled, 57 PUT: enabled,
53 PATCH: enabled,
54 DELETE: enabled, 58 DELETE: enabled,
59 CONNECT: enabled,
60 OPTIONS: enabled,
61 TRACE: enabled,
62 PATCH: enabled,
55 }; 63 };
56 64
57 if (!enabled) { 65 if (method !== null) {
58 methods[method] = true; 66 methods[method] = true;
59 } 67 }
60 68
@@ -72,7 +80,7 @@ export default function RequestList({
72 const methodLabel = useMemo(() => { 80 const methodLabel = useMemo(() => {
73 if (enabledMethods.length == 1) { 81 if (enabledMethods.length == 1) {
74 return enabledMethods[0]; 82 return enabledMethods[0];
75 } else if (enabledMethods.length === 5) { 83 } else if (enabledMethods.length === Object.keys(methods).length) {
76 return "ANY"; 84 return "ANY";
77 } else { 85 } else {
78 return "CUSTOM"; 86 return "CUSTOM";
@@ -88,12 +96,9 @@ export default function RequestList({
88 ); 96 );
89 } catch {} 97 } catch {}
90 98
91 return ( 99 return requests
92 requests.map((request, index) => [index, request]).reverse() as [ 100 .map<[number, RequestResponse]>((request, index) => [index, request])
93 number, 101 .reverse()
94 RequestResponse
95 ][]
96 )
97 .filter( 102 .filter(
98 ([index, request]) => 103 ([index, request]) =>
99 enabledMethods.length > 0 === null || 104 enabledMethods.length > 0 === null ||
@@ -119,21 +124,11 @@ export default function RequestList({
119 ANY 124 ANY
120 </Dropdown.Item> 125 </Dropdown.Item>
121 <Dropdown.Divider /> 126 <Dropdown.Divider />
122 <Dropdown.Item onClick={() => toggleMethods("GET")}> 127 {Object.entries(methods).map(([method, enabled]) => (
123 GET 128 <Dropdown.Item onClick={() => toggleMethods(method as Method)}>
124 </Dropdown.Item> 129 {method}
125 <Dropdown.Item onClick={() => toggleMethods("POST")}> 130 </Dropdown.Item>
126 POST 131 ))}
127 </Dropdown.Item>
128 <Dropdown.Item onClick={() => toggleMethods("PUT")}>
129 PUT
130 </Dropdown.Item>
131 <Dropdown.Item onClick={() => toggleMethods("PATCH")}>
132 PATCH
133 </Dropdown.Item>
134 <Dropdown.Item onClick={() => toggleMethods("DELETE")}>
135 DELETE
136 </Dropdown.Item>
137 </DropdownButton> 132 </DropdownButton>
138 <Form.Control 133 <Form.Control
139 type="text" 134 type="text"
diff --git a/src/hooks/useRequests.tsx b/src/hooks/useRequests.tsx
index 108232f..526e0a6 100644
--- a/src/hooks/useRequests.tsx
+++ b/src/hooks/useRequests.tsx
@@ -2,7 +2,16 @@ import { useCallback, useEffect, useMemo, useState } from "react";
2import { getHost } from "../utils"; 2import { getHost } from "../utils";
3 3
4export type Headers = [string, string][]; 4export type Headers = [string, string][];
5export type Method = "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; 5export type Method =
6 | "GET"
7 | "HEAD"
8 | "POST"
9 | "PUT"
10 | "DELETE"
11 | "CONNECT"
12 | "OPTIONS"
13 | "TRACE"
14 | "PATCH";
6 15
7export interface RequestPayload { 16export interface RequestPayload {
8 id: string; 17 id: string;
diff --git a/tsconfig.json b/tsconfig.json
index a8bbe91..9956ef7 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -7,7 +7,8 @@
7 "~*": ["./*"] 7 "~*": ["./*"]
8 }, 8 },
9 "strict": true, 9 "strict": true,
10 "target": "ES2015" 10 "target": "ES2015",
11 "lib": ["es2015", "dom" ,"esnext"],
11 }, 12 },
12 "include": ["src/**/*"] 13 "include": ["src/**/*"]
13} 14}