mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 01:28:35 +02:00
Hotkey labels
This commit is contained in:
@@ -121,22 +121,8 @@ export const RequestResponse = memo(function RequestResponse({ style }: Props) {
|
|||||||
[width, height, vertical, setHeight, setWidth],
|
[width, height, vertical, setHeight, setWidth],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (activeRequest === null && requests.length > 0) {
|
if (activeRequest === null) {
|
||||||
return (
|
return <HotKeyList hotkeys={['request.create', 'sidebar.toggle']} />;
|
||||||
<div className="h-full flex items-center justify-center opacity-disabled">
|
|
||||||
<p>No Selected Request</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
} else if (requests.length === 0) {
|
|
||||||
return (
|
|
||||||
<HotKeyList
|
|
||||||
hotkeys={[
|
|
||||||
{ action: 'request.create', label: 'New Request' },
|
|
||||||
{ action: 'sidebar.toggle', label: 'Toggle Sidebar' },
|
|
||||||
{ action: 'urlBar.focus', label: 'Focus URL' },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -104,12 +104,7 @@ export const ResponsePane = memo(function ResponsePane({ style, className }: Pro
|
|||||||
<>
|
<>
|
||||||
<span />
|
<span />
|
||||||
<HotKeyList
|
<HotKeyList
|
||||||
hotkeys={[
|
hotkeys={['request.send', 'request.create', 'sidebar.toggle', 'urlBar.focus']}
|
||||||
{ action: 'request.send', label: 'Send Request' },
|
|
||||||
{ action: 'request.create', label: 'New Request' },
|
|
||||||
{ action: 'sidebar.toggle', label: 'Toggle Sidebar' },
|
|
||||||
{ action: 'urlBar.focus', label: 'Focus URL' },
|
|
||||||
]}
|
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
11
src-web/components/core/HotKeyLabel.tsx
Normal file
11
src-web/components/core/HotKeyLabel.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import type { HotkeyAction } from '../../hooks/useHotkey';
|
||||||
|
import { useHotKeyLabel } from '../../hooks/useHotkey';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
action: HotkeyAction | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function HotKeyLabel({ action }: Props) {
|
||||||
|
const label = useHotKeyLabel(action);
|
||||||
|
return <span>{label}</span>;
|
||||||
|
}
|
||||||
@@ -1,21 +1,20 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import type { HotkeyAction } from '../../hooks/useHotkey';
|
import type { HotkeyAction } from '../../hooks/useHotkey';
|
||||||
import { HotKey } from './HotKey';
|
import { HotKey } from './HotKey';
|
||||||
|
import { HotKeyLabel } from './HotKeyLabel';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
hotkeys: { action: HotkeyAction; label: string }[];
|
hotkeys: HotkeyAction[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const HotKeyList = ({ hotkeys }: Props) => {
|
export const HotKeyList = ({ hotkeys }: Props) => {
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto h-full flex items-center text-gray-800 text-sm">
|
<div className="mx-auto h-full flex items-center text-gray-700 text-sm">
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
{hotkeys.map((hotkey) => (
|
{hotkeys.map((hotkey) => (
|
||||||
<div key={hotkey.action} className="grid grid-cols-2">
|
<div key={hotkey} className="grid grid-cols-2">
|
||||||
<p>{hotkey.label}</p>
|
<HotKeyLabel action={hotkey} />
|
||||||
<div className="ml-auto">
|
<HotKey className="ml-auto" action={hotkey} />
|
||||||
<HotKey action={hotkey.action} />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -90,7 +90,28 @@ export function useAnyHotkey(
|
|||||||
window.removeEventListener('keydown', down);
|
window.removeEventListener('keydown', down);
|
||||||
window.removeEventListener('keyup', up);
|
window.removeEventListener('keyup', up);
|
||||||
};
|
};
|
||||||
}, [os]);
|
}, [options.enable, os]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useHotKeyLabel(action: HotkeyAction | null): string {
|
||||||
|
switch (action) {
|
||||||
|
case 'request.send':
|
||||||
|
return 'Send Request';
|
||||||
|
case 'request.create':
|
||||||
|
return 'New Request';
|
||||||
|
case 'request.duplicate':
|
||||||
|
return 'Duplicate Request';
|
||||||
|
case 'sidebar.toggle':
|
||||||
|
return 'Toggle Sidebar';
|
||||||
|
case 'sidebar.focus':
|
||||||
|
return 'Focus Sidebar';
|
||||||
|
case 'urlBar.focus':
|
||||||
|
return 'Focus URL';
|
||||||
|
case 'environmentEditor.toggle':
|
||||||
|
return 'Edit Environments';
|
||||||
|
default:
|
||||||
|
return 'Unknown';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useFormattedHotkey(action: HotkeyAction | null): string | null {
|
export function useFormattedHotkey(action: HotkeyAction | null): string | null {
|
||||||
|
|||||||
Reference in New Issue
Block a user