import { useEffect, useState } from 'react' import { useHotkeys } from 'react-hotkeys-hook' import { ChevronDown, ChevronUp } from 'lucide-react' import { usePhotoStore } from '../store/photoStore' import { useFilterStore } from '../store/filterStore' const STORAGE_KEY = 'keyboard-hints-collapsed' interface Hint { key: string action: string } /** Build the hint list for the current context. Returns an empty array * when no shortcuts apply, which lets the caller hide the panel * entirely instead of rendering an empty pill. */ function getHints(opts: { selectedCount: number currentSection: string viewMode: string }): Hint[] { const { selectedCount, currentSection, viewMode } = opts // Preview mode: culling shortcuts apply to the photo on screen, plus // arrow nav between photos and Esc to close. if (viewMode === 'preview') { const preview: Hint[] = [ { key: '←→', action: 'Navigate' }, { key: '1-5', action: 'Rate' }, { key: 'S', action: 'Select → heap' }, ] if (currentSection === 'discarded') { preview.push({ key: 'U', action: 'Restore' }) } else { preview.push({ key: 'X', action: 'Discard' }) } preview.push( { key: 'I', action: 'Info panel' }, { key: 'Space', action: 'Close' }, { key: 'Esc', action: 'Close' } ) return preview } if (selectedCount > 0) { const base: Hint[] = [ { key: '1-5', action: 'Rate' }, { key: 'S', action: 'Select → heap' }, ] if (currentSection === 'discarded') { base.push({ key: 'U', action: 'Restore' }) } else { base.push({ key: 'X', action: 'Discard' }) } base.push( { key: 'Space', action: 'Preview' }, { key: 'I', action: 'Info panel' }, { key: 'Esc', action: 'Deselect' } ) return base } return [ { key: '↑↓←→', action: 'Navigate' }, { key: 'Space', action: 'Preview' }, { key: 'Tab', action: 'Library panel' }, { key: 'I', action: 'Info panel' }, ] } export function KeyboardHints() { const selectedCount = usePhotoStore((s) => s.selectedPhotos.length) const viewMode = usePhotoStore((s) => s.viewMode) const currentSection = useFilterStore((s) => s.currentSection) const [collapsed, setCollapsed] = useState( () => typeof window !== 'undefined' && localStorage.getItem(STORAGE_KEY) === '1' ) useEffect(() => { localStorage.setItem(STORAGE_KEY, collapsed ? '1' : '0') }, [collapsed]) // `H` toggles the panel. useHotkeys('h', () => setCollapsed((c) => !c), { preventDefault: true }) const hints = getHints({ selectedCount, currentSection, viewMode }) // Nothing relevant to show — hide entirely. if (hints.length === 0) return null return (