Add key command to directly access App Configuration
This commit is contained in:
parent
5acc6948c0
commit
27ab85404d
@ -22,6 +22,7 @@ import { signOutAction } from '@/auth/actions';
|
||||
import { ComponentProps } from 'react';
|
||||
import { FaRegFolderOpen } from 'react-icons/fa';
|
||||
import { FiUploadCloud } from 'react-icons/fi';
|
||||
import useIsKeyBeingPressed from '@/utility/useIsKeyBeingPressed';
|
||||
|
||||
export default function AdminAppMenu({
|
||||
active,
|
||||
@ -45,6 +46,10 @@ export default function AdminAppMenu({
|
||||
|
||||
const isSelecting = selectedPhotoIds !== undefined;
|
||||
|
||||
const isAltPressed = useIsKeyBeingPressed('alt');
|
||||
|
||||
const showAppInsightsLink = photosCountTotal > 0 && !isAltPressed;
|
||||
|
||||
const items: ComponentProps<typeof MoreMenu>['items'] = [{
|
||||
label: 'Upload Photos',
|
||||
icon: <FiUploadCloud
|
||||
@ -95,14 +100,14 @@ export default function AdminAppMenu({
|
||||
}
|
||||
|
||||
items.push({
|
||||
label: photosCountTotal > 0
|
||||
label: showAppInsightsLink
|
||||
? 'App Insights'
|
||||
: 'App Configuration',
|
||||
icon: <AdminAppInfoIcon
|
||||
size="small"
|
||||
className="translate-x-[-0.5px] translate-y-[-0.5px]"
|
||||
/>,
|
||||
href: photosCountTotal > 0
|
||||
href: showAppInsightsLink
|
||||
? PATH_ADMIN_INSIGHTS
|
||||
: PATH_ADMIN_CONFIGURATION,
|
||||
}, {
|
||||
|
||||
29
src/utility/useIsKeyBeingPressed.ts
Normal file
29
src/utility/useIsKeyBeingPressed.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
const LISTENER_KEYDOWN = 'keydown';
|
||||
const LISTENER_KEYUP = 'keyup';
|
||||
|
||||
export default function useIsKeyBeingPressed(key: string) {
|
||||
const [isPressed, setIsPressed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key.toLowerCase() === key.toLowerCase()) {
|
||||
setIsPressed(true);
|
||||
}
|
||||
};
|
||||
const handleKeyUp = (e: KeyboardEvent) => {
|
||||
if (e.key.toLowerCase() === key.toLowerCase()) {
|
||||
setIsPressed(false);
|
||||
}
|
||||
};
|
||||
window.addEventListener(LISTENER_KEYDOWN, handleKeyDown);
|
||||
window.addEventListener(LISTENER_KEYUP, handleKeyUp);
|
||||
return () => {
|
||||
window.removeEventListener(LISTENER_KEYDOWN, handleKeyDown);
|
||||
window.removeEventListener(LISTENER_KEYUP, handleKeyUp);
|
||||
};
|
||||
}, [key]);
|
||||
|
||||
return isPressed;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user