Fix bundle parts

This commit is contained in:
Gregory Schier
2023-03-29 14:00:34 -07:00
parent ab15782019
commit 06ce7abfb9
5 changed files with 65 additions and 32 deletions

View File

@@ -1,10 +1,10 @@
import { appWindow } from '@tauri-apps/api/window';
import classnames from 'classnames';
import type { CSSProperties } from 'react';
import { memo, useCallback, useMemo, useState } from 'react';
import { useActiveRequest } from '../hooks/useActiveRequest';
import { useKeyValue } from '../hooks/useKeyValue';
import { useUpdateRequest } from '../hooks/useUpdateRequest';
import { useWindowFocus } from '../hooks/useWindowFocus';
import { tryFormatJson } from '../lib/formatters';
import type { HttpHeader, HttpRequest } from '../lib/models';
import {
@@ -125,12 +125,13 @@ export const RequestPane = memo(function RequestPane({ style, fullHeight, classN
[],
);
const forceUpdateKey = useMemo(() => {
if (activeRequest == null) return undefined;
if (activeRequest.updatedBy === appWindow.label) return appWindow.label;
return `${appWindow.label}::${activeRequest?.updatedAt}`;
}, [activeRequest]);
console.log('FORCE UPDATE KEY', forceUpdateKey);
const visible = useWindowFocus();
const multiWindowKey = useMemo(() => {
// If the window has focus, don't ever force an update
if (visible) return undefined;
// If the window is not focused, force an update if the request has been updated
return activeRequest?.updatedAt;
}, [visible, activeRequest?.updatedAt]);
return (
<div
@@ -140,7 +141,7 @@ export const RequestPane = memo(function RequestPane({ style, fullHeight, classN
{activeRequest && (
<>
<UrlBar
key={forceUpdateKey}
key={multiWindowKey}
id={activeRequest.id}
url={activeRequest.url}
method={activeRequest.method}
@@ -155,13 +156,13 @@ export const RequestPane = memo(function RequestPane({ style, fullHeight, classN
<TabContent value="auth">
{activeRequest.authenticationType === AUTH_TYPE_BASIC ? (
<BasicAuth
key={forceUpdateKey}
key={multiWindowKey}
requestId={activeRequest.id}
authentication={activeRequest.authentication}
/>
) : activeRequest.authenticationType === AUTH_TYPE_BEARER ? (
<BearerAuth
key={forceUpdateKey}
key={multiWindowKey}
requestId={activeRequest.id}
authentication={activeRequest.authentication}
/>
@@ -173,18 +174,18 @@ export const RequestPane = memo(function RequestPane({ style, fullHeight, classN
</TabContent>
<TabContent value="headers">
<HeaderEditor
key={`${forceUpdateHeaderEditorKey}::${forceUpdateKey}`}
key={`${forceUpdateHeaderEditorKey}::${multiWindowKey}`}
headers={activeRequest.headers}
onChange={handleHeadersChange}
/>
</TabContent>
<TabContent value="params">
<ParametersEditor key={forceUpdateKey} parameters={[]} onChange={() => null} />
<ParametersEditor key={multiWindowKey} parameters={[]} onChange={() => null} />
</TabContent>
<TabContent value="body" className="pl-3 mt-1">
{activeRequest.bodyType === BODY_TYPE_JSON ? (
<Editor
key={forceUpdateKey}
key={multiWindowKey}
useTemplating
placeholder="..."
className="!bg-gray-50"
@@ -196,7 +197,7 @@ export const RequestPane = memo(function RequestPane({ style, fullHeight, classN
/>
) : activeRequest.bodyType === BODY_TYPE_XML ? (
<Editor
key={forceUpdateKey}
key={multiWindowKey}
useTemplating
placeholder="..."
className="!bg-gray-50"
@@ -207,7 +208,7 @@ export const RequestPane = memo(function RequestPane({ style, fullHeight, classN
/>
) : activeRequest.bodyType === BODY_TYPE_GRAPHQL ? (
<GraphQLEditor
key={forceUpdateKey}
key={multiWindowKey}
baseRequest={activeRequest}
className="!bg-gray-50"
defaultValue={activeRequest?.body ?? ''}