GameInformation.jsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React from "react";
  2. import { useTranslation } from "react-i18next";
  3. import useAsyncEffect from "use-async-effect";
  4. import { useBoardConfig } from "react-sync-board";
  5. import { getBestTranslationFromConfig } from "../../utils/api";
  6. const GameInformation = () => {
  7. const { t, i18n } = useTranslation();
  8. const [info, setInfo] = React.useState("");
  9. const [boardConfig] = useBoardConfig();
  10. const translation = React.useMemo(
  11. () => getBestTranslationFromConfig(boardConfig, i18n.languages),
  12. [boardConfig, i18n.languages]
  13. );
  14. useAsyncEffect(
  15. async (isMounted) => {
  16. const marked = (await import("marked")).default;
  17. if (!isMounted()) return;
  18. const renderer = new marked.Renderer();
  19. renderer.link = (href, title, text) => {
  20. return `<a target="_blank" rel="noopener" href="${href}" title="${title}">${text}</a>`;
  21. };
  22. setInfo(
  23. marked(translation.description || "", {
  24. renderer: renderer,
  25. })
  26. );
  27. },
  28. [setInfo, translation.description]
  29. );
  30. return (
  31. <>
  32. <header>
  33. <h3>{t("Game information")}</h3>
  34. </header>
  35. <section>
  36. {translation.description && (
  37. <div
  38. dangerouslySetInnerHTML={{
  39. __html: info,
  40. }}
  41. ></div>
  42. )}
  43. {!translation.description && <div>{t("No information")}</div>}
  44. </section>
  45. </>
  46. );
  47. };
  48. export default GameInformation;