From d486782dd4772139e75068438975a887c0c91fa5 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 22 Apr 2020 13:29:12 +0100 Subject: [PATCH] convert app.js to app.tsx Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/@types/global.d.ts | 4 ++-- src/vector/{app.js => app.tsx} | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) rename src/vector/{app.js => app.tsx} (94%) diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index a3fb9028c4..0068d4018d 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -15,12 +15,12 @@ limitations under the License. */ import "matrix-react-sdk/src/@types/global"; // load matrix-react-sdk's type extensions first -import {Renderer} from "react-dom"; +import type MatrixChat from "matrix-react-sdk/src/components/structures/MatrixChat"; declare global { interface Window { mxSendRageshake: (text: string, withLogs?: boolean) => void; - matrixChat: ReturnType; + matrixChat: MatrixChat; // electron-only ipcRenderer: any; diff --git a/src/vector/app.js b/src/vector/app.tsx similarity index 94% rename from src/vector/app.js rename to src/vector/app.tsx index 930576e2d5..d5484fc3e2 100644 --- a/src/vector/app.js +++ b/src/vector/app.tsx @@ -19,9 +19,9 @@ limitations under the License. */ import React from 'react'; -// add React and ReactPerf to the global namespace, to make them easier to -// access via the console -global.React = React; +// add React and ReactPerf to the global namespace, to make them easier to access via the console +// this incidentally means we can forget our React imports in JSX files without penalty. +window.React = React; import * as sdk from 'matrix-react-sdk'; import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg'; @@ -40,11 +40,11 @@ import SdkConfig from "matrix-react-sdk/src/SdkConfig"; import CallHandler from 'matrix-react-sdk/src/CallHandler'; -let lastLocationHashSet = null; +let lastLocationHashSet: string = null; // Parse the given window.location and return parameters that can be used when calling // MatrixChat.showScreen(screen, params) -function getScreenFromLocation(location) { +function getScreenFromLocation(location: Location) { const fragparts = parseQsFromFragment(location); return { screen: fragparts.location.substring(1), @@ -54,7 +54,7 @@ function getScreenFromLocation(location) { // Here, we do some crude URL analysis to allow // deep-linking. -function routeUrl(location) { +function routeUrl(location: Location) { if (!window.matrixChat) return; console.log("Routing URL ", location.href); @@ -62,7 +62,7 @@ function routeUrl(location) { window.matrixChat.showScreen(s.screen, s.params); } -function onHashChange(ev) { +function onHashChange(ev: HashChangeEvent) { if (decodeURIComponent(window.location.hash) === lastLocationHashSet) { // we just set this: no need to route it! return; @@ -72,8 +72,8 @@ function onHashChange(ev) { // This will be called whenever the SDK changes screens, // so a web page can update the URL bar appropriately. -function onNewScreen(screen) { - console.log("newscreen "+screen); +function onNewScreen(screen: string) { + console.log("newscreen " + screen); const hash = '#/' + screen; lastLocationHashSet = hash; window.location.hash = hash; @@ -88,7 +88,7 @@ function onNewScreen(screen) { // If we're in electron, we should never pass through a file:// URL otherwise // the identity server will try to 302 the browser to it, which breaks horribly. // so in that instance, hardcode to use riot.im/app for now instead. -function makeRegistrationUrl(params) { +function makeRegistrationUrl(params: object) { let url; if (window.location.protocol === "vector:") { url = 'https://riot.im/app/#/register'; @@ -121,8 +121,7 @@ function onTokenLoginCompleted() { const parsedUrl = url.parse(window.location.href); parsedUrl.search = ""; const formatted = url.format(parsedUrl); - console.log("Redirecting to " + formatted + " to drop loginToken " + - "from queryparams"); + console.log(`Redirecting to ${formatted} to drop loginToken from queryparams`); window.location.href = formatted; }