Add key command to directly access App Configuration

This commit is contained in:
Sam Becker 2025-03-01 21:45:42 -06:00
parent 5acc6948c0
commit 27ab85404d
2 changed files with 36 additions and 2 deletions

View File

@ -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,
}, {

View 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;
}