From 8b0823984b0fd08ee178852ea6dc79c797409ab5 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Thu, 1 Feb 2024 00:36:49 -0800 Subject: [PATCH] Even better styles --- src-web/components/GrpcConnectionLayout.tsx | 36 +++++++++------- src-web/components/ResponsePane.tsx | 4 +- src-web/components/UrlBar.tsx | 24 ++++++----- src-web/components/core/JsonAttributeTree.tsx | 41 ++++++++++++------- src-web/hooks/useGrpc.ts | 15 ++----- 5 files changed, 67 insertions(+), 53 deletions(-) diff --git a/src-web/components/GrpcConnectionLayout.tsx b/src-web/components/GrpcConnectionLayout.tsx index a6e9118b..b8db8d63 100644 --- a/src-web/components/GrpcConnectionLayout.tsx +++ b/src-web/components/GrpcConnectionLayout.tsx @@ -1,17 +1,16 @@ import classNames from 'classnames'; import { format } from 'date-fns'; -import { m } from 'framer-motion'; import type { CSSProperties, FormEvent } from 'react'; import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { useAlert } from '../hooks/useAlert'; import type { GrpcMessage } from '../hooks/useGrpc'; import { useGrpc } from '../hooks/useGrpc'; import { useKeyValue } from '../hooks/useKeyValue'; -import { tryFormatJson } from '../lib/formatters'; import { Banner } from './core/Banner'; import { Editor } from './core/Editor'; import { HotKeyList } from './core/HotKeyList'; import { Icon } from './core/Icon'; +import { IconButton } from './core/IconButton'; import { JsonAttributeTree } from './core/JsonAttributeTree'; import { Select } from './core/Select'; import { Separator } from './core/Separator'; @@ -144,12 +143,30 @@ export function GrpcConnectionLayout({ style }: Props) { id="foo" url={url.value ?? ''} method={null} + submitIcon={null} forceUpdateKey="to-do" placeholder="localhost:50051" onSubmit={handleConnect} isLoading={grpc.unary.isLoading} onUrlChange={url.set} - submitIcon={ + /> + -
+
-
+
) : contentType?.match(/csv|tab-separated/) ? ( + ) : contentType?.startsWith('application/json') ? ( + ) : ( - // ) : contentType?.startsWith('application/json') ? ( - // )} diff --git a/src-web/components/UrlBar.tsx b/src-web/components/UrlBar.tsx index d1ef61a3..1f6b6a9b 100644 --- a/src-web/components/UrlBar.tsx +++ b/src-web/components/UrlBar.tsx @@ -14,7 +14,7 @@ type Props = Pick & { placeholder: string; onSubmit: (e: FormEvent) => void; onUrlChange: (url: string) => void; - submitIcon?: IconProps['icon']; + submitIcon?: IconProps['icon'] | null; onMethodChange?: (method: string) => void; isLoading: boolean; forceUpdateKey: string; @@ -74,16 +74,18 @@ export const UrlBar = memo(function UrlBar({ ) } rightSlot={ - + submitIcon !== null && ( + + ) } /> diff --git a/src-web/components/core/JsonAttributeTree.tsx b/src-web/components/core/JsonAttributeTree.tsx index 6d173b8a..4edeed4f 100644 --- a/src-web/components/core/JsonAttributeTree.tsx +++ b/src-web/components/core/JsonAttributeTree.tsx @@ -38,8 +38,8 @@ export const JsonAttributeTree = ({ depth = 0, attrKey, attrValue, attrKeyJsonPa )) : null, isExpandable: true, - label: isExpanded ? undefined : `{⋯}`, - labelClassName: 'text-gray-500', + label: isExpanded ? '{ }' : `{⋯}`, + labelClassName: 'text-gray-600', }; } else if (jsonType === '[object Array]') { return { @@ -54,8 +54,8 @@ export const JsonAttributeTree = ({ depth = 0, attrKey, attrValue, attrKeyJsonPa )) : null, isExpandable: true, - label: isExpanded ? undefined : `[⋯]`, - labelClassName: 'text-gray-500', + label: isExpanded ? '[ ]' : `[⋯]`, + labelClassName: 'text-gray-600', }; } else { return { @@ -72,25 +72,38 @@ export const JsonAttributeTree = ({ depth = 0, attrKey, attrValue, attrKeyJsonPa } }, [attrValue, attrKeyJsonPath, isExpanded, depth]); + const labelEl = ( + + {label} + + ); return ( -
+
- {depth === 0 ? null : isExpandable ? ( - ) : ( - {attrKey}: + <> + + {attrKey}: + + {labelEl} + )} - {label}
{children &&
{children}
}
diff --git a/src-web/hooks/useGrpc.ts b/src-web/hooks/useGrpc.ts index 14567b07..6890a55f 100644 --- a/src-web/hooks/useGrpc.ts +++ b/src-web/hooks/useGrpc.ts @@ -19,20 +19,8 @@ export function useGrpc(url: string | null) { useListenToTauriEvent( 'grpc_message', (event) => { - console.log('GOT MESSAGE', event); setMessages((prev) => [ ...prev, - { - message: JSON.stringify({ - dummy: 'Yo, this is a dummy message', - another: 'property', - list: [1, 2, 3, 4, 5], - null: null, - bool: true, - }), - time: new Date(), - isServer: false, - }, { message: event.payload, time: new Date(), isServer: true }, ]); }, @@ -59,6 +47,9 @@ export function useGrpc(url: string | null) { mutationKey: ['grpc_server_streaming', url], mutationFn: async ({ service, method, message }) => { if (url === null) throw new Error('No URL provided'); + setMessages([ + { isServer: false, message: JSON.stringify(JSON.parse(message)), time: new Date() }, + ]); return (await invoke('grpc_server_streaming', { endpoint: url, service,