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 all commits
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
33 changes: 18 additions & 15 deletions src-web/components/RecentRequestsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export function RecentRequestsDropdown({ className }: Pick<ButtonProps, 'classNa
const activeRequest = useActiveRequest();
const activeWorkspace = useActiveWorkspace();
const allRecentRequestIds = useRecentRequests();
const recentRequestIds = useMemo(() => allRecentRequestIds.slice(1), [allRecentRequestIds]);
const requests = useRequests();
const navigate = useNavigate();

Expand All @@ -39,13 +38,14 @@ export function RecentRequestsDropdown({ className }: Pick<ButtonProps, 'classNa
dropdownRef.current?.prev?.();
});

const items = useMemo<DropdownItem[]>(() => {
if (activeWorkspace === null) return [];
const { items, hasRecentRequests } = useMemo(() => {
if (activeWorkspace === null) return { items: [], hasRecentRequests: false };

const recentRequestItems: DropdownItem[] = [];
for (const id of recentRequestIds) {

for (const id of allRecentRequestIds) {
const request = requests.find((r) => r.id === id);
if (request === undefined) continue;
if (!request) continue;

recentRequestItems.push({
key: request.id,
Expand All @@ -67,19 +67,22 @@ export function RecentRequestsDropdown({ className }: Pick<ButtonProps, 'classNa

// No recent requests to show
if (recentRequestItems.length === 0) {
return [
{
key: 'no-recent-requests',
label: 'No recent requests',
disabled: true,
},
];
return {
items: [
{
key: 'no-recent-requests',
label: 'No recent requests',
disabled: true,
},
],
hasRecentRequests: false,
};
}

return recentRequestItems.slice(0, 20);
return { items: recentRequestItems.slice(0, 20), hasRecentRequests: true };
}, [activeWorkspace, navigate, recentRequestIds, requests]);

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