Refactor: convert initializeApp to func component and use JSX transform in the codebase (#4056)

This commit is contained in:
Aakansha Doshi 2021-10-14 22:56:51 +05:30 committed by GitHub
parent 463857ad9a
commit ff29780760
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 20 additions and 70 deletions

View File

@ -1,4 +1,3 @@
import React from "react";
import { alignElements, Alignment } from "../align"; import { alignElements, Alignment } from "../align";
import { import {
AlignBottomIcon, AlignBottomIcon,

View File

@ -1,4 +1,3 @@
import React from "react";
import { getDefaultAppState } from "../appState"; import { getDefaultAppState } from "../appState";
import { ColorPicker } from "../components/ColorPicker"; import { ColorPicker } from "../components/ColorPicker";
import { trash, zoomIn, zoomOut } from "../components/icons"; import { trash, zoomIn, zoomOut } from "../components/icons";

View File

@ -1,7 +1,6 @@
import { isSomeElementSelected } from "../scene"; import { isSomeElementSelected } from "../scene";
import { KEYS } from "../keys"; import { KEYS } from "../keys";
import { ToolButton } from "../components/ToolButton"; import { ToolButton } from "../components/ToolButton";
import React from "react";
import { trash } from "../components/icons"; import { trash } from "../components/icons";
import { t } from "../i18n"; import { t } from "../i18n";
import { register } from "./register"; import { register } from "./register";

View File

@ -1,4 +1,3 @@
import React from "react";
import { import {
DistributeHorizontallyIcon, DistributeHorizontallyIcon,
DistributeVerticallyIcon, DistributeVerticallyIcon,

View File

@ -1,4 +1,3 @@
import React from "react";
import { KEYS } from "../keys"; import { KEYS } from "../keys";
import { register } from "./register"; import { register } from "./register";
import { ExcalidrawElement } from "../element/types"; import { ExcalidrawElement } from "../element/types";

View File

@ -1,4 +1,3 @@
import React from "react";
import { trackEvent } from "../analytics"; import { trackEvent } from "../analytics";
import { load, questionCircle, saveAs } from "../components/icons"; import { load, questionCircle, saveAs } from "../components/icons";
import { ProjectName } from "../components/ProjectName"; import { ProjectName } from "../components/ProjectName";

View File

@ -1,7 +1,6 @@
import { KEYS } from "../keys"; import { KEYS } from "../keys";
import { isInvisiblySmallElement } from "../element"; import { isInvisiblySmallElement } from "../element";
import { resetCursor } from "../utils"; import { resetCursor } from "../utils";
import React from "react";
import { ToolButton } from "../components/ToolButton"; import { ToolButton } from "../components/ToolButton";
import { done } from "../components/icons"; import { done } from "../components/icons";
import { t } from "../i18n"; import { t } from "../i18n";

View File

@ -1,4 +1,3 @@
import React from "react";
import { CODES, KEYS } from "../keys"; import { CODES, KEYS } from "../keys";
import { t } from "../i18n"; import { t } from "../i18n";
import { getShortcutKey } from "../utils"; import { getShortcutKey } from "../utils";

View File

@ -1,5 +1,4 @@
import { Action, ActionResult } from "./types"; import { Action, ActionResult } from "./types";
import React from "react";
import { undo, redo } from "../components/icons"; import { undo, redo } from "../components/icons";
import { ToolButton } from "../components/ToolButton"; import { ToolButton } from "../components/ToolButton";
import { t } from "../i18n"; import { t } from "../i18n";

View File

@ -1,4 +1,3 @@
import React from "react";
import { menu, palette } from "../components/icons"; import { menu, palette } from "../components/icons";
import { ToolButton } from "../components/ToolButton"; import { ToolButton } from "../components/ToolButton";
import { t } from "../i18n"; import { t } from "../i18n";

View File

@ -1,4 +1,3 @@
import React from "react";
import { getClientColors, getClientInitials } from "../clients"; import { getClientColors, getClientInitials } from "../clients";
import { Avatar } from "../components/Avatar"; import { Avatar } from "../components/Avatar";
import { centerScrollOn } from "../scene/scroll"; import { centerScrollOn } from "../scene/scroll";

View File

@ -1,4 +1,3 @@
import React from "react";
import { AppState } from "../../src/types"; import { AppState } from "../../src/types";
import { ButtonIconSelect } from "../components/ButtonIconSelect"; import { ButtonIconSelect } from "../components/ButtonIconSelect";
import { ColorPicker } from "../components/ColorPicker"; import { ColorPicker } from "../components/ColorPicker";

View File

@ -1,4 +1,3 @@
import React from "react";
import Stack from "../components/Stack"; import Stack from "../components/Stack";
import { ToolButton } from "../components/ToolButton"; import { ToolButton } from "../components/ToolButton";
import { save, file } from "../components/icons"; import { save, file } from "../components/icons";

View File

@ -1,4 +1,3 @@
import React from "react";
import clsx from "clsx"; import clsx from "clsx";
// TODO: It might be "clever" to add option.icon to the existing component <ButtonSelect /> // TODO: It might be "clever" to add option.icon to the existing component <ButtonSelect />

View File

@ -1,4 +1,3 @@
import React from "react";
import clsx from "clsx"; import clsx from "clsx";
export const ButtonSelect = <T extends Object>({ export const ButtonSelect = <T extends Object>({

View File

@ -1,4 +1,3 @@
import React from "react";
import clsx from "clsx"; import clsx from "clsx";
import { ToolButton } from "./ToolButton"; import { ToolButton } from "./ToolButton";
import { t } from "../i18n"; import { t } from "../i18n";

View File

@ -1,4 +1,3 @@
import React from "react";
import { render, unmountComponentAtNode } from "react-dom"; import { render, unmountComponentAtNode } from "react-dom";
import clsx from "clsx"; import clsx from "clsx";
import { Popover } from "./Popover"; import { Popover } from "./Popover";

View File

@ -1,6 +1,5 @@
import "./ToolIcon.scss"; import "./ToolIcon.scss";
import React from "react";
import { t } from "../i18n"; import { t } from "../i18n";
import { ToolButton } from "./ToolButton"; import { ToolButton } from "./ToolButton";
import { THEME } from "../constants"; import { THEME } from "../constants";

View File

@ -1,4 +1,3 @@
import React from "react";
import { questionCircle } from "../components/icons"; import { questionCircle } from "../components/icons";
type HelpIconProps = { type HelpIconProps = {

View File

@ -1,4 +1,3 @@
import React from "react";
import { t } from "../i18n"; import { t } from "../i18n";
import { NonDeletedExcalidrawElement } from "../element/types"; import { NonDeletedExcalidrawElement } from "../element/types";
import { getSelectedElements } from "../scene"; import { getSelectedElements } from "../scene";

View File

@ -1,30 +1,25 @@
import React from "react"; import React, { useEffect, useState } from "react";
import { LoadingMessage } from "./LoadingMessage"; import { LoadingMessage } from "./LoadingMessage";
import { defaultLang, Language, languages, setLanguage } from "../i18n"; import { defaultLang, Language, languages, setLanguage } from "../i18n";
interface Props { interface Props {
langCode: Language["code"]; langCode: Language["code"];
children: React.ReactElement;
} }
interface State {
isLoading: boolean;
}
export class InitializeApp extends React.Component<Props, State> {
public state: { isLoading: boolean } = {
isLoading: true,
};
async componentDidMount() { export const InitializeApp = (props: Props) => {
const [loading, setLoading] = useState(true);
useEffect(() => {
const updateLang = async () => {
await setLanguage(currentLang);
};
const currentLang = const currentLang =
languages.find((lang) => lang.code === this.props.langCode) || languages.find((lang) => lang.code === props.langCode) || defaultLang;
defaultLang; updateLang();
await setLanguage(currentLang); setLoading(false);
this.setState({ }, [props.langCode]);
isLoading: false,
});
}
public render() { return loading ? <LoadingMessage /> : props.children;
return this.state.isLoading ? <LoadingMessage /> : this.props.children; };
}
}

View File

@ -1,6 +1,6 @@
import clsx from "clsx"; import clsx from "clsx";
import oc from "open-color"; import oc from "open-color";
import React, { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import { close } from "../components/icons"; import { close } from "../components/icons";
import { MIME_TYPES } from "../constants"; import { MIME_TYPES } from "../constants";
import { t } from "../i18n"; import { t } from "../i18n";

View File

@ -1,4 +1,3 @@
import React from "react";
import { t } from "../i18n"; import { t } from "../i18n";
export const LoadingMessage = () => { export const LoadingMessage = () => {

View File

@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useRef } from "react"; import { useCallback, useEffect, useRef } from "react";
import { TOAST_TIMEOUT } from "../constants"; import { TOAST_TIMEOUT } from "../constants";
import "./Toast.scss"; import "./Toast.scss";

View File

@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { debounce, getVersion, nFormatter } from "../utils"; import { debounce, getVersion, nFormatter } from "../utils";
import { import {
getElementsStorageSize, getElementsStorageSize,

View File

@ -1,5 +1,5 @@
import throttle from "lodash.throttle"; import throttle from "lodash.throttle";
import React, { PureComponent } from "react"; import { PureComponent } from "react";
import { ExcalidrawImperativeAPI } from "../../types"; import { ExcalidrawImperativeAPI } from "../../types";
import { ErrorDialog } from "../../components/ErrorDialog"; import { ErrorDialog } from "../../components/ErrorDialog";
import { APP_NAME, ENV, EVENT } from "../../constants"; import { APP_NAME, ENV, EVENT } from "../../constants";

View File

@ -1,11 +1,5 @@
import LanguageDetector from "i18next-browser-languagedetector"; import LanguageDetector from "i18next-browser-languagedetector";
import React, { import { useCallback, useContext, useEffect, useRef, useState } from "react";
useCallback,
useContext,
useEffect,
useRef,
useState,
} from "react";
import { trackEvent } from "../analytics"; import { trackEvent } from "../analytics";
import { getDefaultAppState } from "../appState"; import { getDefaultAppState } from "../appState";
import { ErrorDialog } from "../components/ErrorDialog"; import { ErrorDialog } from "../components/ErrorDialog";

View File

@ -1,4 +1,3 @@
import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import ExcalidrawApp from "./excalidraw-app"; import ExcalidrawApp from "./excalidraw-app";

View File

@ -1,4 +1,3 @@
import React from "react";
import { KEYS } from "./keys"; import { KEYS } from "./keys";
// We inline font-awesome icons in order to save on js size rather than including the font awesome react library // We inline font-awesome icons in order to save on js size rather than including the font awesome react library

View File

@ -1,4 +1,3 @@
import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import { render } from "./test-utils"; import { render } from "./test-utils";
import ExcalidrawApp from "../excalidraw-app"; import ExcalidrawApp from "../excalidraw-app";

View File

@ -1,4 +1,3 @@
import React from "react";
import { render, waitFor } from "./test-utils"; import { render, waitFor } from "./test-utils";
import ExcalidrawApp from "../excalidraw-app"; import ExcalidrawApp from "../excalidraw-app";
import { API } from "./helpers/api"; import { API } from "./helpers/api";

View File

@ -1,4 +1,3 @@
import React from "react";
import { fireEvent, render } from "./test-utils"; import { fireEvent, render } from "./test-utils";
import ExcalidrawApp from "../excalidraw-app"; import ExcalidrawApp from "../excalidraw-app";
import { UI, Pointer, Keyboard } from "./helpers/ui"; import { UI, Pointer, Keyboard } from "./helpers/ui";

View File

@ -1,4 +1,3 @@
import React from "react";
import { render, updateSceneData, waitFor } from "./test-utils"; import { render, updateSceneData, waitFor } from "./test-utils";
import ExcalidrawApp from "../excalidraw-app"; import ExcalidrawApp from "../excalidraw-app";
import { API } from "./helpers/api"; import { API } from "./helpers/api";

View File

@ -1,4 +1,3 @@
import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import ExcalidrawApp from "../excalidraw-app"; import ExcalidrawApp from "../excalidraw-app";
import * as Renderer from "../renderer/renderScene"; import * as Renderer from "../renderer/renderScene";

View File

@ -1,4 +1,3 @@
import React from "react";
import { render, waitFor } from "./test-utils"; import { render, waitFor } from "./test-utils";
import ExcalidrawApp from "../excalidraw-app"; import ExcalidrawApp from "../excalidraw-app";
import { API } from "./helpers/api"; import { API } from "./helpers/api";

View File

@ -1,4 +1,3 @@
import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import { render } from "./test-utils"; import { render } from "./test-utils";
import App from "../components/App"; import App from "../components/App";

View File

@ -1,4 +1,3 @@
import React from "react";
import { assertSelectedElements, render } from "./test-utils"; import { assertSelectedElements, render } from "./test-utils";
import ExcalidrawApp from "../excalidraw-app"; import ExcalidrawApp from "../excalidraw-app";
import { Keyboard, Pointer, UI } from "./helpers/ui"; import { Keyboard, Pointer, UI } from "./helpers/ui";

View File

@ -1,4 +1,3 @@
import React from "react";
import { render, waitFor } from "./test-utils"; import { render, waitFor } from "./test-utils";
import ExcalidrawApp from "../excalidraw-app"; import ExcalidrawApp from "../excalidraw-app";
import { API } from "./helpers/api"; import { API } from "./helpers/api";

View File

@ -1,4 +1,3 @@
import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import { import {
render, render,

View File

@ -1,4 +1,3 @@
import React from "react";
import { fireEvent, GlobalTestState, render } from "../test-utils"; import { fireEvent, GlobalTestState, render } from "../test-utils";
import Excalidraw from "../../packages/excalidraw/index"; import Excalidraw from "../../packages/excalidraw/index";
import { queryByText, queryByTestId } from "@testing-library/react"; import { queryByText, queryByTestId } from "@testing-library/react";

View File

@ -1,4 +1,3 @@
import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import { render } from "./test-utils"; import { render } from "./test-utils";
import App from "../components/App"; import App from "../components/App";

View File

@ -1,4 +1,3 @@
import React from "react";
import { import {
mockBoundingClientRect, mockBoundingClientRect,
render, render,

View File

@ -1,4 +1,3 @@
import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import { import {
render, render,

View File

@ -1,4 +1,3 @@
import React from "react";
import { render, GlobalTestState } from "./test-utils"; import { render, GlobalTestState } from "./test-utils";
import ExcalidrawApp from "../excalidraw-app"; import ExcalidrawApp from "../excalidraw-app";
import { KEYS } from "../keys"; import { KEYS } from "../keys";

View File

@ -1,4 +1,3 @@
import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import { render } from "./test-utils"; import { render } from "./test-utils";
import ExcalidrawApp from "../excalidraw-app"; import ExcalidrawApp from "../excalidraw-app";