Add command palette (#46)

This PR finished the initial PoC command palette. It currently only
supports switching between requests and workspaces, but can easily be
extended for more.
This commit is contained in:
Gregory Schier
2024-06-07 21:59:57 -07:00
committed by GitHub
parent 5e058af03e
commit b0e4ece278
7 changed files with 175 additions and 79 deletions

View File

@@ -1,21 +1,15 @@
import { CommandPalette } from '../components/CommandPalette';
import { useDialog } from '../components/DialogContext';
import { useAppInfo } from './useAppInfo';
import { useHotKey } from './useHotKey';
export function useCommandPalette() {
const dialog = useDialog();
const appInfo = useAppInfo();
useHotKey('command_palette.toggle', () => {
// Disabled in production for now
if (!appInfo?.isDev) {
return;
}
dialog.toggle({
id: 'command_palette',
size: 'md',
size: 'dynamic',
hideX: true,
vAlign: 'top',
noPadding: true,
noScroll: true,
render: ({ hide }) => <CommandPalette onClose={hide} />,

View File

@@ -4,10 +4,8 @@ import type { Workspace } from '../lib/models';
import { useAppRoutes } from './useAppRoutes';
import { getRecentEnvironments } from './useRecentEnvironments';
import { getRecentRequests } from './useRecentRequests';
import { useSettings } from './useSettings';
export function useOpenWorkspace() {
const settings = useSettings();
const routes = useAppRoutes();
return useMutation({
@@ -18,7 +16,7 @@ export function useOpenWorkspace() {
workspace: Workspace;
inNewWindow: boolean;
}) => {
if (settings == null || workspace == null) return;
if (workspace == null) return;
if (inNewWindow) {
const environmentId = (await getRecentEnvironments(workspace.id))[0];