import { useState } from 'react'; import { invoke } from '@tauri-apps/api/tauri'; import Editor from './components/Editor/Editor'; import { HStack, VStack } from './components/Stacks'; import { Dropdown } from './components/Dropdown'; import { WindowDragRegion } from './components/WindowDragRegion'; import { IconButton } from './components/IconButton'; import { Sidebar } from './components/Sidebar'; import { UrlBar } from './components/UrlBar'; import { Grid } from './components/Grid'; interface Response { url: string; method: string; body: string; status: string; elapsed: number; elapsed2: number; headers: Record; } function App() { const [error, setError] = useState(null); const [response, setResponse] = useState(null); const [url, setUrl] = useState('https://go-server.schier.dev/debug'); const [method, setMethod] = useState<{ label: string; value: string }>({ label: 'GET', value: 'GET', }); async function sendRequest() { setError(null); try { const resp = (await invoke('send_request', { method: method.value, url })) as Response; if (resp.body.includes('')) { resp.body = resp.body.replace(//gi, ``); } setResponse(resp); console.log('Response', resp.status, resp.url, { resp }); } catch (err) { setError(`${err}`); } } const contentType = response?.headers['content-type']?.split(';')[0] ?? 'text/plain'; return ( <>
setResponse(null), disabled: !response, }, { label: 'Other Thing', }, ]} > {error &&
{error}
} {response !== null && ( <> {response.status}  •  {response.elapsed}ms  •  {response.elapsed2}ms {contentType.includes('html') ? (