From 1ecf64218122e589052000bdd0aee4406da9c99d Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sat, 4 Mar 2023 21:51:17 -0800 Subject: [PATCH] More work on the layout --- src-web/App.tsx | 34 +++++- src-web/components/Editor/Editor.css | 19 +-- src-web/components/Editor/Editor.tsx | 3 + src-web/components/LayoutPane.tsx | 12 +- src-web/components/RequestPane.tsx | 95 +++++++-------- src-web/components/ResponsePane.tsx | 171 +++++++++++++++------------ src-web/components/Stacks.tsx | 3 +- src-web/main.css | 2 + tailwind.config.cjs | 6 +- 9 files changed, 198 insertions(+), 147 deletions(-) diff --git a/src-web/App.tsx b/src-web/App.tsx index c463a17f..6f69c89c 100644 --- a/src-web/App.tsx +++ b/src-web/App.tsx @@ -1,6 +1,8 @@ import classnames from 'classnames'; import { useEffect, useState } from 'react'; import { useParams } from 'react-router-dom'; +import { Button } from './components/Button'; +import { Divider } from './components/Divider'; import { Grid } from './components/Grid'; import { RequestPane } from './components/RequestPane'; import { ResponsePane } from './components/ResponsePane'; @@ -34,10 +36,34 @@ function App() {
{request && ( - - - - +
+
+ + {request.name} + +
+ + +
+
+
)}
); diff --git a/src-web/components/Editor/Editor.css b/src-web/components/Editor/Editor.css index 03e0d573..018f301c 100644 --- a/src-web/components/Editor/Editor.css +++ b/src-web/components/Editor/Editor.css @@ -1,17 +1,18 @@ .cm-wrapper { - height: 100%; - width: 100%; - position: relative; -} + @apply h-full; -.cm-wrapper .cm-editor { - @apply inset-0; - position: absolute !important; - font-size: 0.85em; + &.cm-full-height { + @apply relative; + + .cm-editor { + @apply inset-0; + position: absolute !important; + } + } } .cm-editor { - @apply w-full block; + @apply w-full block text-[0.85rem]; &.cm-focused { outline: none !important; diff --git a/src-web/components/Editor/Editor.tsx b/src-web/components/Editor/Editor.tsx index 3babf33b..026c5839 100644 --- a/src-web/components/Editor/Editor.tsx +++ b/src-web/components/Editor/Editor.tsx @@ -11,6 +11,7 @@ import { baseExtensions, getLanguageExtension, multiLineExtensions } from './ext import { singleLineExt } from './singleLine'; export interface EditorProps extends Omit, 'onChange'> { + height?: 'auto' | 'full'; contentType?: string; autoFocus?: boolean; valueKey?: string | number; @@ -23,6 +24,7 @@ export interface EditorProps extends Omit, 'onCha } export default function Editor({ + height, contentType, autoFocus, placeholder, @@ -95,6 +97,7 @@ export default function Editor({ className={classnames( className, 'cm-wrapper text-base', + height === 'auto' ? 'cm-auto-height' : 'cm-full-height', singleLine ? 'cm-singleline' : 'cm-multiline', )} {...props} diff --git a/src-web/components/LayoutPane.tsx b/src-web/components/LayoutPane.tsx index 43b66119..cdf95333 100644 --- a/src-web/components/LayoutPane.tsx +++ b/src-web/components/LayoutPane.tsx @@ -1,4 +1,3 @@ -import classnames from 'classnames'; import type { ReactNode } from 'react'; export interface LayoutPaneProps { @@ -7,9 +6,10 @@ export interface LayoutPaneProps { } export function LayoutPane({ className, children }: LayoutPaneProps) { - return ( -
-
{children}
-
- ); + return
{children}
; + // return ( + //
+ //
{children}
+ //
+ // ); } diff --git a/src-web/components/RequestPane.tsx b/src-web/components/RequestPane.tsx index 2c1b9335..5f440c66 100644 --- a/src-web/components/RequestPane.tsx +++ b/src-web/components/RequestPane.tsx @@ -1,69 +1,64 @@ import classnames from 'classnames'; -import { useDeleteRequest, useRequestUpdate, useSendRequest } from '../hooks/useRequest'; +import { useRequestUpdate, useSendRequest } from '../hooks/useRequest'; import type { HttpRequest } from '../lib/models'; import { Button } from './Button'; import { Divider } from './Divider'; import Editor from './Editor/Editor'; -import type { LayoutPaneProps } from './LayoutPane'; -import { LayoutPane } from './LayoutPane'; import { ScrollArea } from './ScrollArea'; import { HStack } from './Stacks'; import { UrlBar } from './UrlBar'; -interface Props extends LayoutPaneProps { +interface Props { request: HttpRequest; + fullHeight: boolean; + className?: string; } -export function RequestPane({ request, ...props }: Props) { +export function RequestPane({ fullHeight, request, className }: Props) { const updateRequest = useRequestUpdate(request ?? null); const sendRequest = useSendRequest(request ?? null); return ( - -
- {/**/} - {/* Test Request*/} - {/* deleteRequest.mutate()} />*/} - {/**/} -
- updateRequest.mutate({ method })} - onUrlChange={(url) => updateRequest.mutate({ url })} - sendRequest={sendRequest.mutate} - /> -
- -
-
- {/**/} - - - {['JSON', 'Params', 'Headers', 'Auth', 'Docs'].map((label, i) => ( - - ))} - - -
- updateRequest.mutate({ body })} - /> +
+
+ updateRequest.mutate({ method })} + onUrlChange={(url) => updateRequest.mutate({ url })} + sendRequest={sendRequest.mutate} + /> +
+
- + {/**/} + + + {['JSON', 'Params', 'Headers', 'Auth', 'Docs'].map((label, i) => ( + + ))} + + +
+ updateRequest.mutate({ body })} + /> +
+
); } diff --git a/src-web/components/ResponsePane.tsx b/src-web/components/ResponsePane.tsx index ce49ac42..5679b785 100644 --- a/src-web/components/ResponsePane.tsx +++ b/src-web/components/ResponsePane.tsx @@ -1,20 +1,21 @@ import classnames from 'classnames'; import { useEffect, useMemo, useState } from 'react'; import { useDeleteAllResponses, useDeleteResponse, useResponses } from '../hooks/useResponses'; +import { Button } from './Button'; import { Divider } from './Divider'; import { Dropdown } from './Dropdown'; import Editor from './Editor/Editor'; import { Icon } from './Icon'; import { IconButton } from './IconButton'; -import type { LayoutPaneProps } from './LayoutPane'; -import { LayoutPane } from './LayoutPane'; +import { ScrollArea } from './ScrollArea'; import { HStack } from './Stacks'; -interface Props extends LayoutPaneProps { +interface Props { requestId: string; + className?: string; } -export function ResponsePane({ requestId, className, ...props }: Props) { +export function ResponsePane({ requestId, className }: Props) { const [activeResponseId, setActiveResponseId] = useState(null); const [viewMode, setViewMode] = useState<'pretty' | 'raw'>('pretty'); const responses = useResponses(requestId); @@ -44,81 +45,99 @@ export function ResponsePane({ requestId, className, ...props }: Props) { }, [response?.body, contentType]); return ( - -
- {/**/} - {/**/} - {response?.error && ( -
{response.error}
- )} - {response && ( - <> -
- -
- {response.status} - {response.statusReason && ` ${response.statusReason}`} -  •  - {response.elapsed}ms  •  - {Math.round(response.body.length / 1000)} KB -
+
+ {/**/} + {/**/} + {response?.error && ( +
{response.error}
+ )} + {response && ( + <> +
+ +
+ {response.status} + {response.statusReason && ` ${response.statusReason}`} +  •  + {response.elapsed}ms  •  + {Math.round(response.body.length / 1000)} KB +
- - {contentType.includes('html') && ( - setViewMode((m) => (m === 'pretty' ? 'raw' : 'pretty'))} - /> - )} - ({ - label: r.status + ' - ' + r.elapsed + ' ms', - leftSlot: response?.id === r.id ? : <>, - onSelect: () => setActiveResponseId(r.id), - })), - ]} - > - - - + + {contentType.includes('html') && ( + setViewMode((m) => (m === 'pretty' ? 'raw' : 'pretty'))} + /> + )} + ({ + label: r.status + ' - ' + r.elapsed + ' ms', + leftSlot: response?.id === r.id ? : <>, + onSelect: () => setActiveResponseId(r.id), + })), + ]} + > + + +
+
- {viewMode === 'pretty' && contentForIframe !== null ? ( -