Change more menu link/action handling

This commit is contained in:
Sam Becker 2024-07-16 11:17:31 -05:00
parent 7c267caa0a
commit e9ead7cc9b

View File

@ -42,20 +42,21 @@ export default function MoreMenuItem({
? 'cursor-not-allowed opacity-50'
: 'cursor-pointer',
)}
onClick={e => {
onClick={async e => {
if (shouldPreventDefault) { e.preventDefault(); }
if (action) {
const result = action();
if (result instanceof Promise) {
setIsLoading(true);
await result.finally(() => setIsLoading(false));
}
}
if (href && href !== pathname) {
if (Boolean(hrefDownloadName)) {
window.open(href, '_blank');
} else {
startTransition(() => router.push(href));
}
} else {
const result = action?.();
if (result instanceof Promise) {
setIsLoading(true);
result.finally(() => setIsLoading(false));
}
}
}}
>