import type React from 'react'; import { useMemo } from 'react'; import { useTranslation } from 'next-i18next'; import { Modal, ModalBody, ModalHeader } from 'reactstrap'; import { useShortcutsModalActions, useShortcutsModalStatus, } from '~/states/ui/modal/shortcuts'; import styles from './ShortcutsModal.module.scss'; /** * ShortcutsModalSubstance - Presentation component (heavy logic, rendered only when isOpen) */ const ShortcutsModalSubstance = (): React.JSX.Element => { const { t } = useTranslation(); const { close } = useShortcutsModalActions(); // Memoize OS-specific class const additionalClassByOs = useMemo(() => { const userAgent = window.navigator.userAgent.toLowerCase(); const isMac = userAgent.indexOf('mac') > -1; return isMac ? 'mac' : 'win'; }, []); // Memoize body content (large static JSX) const bodyContent = useMemo(() => { return (
{t('modal_shortcuts.global.title')}
    {/* Open/Close shortcut help */}
  • + /
  • {/* Create Page */}
  • {t('modal_shortcuts.global.Create Page')}
    C
  • {/* Edit Page */}
  • {t('modal_shortcuts.global.Edit Page')}
    E
  • {/* Search */}
  • {t('modal_shortcuts.global.Search')}
    /
  • {/* Show Contributors */}
  • {t('modal_shortcuts.global.Konami Code')}
    arrow_upward arrow_upward arrow_downward arrow_downward
    arrow_back arrow_forward arrow_back arrow_forward
    B A
  • {/* Mirror Mode */}
  • {t('modal_shortcuts.global.MirrorMode')}
    {t('modal_shortcuts.global.Konami Code')}
    X X B B
    A Y A Y
    arrow_downward arrow_back
{t('modal_shortcuts.editor.title')}
    {/* Search in Editor */}
  • {t('modal_shortcuts.editor.Search in Editor')}
    + F
  • {/* Save Page */}
  • {t('modal_shortcuts.editor.Save Page')} {t('modal_shortcuts.editor.Only Editor')}
    + S
  • {/* Indent */}
  • {t('modal_shortcuts.editor.Indent')}
    Tab
  • {/* Outdent */}
  • {t('modal_shortcuts.editor.Outdent')}
    Shift + Tab
  • {/* Delete Line */}
  • {t('modal_shortcuts.editor.Delete Line')}
    + Shift + K
  • {/* Insert Line */}

  • {t('modal_shortcuts.editor.Post Comment')}
    + Enter
  • {/* Move Line */}
  • {t('modal_shortcuts.editor.Move Line')}
    + arrow_downward or arrow_upward
  • {/* Copy Line */}
  • {t('modal_shortcuts.editor.Copy Line')}
    + Shift +
    arrow_downward or arrow_upward
  • {/* Multiple Cursors */}
  • {t('modal_shortcuts.editor.Multiple Cursors')}
    + +
    arrow_downward or arrow_upward
    {t('modal_shortcuts.editor.Or Alt Click')}
{/* Format settings section */}
{t('modal_shortcuts.format.title')}
    {/* Bold */}
  • {t('modal_shortcuts.format.Bold')}
    + B
  • {/* Italic */}
  • {t('modal_shortcuts.format.Italic')}
    + Shift + I
  • {/* Strikethrough */}
  • {t('modal_shortcuts.format.Strikethrough')}
    + Shift + X
  • {/* Code Text */}
  • {t('modal_shortcuts.format.Code Text')}
    + Shift + C
  • {/* Hyperlink */}
  • {t('modal_shortcuts.format.Hyperlink')}
    + Shift + U
{t('modal_shortcuts.line_settings.title')}
    {/* Simple List */}
  • {t('modal_shortcuts.line_settings.Numbered List')}
    + Shift + 7
  • {/* Numbered List */}
  • {t('modal_shortcuts.line_settings.Bullet List')}
    + Shift + 8
  • {/* Quote */}
  • {t('modal_shortcuts.line_settings.Quote')}
    + Shift + 9
  • {/* Code Block */}
  • {t('modal_shortcuts.line_settings.Code Block')}
    + +
    Shift + C
  • {/* Hide comments */}
  • {t('modal_shortcuts.line_settings.Comment Out')}
    {t('modal_shortcuts.line_settings.Comment Out Desc')}
    + /
); }, [additionalClassByOs, t]); return ( <> {t('Shortcuts')} {bodyContent}
{/* TODO: Replace href with the dedicated keyboard shortcuts docs page once published */} help {t('modal_shortcuts.Other Shortcuts')}
); }; /** * ShortcutsModal - Container component (lightweight, always rendered) */ export const ShortcutsModal = (): React.JSX.Element => { const status = useShortcutsModalStatus(); const { close } = useShortcutsModalActions(); return ( {status?.isOpened && } ); };