From 2285fe9f1c205fcceec6abd2aeae35bfff943390 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sun, 9 Apr 2023 15:32:13 -0700 Subject: [PATCH] Small tweaks --- src-web/components/RecentRequestsDropdown.tsx | 33 ++----------------- src-web/components/core/Dropdown.tsx | 2 ++ src-web/hooks/useRecentRequests.ts | 2 +- 3 files changed, 6 insertions(+), 31 deletions(-) diff --git a/src-web/components/RecentRequestsDropdown.tsx b/src-web/components/RecentRequestsDropdown.tsx index 1c581722..b0544d4d 100644 --- a/src-web/components/RecentRequestsDropdown.tsx +++ b/src-web/components/RecentRequestsDropdown.tsx @@ -3,8 +3,6 @@ import { useKeyPressEvent } from 'react-use'; import { useActiveRequest } from '../hooks/useActiveRequest'; import { useActiveWorkspaceId } from '../hooks/useActiveWorkspaceId'; import { useAppRoutes } from '../hooks/useAppRoutes'; -import { useDeleteRequest } from '../hooks/useDeleteRequest'; -import { useDuplicateRequest } from '../hooks/useDuplicateRequest'; import { useRecentRequests } from '../hooks/useRecentRequests'; import { useRequests } from '../hooks/useRequests'; import { Button } from './core/Button'; @@ -24,7 +22,7 @@ export function RecentRequestsDropdown() { if (!e.ctrlKey) return; if (!dropdownRef.current?.isOpen) { // Set to 1 because the first item is the active request - dropdownRef.current?.open(e.shiftKey ? -1 : 1); + dropdownRef.current?.open(e.shiftKey ? -1 : 0); } if (e.shiftKey) { @@ -39,11 +37,6 @@ export function RecentRequestsDropdown() { const recentRequestIds = useRecentRequests(); const requests = useRequests(); const routes = useAppRoutes(); - const deleteRequest = useDeleteRequest(activeRequest?.id ?? null); - const duplicateRequest = useDuplicateRequest({ - id: activeRequest?.id ?? null, - navigateAfter: true, - }); const items = useMemo(() => { if (activeWorkspaceId === null) return []; @@ -65,32 +58,12 @@ export function RecentRequestsDropdown() { }); } - // Show max 30 items - const fixedItems: DropdownItem[] = [ - // { - // label: 'Duplicate', - // onSelect: duplicateRequest.mutate, - // leftSlot: , - // rightSlot: , - // }, - // { - // label: 'Delete', - // onSelect: deleteRequest.mutate, - // variant: 'danger', - // leftSlot: , - // }, - ]; - // No recent requests to show if (recentRequestItems.length === 0) { - return fixedItems; + return []; } - return [ - // ...fixedItems, - // { type: 'separator', label: 'Recent Requests' }, - ...recentRequestItems.slice(0, 20), - ]; + return recentRequestItems.slice(0, 20); }, [activeWorkspaceId, recentRequestIds, requests, routes]); return ( diff --git a/src-web/components/core/Dropdown.tsx b/src-web/components/core/Dropdown.tsx index 5490ea86..cd6790d1 100644 --- a/src-web/components/core/Dropdown.tsx +++ b/src-web/components/core/Dropdown.tsx @@ -257,6 +257,8 @@ const Menu = forwardRef, MenuProps>(functio [items], ); + if (items.length === 0) return null; + return ( diff --git a/src-web/hooks/useRecentRequests.ts b/src-web/hooks/useRecentRequests.ts index c130b87c..8c84aa3c 100644 --- a/src-web/hooks/useRecentRequests.ts +++ b/src-web/hooks/useRecentRequests.ts @@ -27,5 +27,5 @@ export function useRecentRequests() { }); }, [activeRequestId, setHistory]); - return history; + return history.slice(1); }