Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: keyboard shortcut component #26658

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ function FullScreen(): JSX.Element {
<LemonButton
size="xsmall"
onClick={() => setIsFullScreen(!isFullScreen)}
tooltip={`${!isFullScreen ? 'Go' : 'Exit'} full screen (F)`}
tooltip={
<>
{!isFullScreen ? 'Go' : 'Exit'} full screen <KeyboardShortcut f />
</>
}
>
<IconFullScreen className={clsx('text-2xl', isFullScreen ? 'text-link' : 'text-primary-alt')} />
</LemonButton>
Expand Down Expand Up @@ -194,7 +198,11 @@ function Maximise(): JSX.Element {
<LemonButton
size="xsmall"
onClick={onChangeMaximise}
tooltip={`${isMaximised ? 'Open' : 'Close'} other panels (M)`}
tooltip={
<>
{isMaximised ? 'Open' : 'Close'} other panels <KeyboardShortcut m />
</>
}
icon={isMaximised ? <IconCollapse45 className="text-lg" /> : <IconExpand45 className="text-lg" />}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { capitalizeFirstLetter, colonDelimitedDuration } from 'lib/utils'
import { SimpleTimeLabel } from 'scenes/session-recordings/components/SimpleTimeLabel'
import { ONE_FRAME_MS, sessionRecordingPlayerLogic } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'

import { KeyboardShortcut } from '~/layout/navigation-3000/components/KeyboardShortcut'
import { HotKeyOrModifier } from '~/types'

import { playerSettingsLogic, TimestampFormat } from '../playerSettingsLogic'
import { seekbarLogic } from './seekbarLogic'

Expand Down Expand Up @@ -44,10 +47,14 @@ export function SeekSkip({ direction }: { direction: 'forward' | 'backward' }):

const altKeyHeld = useKeyHeld('Alt')
const jumpTimeSeconds = altKeyHeld ? 1 : jumpTimeMs / 1000
const altKeyName = navigator.platform.includes('Mac') ? '⌥' : 'Alt'

const arrowSymbol = direction === 'forward' ? '→' : '←'
const arrowName = direction === 'forward' ? 'right' : 'left'
const arrowKey: Partial<Record<HotKeyOrModifier, true>> = {}
if (direction === 'forward') {
arrowKey.arrowright = true
}
if (direction === 'backward') {
arrowKey.arrowleft = true
}
Comment on lines +51 to +57
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see the react-scan thingy flashing in horror in front of my eyes, lol. I suggest using useMemo :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be ideal if we could simply say something like arrowRight={direction === 'forward'} in the KeyboardShortcut component, but we'd need to tweak the inner implementation to achieve that


return (
<Tooltip
Expand All @@ -56,18 +63,12 @@ export function SeekSkip({ direction }: { direction: 'forward' | 'backward' }):
<div className="text-center">
{!altKeyHeld ? (
<>
{capitalizeFirstLetter(direction)} {jumpTimeSeconds}s (
<kbd>
{arrowSymbol} {arrowName} arrow
</kbd>
) <br />
{capitalizeFirstLetter(direction)} {jumpTimeSeconds}s <KeyboardShortcut {...arrowKey} />
<br />
</>
) : null}
{capitalizeFirstLetter(direction)} 1 frame ({ONE_FRAME_MS}ms) (
<kbd>
{altKeyName} + {arrowSymbol}
</kbd>
)
{capitalizeFirstLetter(direction)} 1 frame ({ONE_FRAME_MS}ms){' '}
<KeyboardShortcut option {...arrowKey} />
</div>
}
>
Expand Down
Loading