InfoModal.jsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import React from "react";
  2. import { useTranslation, Trans } from "react-i18next";
  3. import { useRecoilValue } from "recoil";
  4. import useAsyncEffect from "use-async-effect";
  5. import styled from "styled-components";
  6. import Modal from "../../components/ui/Modal";
  7. // import { BoardConfigAtom } from "../../components/board";
  8. import { getBestTranslationFromConfig } from "../../utils/api";
  9. const Kbd = styled.kbd`
  10. background-color: #eee;
  11. border-radius: 3px;
  12. border: 1px solid #b4b4b4;
  13. box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2),
  14. 0 2px 0 0 rgba(255, 255, 255, 0.7) inset;
  15. color: #333;
  16. display: inline-block;
  17. font-family: consolas, "Liberation Mono", courier, monospace;
  18. font-size: 0.85em;
  19. font-weight: 700;
  20. line-height: 1;
  21. padding: 2px 4px;
  22. white-space: nowrap;
  23. `;
  24. const InfoModal = ({ show, setShow }) => {
  25. const { t, i18n } = useTranslation();
  26. const [info, setInfo] = React.useState("");
  27. // const boardConfig = useRecoilValue(BoardConfigAtom);
  28. const translation = React.useMemo(
  29. // () => getBestTranslationFromConfig(boardConfig, i18n.languages),
  30. () => getBestTranslationFromConfig({}, i18n.languages),
  31. [i18n.languages]
  32. );
  33. useAsyncEffect(
  34. async (isMounted) => {
  35. const marked = (await import("marked")).default;
  36. if (!isMounted()) return;
  37. const renderer = new marked.Renderer();
  38. renderer.link = (href, title, text) => {
  39. return `<a target="_blank" rel="noopener" href="${href}" title="${title}">${text}</a>`;
  40. };
  41. setInfo(
  42. marked(translation.description || "", {
  43. renderer: renderer,
  44. })
  45. );
  46. },
  47. [setInfo, translation.description]
  48. );
  49. return (
  50. <Modal title={t("Help & info")} setShow={setShow} show={show}>
  51. <header>
  52. <h3>{t("Game information")}</h3>
  53. </header>
  54. <section>
  55. {translation.description && (
  56. <div
  57. dangerouslySetInnerHTML={{
  58. __html: info,
  59. }}
  60. ></div>
  61. )}
  62. {!translation.description && <div>{t("No information")}</div>}
  63. </section>
  64. <header>
  65. <h3>{t("Board interactions")}</h3>
  66. </header>
  67. <section>
  68. <Trans i18nKey="helpBoard">
  69. <ul>
  70. <li>
  71. Move the board with middle mouse button click. Alternatively you
  72. can use left button with alt key.
  73. </li>
  74. <li>Zoom with mouse wheel.</li>
  75. <li>
  76. Switch to edit mode with top button to be able to edit the game.
  77. </li>
  78. <li>You can save and reload game by clicking the burger menu.</li>
  79. <li>
  80. Use <Kbd>Ctrl</Kbd> + <Kbd>1</Kbd>-<Kbd>9</Kbd> to save a position
  81. and <Kbd>1</Kbd>-<Kbd>9</Kbd>
  82. to restore it.
  83. </li>
  84. <li>
  85. Use <Kbd>space</Kbd> to zoom temporally to the center of screen.
  86. </li>
  87. </ul>
  88. </Trans>
  89. </section>
  90. <header>
  91. <h3>{t("Item interactions")}</h3>
  92. </header>
  93. <section>
  94. <Trans i18nKey="helpItem">
  95. <ul>
  96. <li>Double click on any item to execute the main action on it.</li>
  97. <li>
  98. Long clic on item to be able to selected previously locked item.
  99. </li>
  100. <li>See other shortcuts in action menu.</li>
  101. </ul>
  102. </Trans>
  103. </section>
  104. <header>
  105. <h3>{t("More information")}</h3>
  106. </header>
  107. <section>
  108. <Trans i18nKey="moreInformation">
  109. <p>
  110. For more information, visit{" "}
  111. <a href="https://github.com/jrmi/airboardgame/">
  112. github repository
  113. </a>
  114. .
  115. </p>
  116. </Trans>
  117. </section>
  118. </Modal>
  119. );
  120. };
  121. export default InfoModal;