:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { useEventListener } from 'lib/hooks/useEventListener'
import { isMac } from 'lib/utils/dom'
export type TodayArchiveShortcutEvent = Pick<
KeyboardEvent,
'key' | 'metaKey' | 'ctrlKey' | 'shiftKey' | 'altKey' | 'repeat' | 'target'
>
export function todayArchiveShortcutLabel(mac: boolean): string {
return mac ? '⌘⇧A' : 'Ctrl+Shift+A'
}
function isTextEntry(target: EventTarget | null): boolean {
return target instanceof HTMLElement && (target.isContentEditable || target.matches('input, textarea, select'))
}
export function isTodayArchiveShortcut(event: TodayArchiveShortcutEvent, mac: boolean): boolean {
const modifier = mac ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey
return (
modifier &&
event.shiftKey &&
!event.altKey &&
!event.repeat &&
event.key.toLowerCase() === 'a' &&
!isTextEntry(event.target)
)
}
export function useTodayArchiveShortcut(enabled: boolean, onArchive: () => void): void {
useEventListener('keydown', (event) => {
if (enabled && isTodayArchiveShortcut(event, isMac())) {
event.preventDefault()
onArchive()
}
})
}