Fix admin photo menu glitches
This commit is contained in:
parent
1fca04320c
commit
90f736ee6a
@ -15,10 +15,12 @@ export default function MoreMenu({
|
||||
items,
|
||||
className,
|
||||
buttonClassName,
|
||||
ariaLabel,
|
||||
}: {
|
||||
items: MoreMenuItem[]
|
||||
className?: string
|
||||
buttonClassName?: string
|
||||
ariaLabel: string
|
||||
}){
|
||||
return (
|
||||
<DropdownMenu.Root>
|
||||
@ -31,7 +33,7 @@ export default function MoreMenu({
|
||||
'hover:dark:bg-gray-800/75 active:dark:bg-gray-900',
|
||||
'text-dim',
|
||||
)}
|
||||
aria-label={`Choose an action for photo: ${'photo'}`}
|
||||
aria-label={ariaLabel}
|
||||
>
|
||||
<FiMoreHorizontal size={18} />
|
||||
</button>
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
|
||||
import * as DropdownMenu from '@radix-ui/react-dropdown-menu';
|
||||
import { clsx } from 'clsx/lite';
|
||||
import { ReactNode, useState } from 'react';
|
||||
import { ReactNode, useState, useTransition } from 'react';
|
||||
import LoaderButton from '../primitives/LoaderButton';
|
||||
import PathLoaderButton from '../primitives/PathLoaderButton';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function MoreMenuItem({
|
||||
label,
|
||||
@ -17,6 +17,10 @@ export default function MoreMenuItem({
|
||||
href?: string
|
||||
action?: () => Promise<void> | void
|
||||
}) {
|
||||
const router = useRouter();
|
||||
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
return (
|
||||
@ -32,36 +36,28 @@ export default function MoreMenuItem({
|
||||
? 'cursor-not-allowed opacity-50'
|
||||
: 'cursor-pointer',
|
||||
)}
|
||||
onClick={e => {
|
||||
e.preventDefault();
|
||||
if (href) {
|
||||
startTransition(() => router.push(href));
|
||||
} else {
|
||||
const result = action?.();
|
||||
if (result instanceof Promise) {
|
||||
setIsLoading(true);
|
||||
result.finally(() => setIsLoading(false));
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
{href &&
|
||||
<PathLoaderButton
|
||||
path={href}
|
||||
icon={icon}
|
||||
hideTextOnMobile={false}
|
||||
shouldPreventDefault
|
||||
styleAs="link-without-hover"
|
||||
>
|
||||
{label}
|
||||
</PathLoaderButton>}
|
||||
{action &&
|
||||
<LoaderButton
|
||||
icon={icon}
|
||||
isLoading={isLoading}
|
||||
hideTextOnMobile={false}
|
||||
styleAs="link-without-hover"
|
||||
onClick={e => {
|
||||
if (!href) {
|
||||
const result = action?.();
|
||||
if (result instanceof Promise) {
|
||||
e.preventDefault();
|
||||
setIsLoading(true);
|
||||
result.finally(() => setIsLoading(false));
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
{label}
|
||||
</LoaderButton>}
|
||||
<LoaderButton
|
||||
icon={icon}
|
||||
isLoading={isLoading || isPending}
|
||||
hideTextOnMobile={false}
|
||||
styleAs="link-without-hover"
|
||||
className="translate-y-[1px]"
|
||||
>
|
||||
{label}
|
||||
</LoaderButton>
|
||||
</DropdownMenu.Item>
|
||||
);
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import {
|
||||
doesPhotoNeedBlurCompatibility,
|
||||
shouldShowCameraDataForPhoto,
|
||||
shouldShowExifDataForPhoto,
|
||||
titleForPhoto,
|
||||
} from '.';
|
||||
import SiteGrid from '@/components/SiteGrid';
|
||||
import ImageLarge from '@/components/image/ImageLarge';
|
||||
@ -133,6 +134,7 @@ export default function PhotoLarge({
|
||||
photo,
|
||||
revalidatePhoto,
|
||||
includeFavorite: includeFavoriteInAdminMenu,
|
||||
ariaLabel: `Admin menu for '${titleForPhoto(photo)}' photo`,
|
||||
}} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user