convert app.js to app.tsx

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2020-04-22 13:29:12 +01:00
parent 7ffa1ba1bd
commit d486782dd4
2 changed files with 13 additions and 14 deletions

View File

@ -15,12 +15,12 @@ limitations under the License.
*/ */
import "matrix-react-sdk/src/@types/global"; // load matrix-react-sdk's type extensions first 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 { declare global {
interface Window { interface Window {
mxSendRageshake: (text: string, withLogs?: boolean) => void; mxSendRageshake: (text: string, withLogs?: boolean) => void;
matrixChat: ReturnType<Renderer>; matrixChat: MatrixChat;
// electron-only // electron-only
ipcRenderer: any; ipcRenderer: any;

View File

@ -19,9 +19,9 @@ limitations under the License.
*/ */
import React from 'react'; import React from 'react';
// add React and ReactPerf to the global namespace, to make them easier to // add React and ReactPerf to the global namespace, to make them easier to access via the console
// access via the console // this incidentally means we can forget our React imports in JSX files without penalty.
global.React = React; window.React = React;
import * as sdk from 'matrix-react-sdk'; import * as sdk from 'matrix-react-sdk';
import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg'; 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'; 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 // Parse the given window.location and return parameters that can be used when calling
// MatrixChat.showScreen(screen, params) // MatrixChat.showScreen(screen, params)
function getScreenFromLocation(location) { function getScreenFromLocation(location: Location) {
const fragparts = parseQsFromFragment(location); const fragparts = parseQsFromFragment(location);
return { return {
screen: fragparts.location.substring(1), screen: fragparts.location.substring(1),
@ -54,7 +54,7 @@ function getScreenFromLocation(location) {
// Here, we do some crude URL analysis to allow // Here, we do some crude URL analysis to allow
// deep-linking. // deep-linking.
function routeUrl(location) { function routeUrl(location: Location) {
if (!window.matrixChat) return; if (!window.matrixChat) return;
console.log("Routing URL ", location.href); console.log("Routing URL ", location.href);
@ -62,7 +62,7 @@ function routeUrl(location) {
window.matrixChat.showScreen(s.screen, s.params); window.matrixChat.showScreen(s.screen, s.params);
} }
function onHashChange(ev) { function onHashChange(ev: HashChangeEvent) {
if (decodeURIComponent(window.location.hash) === lastLocationHashSet) { if (decodeURIComponent(window.location.hash) === lastLocationHashSet) {
// we just set this: no need to route it! // we just set this: no need to route it!
return; return;
@ -72,7 +72,7 @@ function onHashChange(ev) {
// This will be called whenever the SDK changes screens, // This will be called whenever the SDK changes screens,
// so a web page can update the URL bar appropriately. // so a web page can update the URL bar appropriately.
function onNewScreen(screen) { function onNewScreen(screen: string) {
console.log("newscreen " + screen); console.log("newscreen " + screen);
const hash = '#/' + screen; const hash = '#/' + screen;
lastLocationHashSet = hash; lastLocationHashSet = hash;
@ -88,7 +88,7 @@ function onNewScreen(screen) {
// If we're in electron, we should never pass through a file:// URL otherwise // 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. // 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. // so in that instance, hardcode to use riot.im/app for now instead.
function makeRegistrationUrl(params) { function makeRegistrationUrl(params: object) {
let url; let url;
if (window.location.protocol === "vector:") { if (window.location.protocol === "vector:") {
url = 'https://riot.im/app/#/register'; url = 'https://riot.im/app/#/register';
@ -121,8 +121,7 @@ function onTokenLoginCompleted() {
const parsedUrl = url.parse(window.location.href); const parsedUrl = url.parse(window.location.href);
parsedUrl.search = ""; parsedUrl.search = "";
const formatted = url.format(parsedUrl); const formatted = url.format(parsedUrl);
console.log("Redirecting to " + formatted + " to drop loginToken " + console.log(`Redirecting to ${formatted} to drop loginToken from queryparams`);
"from queryparams");
window.location.href = formatted; window.location.href = formatted;
} }