phanpy/src/components/keyboard-shortcuts-help.jsx

197 lines
5.9 KiB
React
Raw Normal View History

2023-09-06 16:54:05 +02:00
import './keyboard-shortcuts-help.css';
2024-08-13 09:26:23 +02:00
import { t, Trans } from '@lingui/macro';
import { memo } from 'preact/compat';
import { useHotkeys } from 'react-hotkeys-hook';
2023-09-06 16:54:05 +02:00
import { useSnapshot } from 'valtio';
import states from '../utils/states';
import Icon from './icon';
import Modal from './modal';
export default memo(function KeyboardShortcutsHelp() {
2023-09-06 16:54:05 +02:00
const snapStates = useSnapshot(states);
function onClose() {
states.showKeyboardShortcutsHelp = false;
}
useHotkeys(
'?, shift+?, shift+slash',
2023-09-06 16:54:05 +02:00
(e) => {
console.log('help');
states.showKeyboardShortcutsHelp = true;
},
{
ignoreEventWhen: (e) => {
const hasModal = !!document.querySelector('#modal-container > *');
return hasModal;
},
},
);
return (
!!snapStates.showKeyboardShortcutsHelp && (
<Modal onClose={onClose}>
2023-12-20 13:59:59 +01:00
<div id="keyboard-shortcuts-help-container" class="sheet" tabindex="-1">
2023-09-06 16:54:05 +02:00
<button type="button" class="sheet-close" onClick={onClose}>
2024-08-13 09:26:23 +02:00
<Icon icon="x" alt={t`Close`} />
2023-09-06 16:54:05 +02:00
</button>
<header>
2024-08-13 09:26:23 +02:00
<h2>
<Trans>Keyboard shortcuts</Trans>
</h2>
2023-09-06 16:54:05 +02:00
</header>
<main>
<table>
2024-08-13 09:26:23 +02:00
<tbody>
{[
{
action: t`Keyboard shortcuts help`,
keys: <kbd>?</kbd>,
},
{
action: t`Next post`,
keys: <kbd>j</kbd>,
},
{
action: t`Previous post`,
keys: <kbd>k</kbd>,
},
{
action: t`Skip carousel to next post`,
keys: (
<Trans>
2024-08-13 09:26:23 +02:00
<kbd>Shift</kbd> + <kbd>j</kbd>
</Trans>
2024-08-13 09:26:23 +02:00
),
},
{
action: t`Skip carousel to previous post`,
keys: (
<Trans>
2024-08-13 09:26:23 +02:00
<kbd>Shift</kbd> + <kbd>k</kbd>
</Trans>
2024-08-13 09:26:23 +02:00
),
},
{
action: t`Load new posts`,
keys: <kbd>.</kbd>,
},
{
action: t`Open post details`,
keys: (
<Trans>
2024-08-13 09:26:23 +02:00
<kbd>Enter</kbd> or <kbd>o</kbd>
</Trans>
2024-08-13 09:26:23 +02:00
),
},
{
action: (
<Trans>
Expand content warning or
<br />
toggle expanded/collapsed thread
</Trans>
),
keys: <kbd>x</kbd>,
},
{
action: t`Close post or dialogs`,
keys: (
<Trans>
2024-08-13 09:26:23 +02:00
<kbd>Esc</kbd> or <kbd>Backspace</kbd>
</Trans>
2024-08-13 09:26:23 +02:00
),
},
{
action: t`Focus column in multi-column mode`,
keys: (
<Trans>
2024-08-13 09:26:23 +02:00
<kbd>1</kbd> to <kbd>9</kbd>
</Trans>
2024-08-13 09:26:23 +02:00
),
},
{
action: t`Compose new post`,
keys: <kbd>c</kbd>,
},
{
action: t`Compose new post (new window)`,
className: 'insignificant',
keys: (
<Trans>
2024-08-13 09:26:23 +02:00
<kbd>Shift</kbd> + <kbd>c</kbd>
</Trans>
2024-08-13 09:26:23 +02:00
),
},
{
action: t`Send post`,
keys: (
<Trans>
2024-08-13 09:26:23 +02:00
<kbd>Ctrl</kbd> + <kbd>Enter</kbd> or <kbd></kbd> +{' '}
<kbd>Enter</kbd>
</Trans>
2024-08-13 09:26:23 +02:00
),
},
{
action: t`Search`,
keys: <kbd>/</kbd>,
},
{
action: t`Reply`,
keys: <kbd>r</kbd>,
},
{
action: t`Reply (new window)`,
className: 'insignificant',
keys: (
<Trans>
2024-08-13 09:26:23 +02:00
<kbd>Shift</kbd> + <kbd>r</kbd>
</Trans>
2024-08-13 09:26:23 +02:00
),
},
{
action: t`Like (favourite)`,
keys: (
<Trans>
2024-08-13 09:26:23 +02:00
<kbd>l</kbd> or <kbd>f</kbd>
</Trans>
2024-08-13 09:26:23 +02:00
),
},
{
action: t`Boost`,
keys: (
<Trans>
2024-08-13 09:26:23 +02:00
<kbd>Shift</kbd> + <kbd>b</kbd>
</Trans>
2024-08-13 09:26:23 +02:00
),
},
{
action: t`Bookmark`,
keys: <kbd>d</kbd>,
},
{
action: t`Toggle Cloak mode`,
keys: (
<Trans>
2024-08-13 09:26:23 +02:00
<kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>k</kbd>
</Trans>
2024-08-13 09:26:23 +02:00
),
},
].map(({ action, className, keys }) => (
<tr key={action}>
<th class={className}>{action}</th>
<td>{keys}</td>
</tr>
))}
</tbody>
2023-09-06 16:54:05 +02:00
</table>
</main>
</div>
</Modal>
)
);
});