WelcomeScreen.tsx 3.7 KB

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