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