Skip to content

Commit 01c5d57

Browse files
committed
feat: add dark theme and ui improvments and request tabs
1 parent c1f16c4 commit 01c5d57

File tree

6 files changed

+144
-102
lines changed

6 files changed

+144
-102
lines changed

app.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ func NewApp() *App {
2525
// so we can call the runtime methods
2626
func (a *App) startup(ctx context.Context) {
2727
tr := &http.Transport{
28-
MaxIdleConns: 2,
29-
IdleConnTimeout: 5 * time.Second,
28+
MaxIdleConns: 10,
29+
IdleConnTimeout: 50 * time.Second,
3030
}
3131
a.client = &http.Client{
32-
Timeout: 5 * time.Second,
32+
Timeout: 50 * time.Second,
3333
Transport: tr,
3434
}
3535
a.ctx = ctx

export.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"log"
66
"os"
7+
"os/user"
78

89
"github.com/wailsapp/wails/v2/pkg/runtime"
910
)
@@ -23,6 +24,10 @@ func (a *App) Export(r RequestResult) error {
2324
log.Println(err)
2425
return err
2526
}
27+
28+
user, _ := user.Current()
29+
log.Println("writing file as user", user.Username)
30+
2631
f, err := os.Create(filepath)
2732
if err != nil {
2833
log.Println(err)

frontend/src/App.css

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,18 @@
1-
.App {
2-
width: 100%;
3-
padding: 0.5em !important;
4-
}
5-
6-
.headersp {
7-
padding-left: 1em !important;
8-
padding: 1em !important;
9-
}
10-
11-
.headers {
12-
margin-right: 1em !important;
13-
padding-right: 1em !important;
14-
text-align: left;
15-
height: auto;
16-
color: var(--mui-palette-primary-dark);
17-
overflow-x: hidden;
18-
overflow-y: auto;
1+
body {
2+
line-height: 1 !important;
3+
letter-spacing: normal !important;
4+
width: 100vw;
195
}
206

21-
.resultp {
22-
padding: 1em !important;
7+
.__json-pretty__ {
8+
padding-top: 0;
9+
margin-top: 0;
2310
}
2411

25-
.result {
26-
text-align: left;
27-
line-height: 0.7em;
12+
.headers label {
13+
font-weight: 600;
2814
font-size: 1em;
29-
color: var(--mui-palette-success-dark);
30-
margin-right: 1em !important;
31-
overflow-y: auto;
32-
}
33-
34-
.url {
35-
width:100%;
36-
margin: 5px !important;
37-
}
38-
39-
.make-request {
40-
width:100%;
41-
margin-left: 1em !important;
42-
}
43-
44-
#req-button-p {
45-
width: 70%;
46-
margin: 0px auto;
47-
}
48-
49-
.req-header-div,.body-div,.header-div {
50-
margin-top: 1em !important;
51-
font-weight: 1000;
52-
}
53-
54-
55-
.res-div {
56-
margin-top: 1em !important;
57-
font-weight: 1000;
15+
color: var(--mui-palette-primary-dark);
5816
}
5917

6018
.req-body {

frontend/src/App.tsx

Lines changed: 110 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,30 @@ import './App.css';
33
import {MakeRequest, RunCurl, Export} from "../wailsjs/go/main/App";
44
import {main} from "../wailsjs/go/models";
55
import Button from '@mui/material/Button';
6+
import ButtonGroup from '@mui/material/ButtonGroup';
67
import TextField from '@mui/material/TextField';
78
import Divider from '@mui/material/Divider';
89
import Grid from '@mui/material/Unstable_Grid2'; // Grid version 2
910
import MenuItem from '@mui/material/MenuItem';
1011
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';
1115
import Select from '@mui/material/Select';
1216
import Box from '@mui/material/Box';
1317
import Typography from '@mui/material/Typography';
1418
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';
1522
import { ThemeProvider, createTheme } from '@mui/material/styles';
1623
import {
1724
Experimental_CssVarsProvider as CssVarsProvider,
1825
} from '@mui/material/styles';
1926
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';
2030

2131
const darkTheme = createTheme({
2232
palette: {
@@ -41,12 +51,14 @@ class Request {
4151

4252

4353
function App() {
54+
const [value, setValue] = useState('one');
55+
const [reqBodies, setReqBodies] = useState([""])
56+
const [activeReqBody, setActiveReqBody] = useState(0)
4457
const [request, setRequest] = useState(new Request({"Method": "GET"}))
4558
const [result, setResult] = useState(new main.RequestResult)
4659
const [curlBody, setCurlBody] = useState("");
4760
const [open, setOpen] = useState(false);
4861

49-
5062
const handleRequestChange = (e: any) => {
5163
const { name, value } = e.target;
5264
setRequest(prevState => ({
@@ -63,6 +75,20 @@ function App() {
6375
}));
6476
};
6577

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+
6692
const handleOpen = () => setOpen(true);
6793
const handleClose = () => setOpen(false);
6894
const style = {
@@ -77,8 +103,7 @@ function App() {
77103

78104
const updateCurlBody = (e:any) => setCurlBody(e.target.value)
79105
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);
82107
}
83108

84109
function importCurl() {
@@ -98,9 +123,16 @@ function App() {
98123
function handleExport() {
99124
Export(result)
100125
}
126+
127+
const darkTheme = createTheme({
128+
palette: {
129+
mode: 'dark',
130+
},
131+
});
132+
101133
return (
102-
<CssVarsProvider>
103-
<CssBaseline />
134+
<ThemeProvider theme={darkTheme}>
135+
<CssBaseline />
104136
<Modal
105137
open={open}
106138
onClose={handleClose}
@@ -120,54 +152,87 @@ function App() {
120152
</Typography>
121153
</Box>
122154
</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
140169
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>
141181
</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"/>
151210
</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"/>
156214
</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>
160217
</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>
164225
</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>
168232
</Grid>
169233
</Grid>
170-
</CssVarsProvider>
234+
</Box>
235+
</ThemeProvider>
171236
)
172237
}
173238

package-lock.json

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"@emotion/styled": "^11.11.0",
55
"@fontsource/roboto": "^5.0.3",
66
"@mui/icons-material": "^5.11.16",
7-
"@mui/material": "^5.13.5"
7+
"@mui/material": "^5.13.5",
8+
"react-json-pretty": "^2.2.0"
89
}
910
}

0 commit comments

Comments
 (0)