WelcomeScreen.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { actionLoadScene, actionShortcuts } from "../actions";
  2. import { ActionManager } from "../actions/manager";
  3. import { getShortcutFromShortcutName } from "../actions/shortcuts";
  4. import { isExcalidrawPlusSignedUser } from "../constants";
  5. import { t } from "../i18n";
  6. import { AppState } from "../types";
  7. import { ExcalLogo, HelpIcon, LoadIcon, PlusPromoIcon } from "./icons";
  8. import "./WelcomeScreen.scss";
  9. const WelcomeScreenItem = ({
  10. label,
  11. shortcut,
  12. onClick,
  13. icon,
  14. link,
  15. }: {
  16. label: string;
  17. shortcut: string | null;
  18. onClick?: () => void;
  19. icon: JSX.Element;
  20. link?: string;
  21. }) => {
  22. if (link) {
  23. return (
  24. <a
  25. className="WelcomeScreen-item"
  26. href={link}
  27. target="_blank"
  28. rel="noreferrer"
  29. >
  30. <div className="WelcomeScreen-item__label">
  31. {icon}
  32. {label}
  33. </div>
  34. </a>
  35. );
  36. }
  37. return (
  38. <button className="WelcomeScreen-item" type="button" onClick={onClick}>
  39. <div className="WelcomeScreen-item__label">
  40. {icon}
  41. {label}
  42. </div>
  43. {shortcut && (
  44. <div className="WelcomeScreen-item__shortcut">{shortcut}</div>
  45. )}
  46. </button>
  47. );
  48. };
  49. const WelcomeScreen = ({
  50. appState,
  51. actionManager,
  52. }: {
  53. appState: AppState;
  54. actionManager: ActionManager;
  55. }) => {
  56. let subheadingJSX;
  57. if (isExcalidrawPlusSignedUser) {
  58. subheadingJSX = t("welcomeScreen.switchToPlusApp")
  59. .split(/(Excalidraw\+)/)
  60. .map((bit, idx) => {
  61. if (bit === "Excalidraw+") {
  62. return (
  63. <a
  64. style={{ pointerEvents: "all" }}
  65. href={`${process.env.REACT_APP_PLUS_APP}?utm_source=excalidraw&utm_medium=app&utm_content=welcomeScreenSignedInUser`}
  66. key={idx}
  67. >
  68. Excalidraw+
  69. </a>
  70. );
  71. }
  72. return bit;
  73. });
  74. } else {
  75. subheadingJSX = t("welcomeScreen.data");
  76. }
  77. return (
  78. <div className="WelcomeScreen-container">
  79. <div className="WelcomeScreen-logo virgil WelcomeScreen-decor">
  80. {ExcalLogo} Excalidraw
  81. </div>
  82. <div className="virgil WelcomeScreen-decor WelcomeScreen-decor--subheading">
  83. {subheadingJSX}
  84. </div>
  85. <div className="WelcomeScreen-items">
  86. {!appState.viewModeEnabled && (
  87. <WelcomeScreenItem
  88. // TODO barnabasmolnar/editor-redesign
  89. // do we want the internationalized labels here that are currently
  90. // in use elsewhere or new ones?
  91. label={t("buttons.load")}
  92. onClick={() => actionManager.executeAction(actionLoadScene)}
  93. shortcut={getShortcutFromShortcutName("loadScene")}
  94. icon={LoadIcon}
  95. />
  96. )}
  97. <WelcomeScreenItem
  98. onClick={() => actionManager.executeAction(actionShortcuts)}
  99. label={t("helpDialog.title")}
  100. shortcut="?"
  101. icon={HelpIcon}
  102. />
  103. {!isExcalidrawPlusSignedUser && (
  104. <WelcomeScreenItem
  105. link="https://plus.excalidraw.com/plus?utm_source=excalidraw&utm_medium=app&utm_content=welcomeScreenGuest"
  106. label="Try Excalidraw Plus!"
  107. shortcut={null}
  108. icon={PlusPromoIcon}
  109. />
  110. )}
  111. </div>
  112. </div>
  113. );
  114. };
  115. export default WelcomeScreen;