Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide dropdown when no valid recent requests exist #141

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src-web/components/RecentRequestsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ export function RecentRequestsDropdown({ className }: Pick<ButtonProps, 'classNa
const [activeCookieJar] = useActiveCookieJar();
const routes = useAppRoutes();
const allRecentRequestIds = useRecentRequests();
const recentRequestIds = useMemo(() => allRecentRequestIds.slice(1), [allRecentRequestIds]);
const requests = useRequests();

type ExtendedDropdownItem = DropdownItem & { key: string };

// Handle key-up
useKeyPressEvent('Control', undefined, () => {
if (!dropdownRef.current?.isOpen) return;
Expand All @@ -43,11 +44,11 @@ export function RecentRequestsDropdown({ className }: Pick<ButtonProps, 'classNa
dropdownRef.current?.prev?.();
});

const items = useMemo<DropdownItem[]>(() => {
const items = useMemo<ExtendedDropdownItem[]>(() => {
if (activeWorkspace === null) return [];

const recentRequestItems: DropdownItem[] = [];
for (const id of recentRequestIds) {
const recentRequestItems: ExtendedDropdownItem[] = [];
for (const id of allRecentRequestIds) {
const request = requests.find((r) => r.id === id);
if (request === undefined) continue;

Expand Down Expand Up @@ -79,9 +80,12 @@ export function RecentRequestsDropdown({ className }: Pick<ButtonProps, 'classNa
}

return recentRequestItems.slice(0, 20);
}, [activeWorkspace, recentRequestIds, requests, routes, activeEnvironment?.id, activeCookieJar?.id]);
}, [activeWorkspace, allRecentRequestIds, requests, routes, activeEnvironment?.id, activeCookieJar?.id]);

// Only show dropdown if there are valid recent requests
const hasRecentRequests = items.length > 0 && items[0]?.key !== 'no-recent-requests';
peimn marked this conversation as resolved.
Show resolved Hide resolved

return (
return hasRecentRequests ? (
<Dropdown ref={dropdownRef} items={items}>
<Button
data-tauri-drag-region
Expand All @@ -96,5 +100,5 @@ export function RecentRequestsDropdown({ className }: Pick<ButtonProps, 'classNa
{fallbackRequestName(activeRequest)}
</Button>
</Dropdown>
);
) : null;
}