All files / Rindu/components/ShortCuts ShortCuts.tsx

38.46% Statements 5/13
100% Branches 0/0
0% Functions 0/6
38.46% Lines 5/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 15819x   19x 19x 19x 19x                                                                                                                                                                                                                                                                                                                
import { Fragment, ReactElement } from "react";
 
import { Heading, Kbd } from "components";
import { useTranslations } from "hooks";
import { AsType } from "types/heading";
import { templateReplace } from "utils";
 
export default function ShortCuts(): ReactElement {
  const { translations } = useTranslations();
  const shortCutsGroups: Record<string, Record<string, string[]>[]>[] = [
    {
      [translations.shortCuts.basic]: [
        {
          [translations.shortCuts.createNewPlaylist]: ["Alt", "Shift", "P"],
          [translations.shortCuts.createNewFolder]: [
            "Ctrl",
            "Alt",
            "Shift",
            "P",
          ],
          [translations.shortCuts.openContextMenu]: ["Alt", "J"],
          [translations.shortCuts.openQuickSearch]: ["Ctrl", "K"],
          [translations.shortCuts.logOut]: ["Alt", "Shift", "F6"],
        },
      ],
      [translations.shortCuts.playback]: [
        {
          [translations.shortCuts.playPause]: ["Space"],
          [translations.shortCuts.like]: ["Alt", "Shift", "B"],
          [translations.shortCuts.shuffle]: ["Alt", "S"],
          [translations.shortCuts.repeat]: ["Alt", "R"],
          [translations.shortCuts.skipToPrevious]: ["Alt", "←"],
          [translations.shortCuts.skipToNext]: ["Alt", "→"],
          [translations.shortCuts.seekBackward]: ["Shift", "←"],
          [translations.shortCuts.seekForward]: ["Shift", "→"],
          [translations.shortCuts.raiseVolume]: ["Alt", "↑"],
          [translations.shortCuts.lowerVolume]: ["Alt", "↓"],
        },
      ],
      [translations.shortCuts.navigation]: [
        {
          [translations.shortCuts.home]: ["Alt", "Shift", "H"],
          [translations.shortCuts.backInHistory]: ["Ctrl", "←"],
          [translations.shortCuts.forwardInHistory]: ["Ctrl", "→"],
          [translations.shortCuts.currentlyPlaying]: ["Alt", "Shift", "J"],
          [translations.shortCuts.search]: ["Ctrl", "Shift", "L"],
          [translations.shortCuts.likedSongs]: ["Alt", "Shift", "S"],
          [translations.shortCuts.queue]: ["Alt", "Shift", "Q"],
          [translations.shortCuts.yourPlaylists]: ["Alt", "Shift", "1"],
          [translations.shortCuts.yourPodcasts]: ["Alt", "Shift", "2"],
          [translations.shortCuts.yourArtists]: ["Alt", "Shift", "3"],
          [translations.shortCuts.yourAlbums]: ["Alt", "Shift", "4"],
          [translations.shortCuts.madeForYou]: ["Alt", "Shift", "M"],
          [translations.shortCuts.newReleases]: ["Alt", "Shift", "N"],
          [translations.shortCuts.charts]: ["Alt", "Shift", "C"],
        },
      ],
      [translations.shortCuts.layout]: [
        {
          [translations.shortCuts.decreaseNavigationWidth]: [
            "Alt",
            "Shift",
            "←",
          ],
          [translations.shortCuts.increaseNavigationWidth]: [
            "Alt",
            "Shift",
            "→",
          ],
          [translations.shortCuts.decreaseActivityTabWidth]: [
            "Alt",
            "Shift",
            "↑",
          ],
          [translations.shortCuts.increaseActivityTabWidth]: [
            "Alt",
            "Shift",
            "↓",
          ],
        },
      ],
    },
  ];
 
  return (
    <div className="shortcuts-container">
      <p>
        {templateReplace(translations.shortCuts.shortCutdescription, [
          <Fragment key={"Shortcut to shortcut"}>
            <Kbd key={"Ctrl"}>Ctrl</Kbd>
            <Kbd key={"/"}>/</Kbd>
          </Fragment>,
          <Kbd key={"?"}>?</Kbd>,
        ])}
      </p>
      <div className="shortcuts">
        {shortCutsGroups.map((group) => {
          return Object.keys(group).map((groupName) => {
            return (
              <Fragment key={groupName}>
                <Heading number={4} as={AsType.H2} margin="30px 0 15px">
                  {groupName}
                </Heading>
                <ul>
                  {group[groupName].map((shortCut) => {
                    return Object.keys(shortCut).map((shortCutName) => {
                      return (
                        <li key={shortCutName}>
                          <span>{shortCutName}</span>
                          {shortCut[shortCutName].map((key) => {
                            return <Kbd key={key}>{key}</Kbd>;
                          })}
                        </li>
                      );
                    });
                  })}
                </ul>
              </Fragment>
            );
          });
        })}
      </div>
      <style jsx>{`
        :global(.modal) {
          overflow: auto;
        }
        .shortcuts-container {
          max-width: 100%;
          margin-bottom: 20px;
          min-width: 440px;
        }
        .shortcuts {
          overflow: auto;
          max-width: 100%;
          max-height: 100%;
        }
        ol,
        ul {
          list-style: none;
        }
        li {
          align-items: center;
          display: flex;
          margin: 16px 0;
        }
        ul span {
          margin-right: 16px;
          box-sizing: border-box;
          font-size: 1rem;
          font-weight: 400;
          color: inherit;
          flex: 1;
        }
      `}</style>
    </div>
  );
}