Socialify

Folder ..

Viewing ShortcutsPopup.tsx
208 lines (192 loc) • 5.0 KB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import styled from 'styled-components';
import { useState, useEffect } from 'react';
import { FaTimes } from 'react-icons/fa';

const Overlay = styled.table`
  font-size: 0.85rem;
  animation: fadeIn 0.3s ease-in-out;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
`;

const TableCell = styled.td`
  padding: 0.5rem;
  border-bottom: 1px solid rgba(128, 128, 128, 0.3);
`;

const Column1 = styled(TableCell)`
  padding-right: 15rem;
  opacity: 0.7;
`;

const Column2 = styled(TableCell)`
  padding-right: 5rem;
`;

const CloseButton = styled.button`
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  padding: 0.5rem;
  padding-left: 0.6rem;
  background-color: var(--global-primary-bg-tr);
  color: var(--global-text);
  border: none;
  border-radius: var(--global-border-radius);
  cursor: pointer;
  outline: none;
  transition: 0.1s ease-in-out;
  display: flex;
  justify-content: center;
  align-items: center;

  &:hover {
    transform: scale(1.06);
    svg {
      padding-bottom: 0.1rem;
    }
  }

  &:active,
  &:focus {
    transform: scale(0.94);
  }
`;

const PopUp = styled.thead`
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: slideUp 0.3s ease-in-out;
  position: relative;
  border-radius: var(--global-border-radius);
  padding: 1rem;
  line-height: 1.8rem;
  background: var(--global-primary-bg);
  z-index: 1100;
  overflow: auto;
  max-height: 90vh;
  max-width: 90vw;
`;

const KeyboardShortcutsPopup = ({ onClose }: { onClose: () => void }) => {
  return (
    <Overlay onClick={onClose}>
      <PopUp className='popup-content' onClick={(e) => e.stopPropagation()}>
        <div
          style={{
            background: 'var(--global-div)',
            borderRadius: 'var(--global-border-radius)',
            padding: '0.5rem',
          }}
        >
          <tr>
            <td>
              <CloseButton onClick={onClose}>
                <FaTimes size={'1rem'} />
              </CloseButton>
            </td>
          </tr>
          <tr>
            <td>
              <strong>Keyboard Shortcuts</strong>(shift+/)
            </td>
          </tr>
        </div>
        <div
          style={{
            background: 'var(--global-div)',
            borderRadius: 'var(--global-border-radius)',
            padding: '0.5rem',
          }}
        >
          <tr>
            <Column1>Play/Pause Toggle</Column1>
            <Column2>K / Space</Column2>
          </tr>
          <tr>
            <Column1>Seek Backward 10 Seconds</Column1>
            <Column2>J</Column2>
          </tr>
          <tr>
            <Column1>Seek Forward 10 Seconds</Column1>
            <Column2>L</Column2>
          </tr>
          <tr>
            <Column1>Toggle Fullscreen</Column1>
            <Column2>F</Column2>
          </tr>
          <tr>
            <Column1>Toggle Mute</Column1>
            <Column2>M</Column2>
          </tr>
          <tr>
            <Column1>Previous Episode</Column1>
            <Column2>(SHIFT+P)</Column2>
          </tr>
          <tr>
            <Column1>Next Episode</Column1>
            <Column2>(SHIFT+N)</Column2>
          </tr>
          <tr>
            <Column1>Increase Volume</Column1>
            <Column2>Arrow Up</Column2>
          </tr>
          <tr>
            <Column1>Decrease Volume</Column1>
            <Column2>Arrow Down</Column2>
          </tr>
          <tr>
            <Column1>Seek Forward 5 Seconds</Column1>
            <Column2>Arrow Right</Column2>
          </tr>
          <tr>
            <Column1>Seek Backward 5 Seconds</Column1>
            <Column2>Arrow Left</Column2>
          </tr>
          <tr>
            <Column1>Increase Playback Speed</Column1>
            <Column2>&gt; (SHIFT+,)</Column2>
          </tr>
          <tr>
            <Column1>Decrease Playback Speed</Column1>
            <Column2>&lt; (SHIFT+.)</Column2>
          </tr>
          <tr>
            <Column1>Jump to Percentage (0-90%)</Column1>
            <Column2>0-9</Column2>
          </tr>
        </div>
      </PopUp>
    </Overlay>
  );
};

export const ShortcutsPopup = () => {
  const [showPopup, setShowPopup] = useState(false);

  useEffect(() => {
    const togglePopupWithShortcut = (e: KeyboardEvent) => {
      if (
        e.target &&
        ['INPUT', 'TEXTAREA', 'SELECT'].includes((e.target as Element).tagName)
      ) {
        return;
      }

      if (e.shiftKey && e.key === '?') {
        e.preventDefault();
        setShowPopup(!showPopup);
      } else if (e.key === 'Escape') {
        setShowPopup(false);
      }
    };

    window.addEventListener('keydown', togglePopupWithShortcut);

    return () => {
      window.removeEventListener('keydown', togglePopupWithShortcut);
    };
  }, [showPopup]);

  const togglePopup = () => setShowPopup(!showPopup);

  return (
    <div className='App'>
      {showPopup && <KeyboardShortcutsPopup onClose={togglePopup} />}
    </div>
  );
};