@@ -3,20 +3,30 @@ import './App.css';
3
3
import { MakeRequest , RunCurl , Export } from "../wailsjs/go/main/App" ;
4
4
import { main } from "../wailsjs/go/models" ;
5
5
import Button from '@mui/material/Button' ;
6
+ import ButtonGroup from '@mui/material/ButtonGroup' ;
6
7
import TextField from '@mui/material/TextField' ;
7
8
import Divider from '@mui/material/Divider' ;
8
9
import Grid from '@mui/material/Unstable_Grid2' ; // Grid version 2
9
10
import MenuItem from '@mui/material/MenuItem' ;
10
11
import Modal from '@mui/material/Modal' ;
12
+ import InputLabel from '@mui/material/InputLabel' ;
13
+ import FormLabel from '@mui/material/FormLabel' ;
14
+ import FormControl from '@mui/material/FormControl' ;
11
15
import Select from '@mui/material/Select' ;
12
16
import Box from '@mui/material/Box' ;
13
17
import Typography from '@mui/material/Typography' ;
14
18
import SaveIcon from '@mui/icons-material/Save' ;
19
+ import AddIcon from '@mui/icons-material/Add' ;
20
+ import Tabs from '@mui/material/Tabs' ;
21
+ import Tab from '@mui/material/Tab' ;
15
22
import { ThemeProvider , createTheme } from '@mui/material/styles' ;
16
23
import {
17
24
Experimental_CssVarsProvider as CssVarsProvider ,
18
25
} from '@mui/material/styles' ;
19
26
import CssBaseline from '@mui/material/CssBaseline' ;
27
+ import { Margin } from '@mui/icons-material' ;
28
+ import JSONPretty from 'react-json-pretty' ;
29
+ import 'react-json-pretty/themes/monikai.css' ;
20
30
21
31
const darkTheme = createTheme ( {
22
32
palette : {
@@ -41,12 +51,14 @@ class Request {
41
51
42
52
43
53
function App ( ) {
54
+ const [ value , setValue ] = useState ( 'one' ) ;
55
+ const [ reqBodies , setReqBodies ] = useState ( [ "" ] )
56
+ const [ activeReqBody , setActiveReqBody ] = useState ( 0 )
44
57
const [ request , setRequest ] = useState ( new Request ( { "Method" : "GET" } ) )
45
58
const [ result , setResult ] = useState ( new main . RequestResult )
46
59
const [ curlBody , setCurlBody ] = useState ( "" ) ;
47
60
const [ open , setOpen ] = useState ( false ) ;
48
61
49
-
50
62
const handleRequestChange = ( e : any ) => {
51
63
const { name, value } = e . target ;
52
64
setRequest ( prevState => ( {
@@ -63,6 +75,20 @@ function App() {
63
75
} ) ) ;
64
76
} ;
65
77
78
+ const updateActiveReqTab = ( e :any ) => {
79
+ setActiveReqBody ( e . target . value )
80
+ }
81
+
82
+ const addReqBody = ( e :any ) => {
83
+ reqBodies . push ( "{}" )
84
+ setReqBodies ( [ ...reqBodies ] )
85
+ }
86
+
87
+ const updateReqBody = ( e : any ) => {
88
+ reqBodies [ activeReqBody ] = e . target . value
89
+ setReqBodies ( [ ...reqBodies ] )
90
+ }
91
+
66
92
const handleOpen = ( ) => setOpen ( true ) ;
67
93
const handleClose = ( ) => setOpen ( false ) ;
68
94
const style = {
@@ -77,8 +103,7 @@ function App() {
77
103
78
104
const updateCurlBody = ( e :any ) => setCurlBody ( e . target . value )
79
105
function makeRequest ( ) {
80
- console . log ( request )
81
- MakeRequest ( request . URL , request . Method , request . Body , request . Headers ) . then ( setResult ) ;
106
+ MakeRequest ( request . URL , request . Method , reqBodies [ activeReqBody ] , request . Headers ) . then ( setResult ) ;
82
107
}
83
108
84
109
function importCurl ( ) {
@@ -98,9 +123,16 @@ function App() {
98
123
function handleExport ( ) {
99
124
Export ( result )
100
125
}
126
+
127
+ const darkTheme = createTheme ( {
128
+ palette : {
129
+ mode : 'dark' ,
130
+ } ,
131
+ } ) ;
132
+
101
133
return (
102
- < CssVarsProvider >
103
- < CssBaseline />
134
+ < ThemeProvider theme = { darkTheme } >
135
+ < CssBaseline />
104
136
< Modal
105
137
open = { open }
106
138
onClose = { handleClose }
@@ -120,54 +152,87 @@ function App() {
120
152
</ Typography >
121
153
</ Box >
122
154
</ Modal >
123
- < Grid container className = "App" >
124
- < Grid xs = { 1 } >
125
- < Button onClick = { handleExport } variant = "outlined" > < SaveIcon > </ SaveIcon > </ Button >
126
- </ Grid >
127
- < Grid xs = { 1 } >
128
- < Button onClick = { handleOpen } variant = "outlined" > Curl</ Button >
129
- </ Grid >
130
- < Grid xs = { 1 } >
131
- < Select label = "Type" value = { request . Method } color = "success" name = "Method"
132
- variant = "standard" onChange = { handleRequestChange } >
133
- < MenuItem value = { "GET" } > GET</ MenuItem >
134
- < MenuItem value = { "POST" } > POST</ MenuItem >
135
- < MenuItem value = { "PUT" } > PUT</ MenuItem >
136
- </ Select >
137
- </ Grid >
138
- < Grid xs = { 8 } >
139
- < TextField id = "url" className = "url" variant = "standard" value = { request . URL }
155
+ < Box >
156
+ < Grid container spacing = { 1 } sx = { { m :0 } } >
157
+ < Grid xs = { 12 } sx = { { marginTop : "1em" } } >
158
+ < FormControl sx = { { minWidth : "5%" , verticalAlign :"bottom" } } size = "small" variant = 'standard' >
159
+ < Select label = "Method" value = { request . Method }
160
+ color = "success" name = "Method"
161
+ onChange = { handleRequestChange } autoWidth size = "small" >
162
+ < MenuItem value = { "GET" } > GET</ MenuItem >
163
+ < MenuItem value = { "POST" } > POST</ MenuItem >
164
+ < MenuItem value = { "PUT" } > PUT</ MenuItem >
165
+ </ Select >
166
+ </ FormControl >
167
+ < FormControl sx = { { width : "70%" , verticalAlign :"bottom" } } size = "small" >
168
+ < TextField id = "url" variant = "standard" value = { request . URL } size = "small" fullWidth
140
169
onChange = { handleRequestChange } autoComplete = "off" name = "URL" />
170
+ </ FormControl >
171
+ < FormControl sx = { { minWidth : "5%" , verticalAlign :"bottom" } } size = "small" >
172
+ < Button className = "make-request" variant = "contained" onClick = { makeRequest } size = "small" > Go</ Button >
173
+ </ FormControl >
174
+ < span style = { { margin : "0.5rem" } } > </ span >
175
+ < FormControl sx = { { minWidth : "5%" , verticalAlign :"bottom" , flexFlow :"right" } } >
176
+ < ButtonGroup size = "small" >
177
+ < Button onClick = { handleExport } variant = "outlined" > < SaveIcon > </ SaveIcon > </ Button >
178
+ < Button onClick = { handleOpen } variant = "contained" color = "secondary" > Import Curl</ Button >
179
+ </ ButtonGroup >
180
+ </ FormControl >
141
181
</ Grid >
142
- < Grid xs = { 1 } >
143
- < div id = "req-button-p" >
144
- < Button className = "make-request" color = "primary" variant = "contained" onClick = { makeRequest } > Go</ Button >
145
- </ div >
146
- </ Grid >
147
- < Grid xs = { 4 } className = "req-headers-p" >
148
- < Divider textAlign = "left" className = "req-header-div" color = "success" > < span > Request Headers</ span > </ Divider >
149
- < TextField id = "reqheaders" multiline className = "req-headers" variant = "filled" rows = { 10 } color = "success"
150
- value = { request . Headers } onChange = { handleResultChange } autoComplete = "off" name = "Headers" />
182
+ </ Grid >
183
+ < Grid container spacing = { 1 } className = "headers" sx = { { marginTop : 0.5 } } >
184
+ < Grid xs = { 3 } >
185
+ < FormLabel > Request Header</ FormLabel >
186
+ </ Grid >
187
+ < Grid xs = { 4 } >
188
+ < FormLabel > Request Body</ FormLabel >
189
+ < ButtonGroup sx = { { margin : "0 5px" } } >
190
+ {
191
+ reqBodies . map ( ( d , index ) => < Button
192
+ key = { index } style = { { padding : "0em" , minWidth : "2rem" } }
193
+ variant = "contained" value = { index } color = "success" onClick = { updateActiveReqTab }
194
+ > { index + 1 } </ Button > )
195
+ }
196
+ < Button color = "success" sx = { { minWidth : "2rem" , padding : "0em" } } onClick = { addReqBody } > < AddIcon /> </ Button >
197
+ </ ButtonGroup >
198
+ </ Grid >
199
+ < Grid xs = { 5 } >
200
+ < FormLabel >
201
+ Response
202
+ </ FormLabel >
203
+ </ Grid >
204
+ </ Grid >
205
+ < Grid container spacing = { 1 } sx = { { marginTop : 0.5 } } >
206
+ < Grid xs = { 3 } >
207
+ < TextField multiline variant = "filled" rows = { 15 } color = "success" sx = { { width :"100%" } }
208
+ value = { request . Headers } onChange = { handleRequestChange }
209
+ autoComplete = "off" name = "Headers" />
151
210
</ Grid >
152
- < Grid xs = { 8 } className = "req-body-p" >
153
- < Divider textAlign = "left" className = "body-div" color = "primary" > < span > Request Body</ span > </ Divider >
154
- < TextField id = "url" multiline className = "req-body" variant = "filled" rows = { 10 } color = "primary"
155
- onChange = { handleResultChange } value = { result . RequestBody } autoComplete = "off" name = "RequestBody" />
211
+ < Grid xs = { 4 } >
212
+ < TextField sx = { { width : "100%" } } multiline variant = "filled" rows = { 15 } color = "primary"
213
+ onChange = { updateReqBody } value = { reqBodies [ activeReqBody ] } autoComplete = "off" name = "RequestBody" />
156
214
</ Grid >
157
- < Grid xs = { 4 } className = "headersp" >
158
- < Divider textAlign = "left" className = "header-div" > < span color = '#82aaff' > Headers</ span > </ Divider >
159
- < div id = "headers" className = "headers" > < pre > { result . HeadersStr } </ pre > </ div >
215
+ < Grid xs = { 5 } sx = { { overflowY : "auto" } } >
216
+ < JSONPretty data = { result . Body } > </ JSONPretty >
160
217
</ Grid >
161
- < Grid xs = { 8 } className = "resultp" >
162
- < Divider textAlign = "left" className = "res-div" > < span color = '#c3e88d' > Response</ span > </ Divider >
163
- < div id = "result" className = "result" > < pre > { result . Body } </ pre > </ div >
218
+ </ Grid >
219
+ < Grid container spacing = { 1 } className = "headers" >
220
+ < Grid xs = { 3 } >
221
+ < FormLabel >
222
+ Response Header
223
+ </ FormLabel >
224
+ < JSONPretty data = { result . HeadersStr } > </ JSONPretty >
164
225
</ Grid >
165
- < Grid xs = { 12 } className = "errorp" >
166
- < Divider textAlign = "left" className = "error-div" color = "error" > Error</ Divider >
167
- < div id = "error" className = "error" > < pre > { result . Error } </ pre > </ div >
226
+
227
+ < Grid xs = { 4 } >
228
+ < FormLabel >
229
+ Error
230
+ </ FormLabel >
231
+ < JSONPretty data = { result . Error } > </ JSONPretty >
168
232
</ Grid >
169
233
</ Grid >
170
- </ CssVarsProvider >
234
+ </ Box >
235
+ </ ThemeProvider >
171
236
)
172
237
}
173
238
0 commit comments