From d7ca790f0a5b55777df73451162089ef5135a239 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 16 Aug 2021 14:21:33 +0300 Subject: [PATCH] [Refactoring] Fix TS and ESLint errors after updating packages (#1386) --- .eslintignore | 1 + .eslintrc | 7 ++ .husky/pre-commit | 4 + package-lock.json | 82 ++++++++----------- package.json | 2 +- src/@types/global.d.ts | 8 +- src/api/gramjs/apiBuilders/messages.ts | 1 - src/api/gramjs/methods/chats.ts | 1 - src/api/gramjs/methods/client.ts | 2 +- src/api/gramjs/updater.ts | 2 + src/api/types/bots.ts | 2 +- src/api/types/updates.ts | 5 +- src/components/common/Audio.tsx | 4 +- src/components/common/ReportMessageModal.tsx | 2 +- src/components/left/LeftColumn.tsx | 4 +- src/components/left/main/ChatList.tsx | 2 +- .../settings/SettingsPrivacyBlockedUsers.tsx | 1 - ...SettingsPrivacyVisibilityExceptionList.tsx | 1 - src/components/main/Main.tsx | 2 +- src/components/middle/ContactGreeting.tsx | 1 - src/components/middle/MessageList.tsx | 2 +- src/components/middle/MiddleColumn.tsx | 1 - src/components/middle/NoMessages.tsx | 1 - .../middle/composer/InlineBotTooltip.tsx | 2 - .../middle/message/CommentButton.tsx | 1 - src/components/middle/message/Message.tsx | 1 - .../message/helpers/calculateAlbumLayout.ts | 1 - src/components/right/RightColumn.tsx | 1 - .../right/management/ManageChannel.tsx | 1 - .../management/ManageChatPrivacyType.tsx | 2 +- .../management/ManageGroupAdminRights.tsx | 1 - .../management/ManageGroupUserPermissions.tsx | 1 - .../ManageGroupUserPermissionsCreate.tsx | 1 - src/components/test/TestNoRedundancy.tsx | 31 ++++--- src/components/ui/InfiniteScroll.tsx | 15 ++-- src/components/ui/RippleEffect.tsx | 2 +- src/components/ui/Select.tsx | 1 - src/hooks/useHistoryBack.ts | 1 - src/hooks/useLang.ts | 4 +- src/hooks/useShowTransition.ts | 1 - src/lib/gramjs/client/auth.ts | 2 +- src/lib/rlottie/RLottie.ts | 4 +- src/lib/rlottie/rlottie.worker.ts | 2 +- src/lib/teact/teact-dom.ts | 2 + src/lib/teact/teact.ts | 7 +- src/lib/teact/teactn.tsx | 1 + src/modules/actions/api/chats.ts | 6 +- src/modules/actions/api/payments.ts | 1 - src/modules/actions/api/users.ts | 1 - src/modules/helpers/chats.ts | 1 - src/modules/helpers/messageMedia.ts | 1 - src/modules/helpers/payments.ts | 2 +- src/modules/reducers/bots.ts | 1 - src/modules/reducers/messages.ts | 1 - src/modules/reducers/users.ts | 1 - src/modules/selectors/payments.ts | 1 - src/serviceWorker/pushNotification.ts | 2 +- src/types/index.ts | 2 +- src/util/fastSmoothScroll.ts | 1 - src/util/files.ts | 2 +- src/util/moduleLoader.ts | 2 +- src/util/oggToWav.ts | 4 +- src/util/schedulers.ts | 4 +- src/util/voiceRecording.ts | 12 +-- src/util/webpToPng.ts | 11 +-- src/util/websync.ts | 2 +- tsconfig.json | 3 +- 67 files changed, 130 insertions(+), 154 deletions(-) create mode 100644 .eslintignore create mode 100755 .husky/pre-commit diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..38f8e886 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +dev diff --git a/.eslintrc b/.eslintrc index b05e5939..8b2c8010 100644 --- a/.eslintrc +++ b/.eslintrc @@ -42,12 +42,15 @@ "import/no-webpack-loader-syntax": "off", "react/prop-types": "off", "react/jsx-one-expression-per-line": "off", + "react/button-has-type": "off", + "react/require-default-props": "off", // Teact feature "react/style-prop-object": "off", "jsx-a11y/click-events-have-key-events": "off", "jsx-a11y/no-static-element-interactions": "off", "jsx-a11y/label-has-associated-control": "off", "jsx-a11y/anchor-is-valid": "off", + "jsx-a11y/no-noninteractive-element-to-interactive-role": "off", "no-async-without-await/no-async-without-await": 1, "@typescript-eslint/no-use-before-define": [ "error", @@ -57,9 +60,13 @@ ], "@typescript-eslint/camelcase": "off", "@typescript-eslint/member-delimiter-style": "error", + "@typescript-eslint/no-throw-literal": "off", "teactn/prefer-separate-component-file": "off" }, "settings": { "import/resolver": "webpack" + }, + "parserOptions": { + "project": "./tsconfig.json" } } diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 00000000..77ff5eb6 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npx tsc && npx lint-staged diff --git a/package-lock.json b/package-lock.json index a65300d2..6c74cc54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4060,15 +4060,15 @@ } }, "@jest/types": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", - "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", + "version": "27.0.6", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-27.0.6.tgz", + "integrity": "sha512-aSquT1qa9Pik26JK5/3rvnYb4bGtm1VFNesHKmNTwmPIgOrixvhL2ghIvFRNEpzy3gU+rUgjIF/KodbkFAl++g==", "dev": true, "requires": { "@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-reports": "^3.0.0", "@types/node": "*", - "@types/yargs": "^15.0.0", + "@types/yargs": "^16.0.0", "chalk": "^4.0.0" }, "dependencies": { @@ -4478,13 +4478,13 @@ } }, "@types/jest": { - "version": "27.0.0", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-27.0.0.tgz", - "integrity": "sha512-IlpQZVpxufe+3qPaAqEoSPHVSxnJh1cf0BqqWHJeKiAUbwnHdmNzjP3ZCWSZSTbmAGXQPNk9QmM3Bif0pR54rg==", + "version": "27.0.1", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-27.0.1.tgz", + "integrity": "sha512-HTLpVXHrY69556ozYkcq47TtQJXpcWAWfkoqz+ZGz2JnmZhzlRjprCIyFnetSy8gpDWwTTGBcRVv1J1I1vBrHw==", "dev": true, "requires": { - "jest-diff": "^26.0.0", - "pretty-format": "^26.0.0" + "jest-diff": "^27.0.0", + "pretty-format": "^27.0.0" } }, "@types/json-schema": { @@ -4583,9 +4583,9 @@ } }, "@types/yargs": { - "version": "15.0.14", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.14.tgz", - "integrity": "sha512-yEJzHoxf6SyQGhBhIYGXQDSCkJjB6HohDShto7m8vaKg9Yp0Yn8+71J9eakh2bnPg6BfsH9PRMhiRTZnd4eXGQ==", + "version": "16.0.4", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz", + "integrity": "sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==", "dev": true, "requires": { "@types/yargs-parser": "*" @@ -7121,9 +7121,9 @@ "dev": true }, "diff-sequences": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-26.6.2.tgz", - "integrity": "sha512-Mv/TDa3nZ9sbc5soK+OoA74BsS3mL37yixCvUAQkiuA4Wz6YtwP/K47n2rv2ovzHZvoiQeA5FTQOschKkEwB0Q==", + "version": "27.0.6", + "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-27.0.6.tgz", + "integrity": "sha512-ag6wfpBFyNXZ0p8pcuIDS//D8H062ZQJ3fzYxjpmeKjnz8W4pekL3AI8VohmyZmsWW2PWaHgjsmqR6L13101VQ==", "dev": true }, "dir-glob": { @@ -11580,15 +11580,15 @@ } }, "jest-diff": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-26.6.2.tgz", - "integrity": "sha512-6m+9Z3Gv9wN0WFVasqjCL/06+EFCMTqDEUl/b87HYK2rAPTyfz4ZIuSlPhY51PIQRWx5TaxeF1qmXKe9gfN3sA==", + "version": "27.0.6", + "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-27.0.6.tgz", + "integrity": "sha512-Z1mqgkTCSYaFgwTlP/NUiRzdqgxmmhzHY1Tq17zL94morOHfHu3K4bgSgl+CR4GLhpV8VxkuOYuIWnQ9LnFqmg==", "dev": true, "requires": { "chalk": "^4.0.0", - "diff-sequences": "^26.6.2", - "jest-get-type": "^26.3.0", - "pretty-format": "^26.6.2" + "diff-sequences": "^27.0.6", + "jest-get-type": "^27.0.6", + "pretty-format": "^27.0.6" }, "dependencies": { "ansi-styles": { @@ -11951,9 +11951,9 @@ } }, "jest-get-type": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-26.3.0.tgz", - "integrity": "sha512-TpfaviN1R2pQWkIihlfEanwOXK0zcxrKEE4MlU6Tn7keoXdN6/3gK/xl0yEh8DOunn5pOVGKf8hB4R9gVh04ig==", + "version": "27.0.6", + "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-27.0.6.tgz", + "integrity": "sha512-XTkK5exIeUbbveehcSR8w0bhH+c0yloW/Wpl+9vZrjzztCPWrxhHwkIFpZzCt71oRBsgxmuUfxEqOYoZI2macg==", "dev": true }, "jest-haste-map": { @@ -16230,14 +16230,14 @@ } }, "pretty-format": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", - "integrity": "sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==", + "version": "27.0.6", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.0.6.tgz", + "integrity": "sha512-8tGD7gBIENgzqA+UBzObyWqQ5B778VIFZA/S66cclyd5YkFLYs2Js7gxDKf0MXtTc9zcS7t1xhdfcElJ3YIvkQ==", "dev": true, "requires": { - "@jest/types": "^26.6.2", + "@jest/types": "^27.0.6", "ansi-regex": "^5.0.0", - "ansi-styles": "^4.0.0", + "ansi-styles": "^5.0.0", "react-is": "^17.0.1" }, "dependencies": { @@ -16248,27 +16248,9 @@ "dev": true }, "ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "requires": { - "color-convert": "^2.0.1" - } - }, - "color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "requires": { - "color-name": "~1.1.4" - } - }, - "color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", + "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", "dev": true }, "react-is": { diff --git a/package.json b/package.json index a3c7c837..9af7c127 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@types/croppie": "^2.6.1", "@types/css-font-loading-module": "0.0.6", "@types/dom-mediacapture-record": "^1.0.10", - "@types/jest": "^27.0.0", + "@types/jest": "^27.0.1", "@types/react": "^17.0.17", "@types/react-dom": "^17.0.9", "@types/resize-observer-browser": "^0.1.6", diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 38536286..0b85686c 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -56,9 +56,15 @@ declare module 'pako/dist/pako_inflate' { type WindowWithPerf = typeof window & { perf: AnyLiteral }; +interface TEncodedImage { + result: Uint8ClampedArray; + width: number; + height: number; +} + interface IWebpWorker extends Worker { wasmReady?: boolean; - requests: Map) => void>; + requests: Map) => void>; } interface Window { diff --git a/src/api/gramjs/apiBuilders/messages.ts b/src/api/gramjs/apiBuilders/messages.ts index 1e6bffc1..2116946b 100644 --- a/src/api/gramjs/apiBuilders/messages.ts +++ b/src/api/gramjs/apiBuilders/messages.ts @@ -463,7 +463,6 @@ function buildPollFromMedia(media: GramJs.TypeMessageMedia): ApiPoll | undefined return buildPoll(media.poll, media.results); } - function buildInvoiceFromMedia(media: GramJs.TypeMessageMedia): ApiInvoice | undefined { if (!(media instanceof GramJs.MessageMediaInvoice)) { return undefined; diff --git a/src/api/gramjs/methods/chats.ts b/src/api/gramjs/methods/chats.ts index 3ce53b92..2d4f963c 100644 --- a/src/api/gramjs/methods/chats.ts +++ b/src/api/gramjs/methods/chats.ts @@ -75,7 +75,6 @@ export async function fetchChats({ return undefined; } - if (resultPinned) { updateLocalDb(resultPinned); } diff --git a/src/api/gramjs/methods/client.ts b/src/api/gramjs/methods/client.ts index 113b97da..cc2b08f3 100644 --- a/src/api/gramjs/methods/client.ts +++ b/src/api/gramjs/methods/client.ts @@ -185,7 +185,7 @@ export async function invokeRequest( let updatesContainer; if (result instanceof GramJs.Updates || result instanceof GramJs.UpdatesCombined) { updatesContainer = result; - } else if ('updates' in result && ( + } else if ('updates' in (result as ResultWithUpdates) && ( (result as ResultWithUpdates).updates instanceof GramJs.Updates || (result as ResultWithUpdates).updates instanceof GramJs.UpdatesCombined )) { diff --git a/src/api/gramjs/updater.ts b/src/api/gramjs/updater.ts index 9bd98358..919c54ac 100644 --- a/src/api/gramjs/updater.ts +++ b/src/api/gramjs/updater.ts @@ -582,6 +582,7 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) { typingStatus: buildChatTypingStatus(update, serverTimeOffset), }); } else if (update instanceof GramJs.UpdateChannel) { + // eslint-disable-next-line @typescript-eslint/naming-convention const { _entities } = update; if (!_entities) { return; @@ -690,6 +691,7 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) { user: { phoneNumber: phone }, }); } else if (update instanceof GramJs.UpdatePeerSettings) { + // eslint-disable-next-line @typescript-eslint/naming-convention const { _entities } = update; if (!_entities) { return; diff --git a/src/api/types/bots.ts b/src/api/types/bots.ts index 06d72c52..3b6a8ac4 100644 --- a/src/api/types/bots.ts +++ b/src/api/types/bots.ts @@ -4,7 +4,7 @@ import { export type ApiInlineResultType = ( 'article' | 'audio' | 'contact' | 'document' | 'game' | 'gif' | 'location' | 'mpeg4_gif' | - 'photo' | 'sticker'| 'venue' | 'video' | 'voice' + 'photo' | 'sticker' | 'venue' | 'video' | 'voice' ); export interface ApiWebDocument { diff --git a/src/api/types/updates.ts b/src/api/types/updates.ts index 03744ebd..6b387855 100644 --- a/src/api/types/updates.ts +++ b/src/api/types/updates.ts @@ -365,7 +365,7 @@ export type ApiUpdateNotifyExceptions = { '@type': 'updateNotifyExceptions'; } & ApiNotifyException; -export type updateTwoFaStateWaitCode = { +export type ApiUpdateTwoFaStateWaitCode = { '@type': 'updateTwoFaStateWaitCode'; length: number; }; @@ -393,7 +393,6 @@ export type ApiUpdateServerTimeOffset = { serverTimeOffset: number; }; - export type ApiUpdate = ( ApiUpdateReady | ApiUpdateSession | ApiUpdateAuthorizationState | ApiUpdateAuthorizationError | ApiUpdateConnectionState | ApiUpdateCurrentUser | @@ -409,7 +408,7 @@ export type ApiUpdate = ( ApiUpdateFavoriteStickers | ApiUpdateStickerSet | ApiUpdateNewScheduledMessage | ApiUpdateScheduledMessageSendSucceeded | ApiUpdateScheduledMessage | ApiUpdateDeleteScheduledMessages | ApiUpdateResetMessages | - ApiUpdateTwoFaError | updateTwoFaStateWaitCode | + ApiUpdateTwoFaError | ApiUpdateTwoFaStateWaitCode | ApiUpdateNotifySettings | ApiUpdateNotifyExceptions | ApiUpdatePeerBlocked | ApiUpdatePrivacy | ApiUpdateServerTimeOffset | ApiUpdateShowInvite ); diff --git a/src/components/common/Audio.tsx b/src/components/common/Audio.tsx index a3c986ac..fa64a114 100644 --- a/src/components/common/Audio.tsx +++ b/src/components/common/Audio.tsx @@ -217,8 +217,8 @@ const Audio: FC = ({ const seekHandlers = { handleStartSeek, handleSeek, handleStopSeek }; const isOwn = isOwnMessage(message); const renderedWaveform = useMemo( - () => voice && renderWaveform(voice, playProgress, isOwn, seekHandlers, theme), - [voice, playProgress, isOwn, seekHandlers, theme], + () => voice && renderWaveform(voice, playProgress, isOwn, { handleStartSeek, handleSeek, handleStopSeek }, theme), + [voice, playProgress, isOwn, handleStartSeek, handleSeek, handleStopSeek, theme], ); const fullClassName = buildClassName( diff --git a/src/components/common/ReportMessageModal.tsx b/src/components/common/ReportMessageModal.tsx index 592f0dce..bd1e5fda 100644 --- a/src/components/common/ReportMessageModal.tsx +++ b/src/components/common/ReportMessageModal.tsx @@ -51,7 +51,7 @@ const ReportMessageModal: FC = ({ const lang = useLang(); - const REPORT_OPTIONS: {value: ApiReportReason; label: string}[] = [ + const REPORT_OPTIONS: { value: ApiReportReason; label: string }[] = [ { value: 'spam', label: lang('lng_report_reason_spam') }, { value: 'violence', label: lang('lng_report_reason_violence') }, { value: 'pornography', label: lang('lng_report_reason_pornography') }, diff --git a/src/components/left/LeftColumn.tsx b/src/components/left/LeftColumn.tsx index c989160e..20802f29 100644 --- a/src/components/left/LeftColumn.tsx +++ b/src/components/left/LeftColumn.tsx @@ -33,13 +33,13 @@ type DispatchProps = Pick = ({ diff --git a/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx b/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx index ec57695b..d6e13a02 100644 --- a/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx +++ b/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx @@ -130,7 +130,6 @@ const SettingsPrivacyBlockedUsers: FC = ( ); }; - export default memo(withGlobal( (global): StateProps => { const { diff --git a/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx b/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx index 884aae77..c030b433 100644 --- a/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx +++ b/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx @@ -129,7 +129,6 @@ const SettingsPrivacyVisibilityExceptionList: FC = ({ @@ -135,7 +136,6 @@ const Main: FC = ({ transitionClassNames: rightColumnTransitionClassNames, } = useShowTransition(isRightColumnShown, undefined, true, undefined, shouldSkipHistoryAnimations); - const className = buildClassName( middleColumnTransitionClassNames.replace(/([\w-]+)/g, 'middle-column-$1'), rightColumnTransitionClassNames.replace(/([\w-]+)/g, 'right-column-$1'), diff --git a/src/components/middle/ContactGreeting.tsx b/src/components/middle/ContactGreeting.tsx index c5042f3b..94164c39 100644 --- a/src/components/middle/ContactGreeting.tsx +++ b/src/components/middle/ContactGreeting.tsx @@ -91,7 +91,6 @@ const ContactGreeting: FC = ({ ); }; - export default memo(withGlobal( (global, { userId }): StateProps => { const { stickers } = global.stickers.greeting; diff --git a/src/components/middle/MessageList.tsx b/src/components/middle/MessageList.tsx index 4d593245..508eb65e 100644 --- a/src/components/middle/MessageList.tsx +++ b/src/components/middle/MessageList.tsx @@ -300,7 +300,7 @@ const MessageList: FC = ({ useLayoutEffectWithPrevDeps(([ prevMessageIds, prevIsViewportNewest, prevContainerHeight, ]: [ - typeof messageIds, typeof isViewportNewest, typeof containerHeight + typeof messageIds, typeof isViewportNewest, typeof containerHeight, ]) => { const container = containerRef.current!; listItemElementsRef.current = Array.from(container.querySelectorAll('.message-list-item')); diff --git a/src/components/middle/MiddleColumn.tsx b/src/components/middle/MiddleColumn.tsx index 8f39ae1e..3cbe2850 100644 --- a/src/components/middle/MiddleColumn.tsx +++ b/src/components/middle/MiddleColumn.tsx @@ -239,7 +239,6 @@ const MiddleColumn: FC = ({ !isSelectModeActive && 'shown', ); - const messageSendingRestrictionReason = getMessageSendingRestrictionReason( lang, currentUserBannedRights, defaultBannedRights, ); diff --git a/src/components/middle/NoMessages.tsx b/src/components/middle/NoMessages.tsx index 0d7e471e..e9c8e4af 100644 --- a/src/components/middle/NoMessages.tsx +++ b/src/components/middle/NoMessages.tsx @@ -75,5 +75,4 @@ function renderGroup(lang: LangFn) { ); } - export default memo(NoMessages); diff --git a/src/components/middle/composer/InlineBotTooltip.tsx b/src/components/middle/composer/InlineBotTooltip.tsx index 7ff81396..669feab3 100644 --- a/src/components/middle/composer/InlineBotTooltip.tsx +++ b/src/components/middle/composer/InlineBotTooltip.tsx @@ -110,7 +110,6 @@ const InlineBotTooltip: FC = ({ } }, [loadMore]); - useEffect(() => (isOpen ? captureKeyboardListeners({ onEsc: onClose, onUp: (e: KeyboardEvent) => handleArrowKey(-1, e), @@ -123,7 +122,6 @@ const InlineBotTooltip: FC = ({ sendBotCommand({ chatId: botId, command: `/start ${switchPm!.startParam}` }); }, [botId, openChat, sendBotCommand, switchPm]); - const prevInlineBotResults = usePrevious( inlineBotResults && inlineBotResults.length ? inlineBotResults diff --git a/src/components/middle/message/CommentButton.tsx b/src/components/middle/message/CommentButton.tsx index a035b800..a34908ba 100644 --- a/src/components/middle/message/CommentButton.tsx +++ b/src/components/middle/message/CommentButton.tsx @@ -51,7 +51,6 @@ const CommentButton: FC = ({ openChat({ id: chatId, threadId }); }, [openChat, chatId, threadId]); - useEffect(() => { if (shouldRequestThreadUpdate) { requestThreadInfoUpdate({ chatId, threadId }); diff --git a/src/components/middle/message/Message.tsx b/src/components/middle/message/Message.tsx index fb61ea63..998f41dc 100644 --- a/src/components/middle/message/Message.tsx +++ b/src/components/middle/message/Message.tsx @@ -241,7 +241,6 @@ const Message: FC = ({ const appendixRef = useRef(null); const lang = useLang(); - useOnIntersect(bottomMarkerRef, observeIntersectionForBottom); const { diff --git a/src/components/middle/message/helpers/calculateAlbumLayout.ts b/src/components/middle/message/helpers/calculateAlbumLayout.ts index 9acdaeab..7e89ddeb 100644 --- a/src/components/middle/message/helpers/calculateAlbumLayout.ts +++ b/src/components/middle/message/helpers/calculateAlbumLayout.ts @@ -261,7 +261,6 @@ function layoutWithComplexLayouter({ return result; } - function layoutTwo(params: ILayoutParams) { const { ratios, diff --git a/src/components/right/RightColumn.tsx b/src/components/right/RightColumn.tsx index cc89fbf4..3d0bbc43 100644 --- a/src/components/right/RightColumn.tsx +++ b/src/components/right/RightColumn.tsx @@ -205,7 +205,6 @@ const RightColumn: FC = ({ } }, [contentKey, chatId]); - useHistoryBack(isChatSelected && (contentKey === RightColumnContent.ChatInfo || contentKey === RightColumnContent.UserInfo || contentKey === RightColumnContent.Management || contentKey === RightColumnContent.AddingMembers), diff --git a/src/components/right/management/ManageChannel.tsx b/src/components/right/management/ManageChannel.tsx index 706d7d9f..48b6230c 100644 --- a/src/components/right/management/ManageChannel.tsx +++ b/src/components/right/management/ManageChannel.tsx @@ -139,7 +139,6 @@ const ManageChannel: FC = ({ onScreenSelect(ManagementScreens.ChannelSubscribers); }, [onScreenSelect]); - const handleDeleteChannel = useCallback(() => { if (chat.isCreator) { deleteChannel({ chatId: chat.id }); diff --git a/src/components/right/management/ManageChatPrivacyType.tsx b/src/components/right/management/ManageChatPrivacyType.tsx index 5f760d1c..eccfda0e 100644 --- a/src/components/right/management/ManageChatPrivacyType.tsx +++ b/src/components/right/management/ManageChatPrivacyType.tsx @@ -60,7 +60,7 @@ const ManageChatPrivacyType: FC = ({ const [username, setUsername] = useState(); const [isRevokeConfirmDialogOpen, openRevokeConfirmDialog, closeRevokeConfirmDialog] = useFlag(); - const canUpdate = ( + const canUpdate = Boolean( (privacyType === 'public' && username && isUsernameAvailable) || (privacyType === 'private' && isPublic) ); diff --git a/src/components/right/management/ManageGroupAdminRights.tsx b/src/components/right/management/ManageGroupAdminRights.tsx index cb2bbfce..74a551f0 100644 --- a/src/components/right/management/ManageGroupAdminRights.tsx +++ b/src/components/right/management/ManageGroupAdminRights.tsx @@ -333,7 +333,6 @@ const ManageGroupAdminRights: FC = ({ ); }; - export default memo(withGlobal( (global, { chatId, isPromotedByCurrentUser }): StateProps => { const chat = selectChat(global, chatId)!; diff --git a/src/components/right/management/ManageGroupUserPermissions.tsx b/src/components/right/management/ManageGroupUserPermissions.tsx index 66e23f65..bc84f94b 100644 --- a/src/components/right/management/ManageGroupUserPermissions.tsx +++ b/src/components/right/management/ManageGroupUserPermissions.tsx @@ -259,7 +259,6 @@ const ManageGroupUserPermissions: FC = ({ ); }; - export default memo(withGlobal( (global, { chatId, isPromotedByCurrentUser }): StateProps => { const chat = selectChat(global, chatId)!; diff --git a/src/components/right/management/ManageGroupUserPermissionsCreate.tsx b/src/components/right/management/ManageGroupUserPermissionsCreate.tsx index 064e6dba..c28286ba 100644 --- a/src/components/right/management/ManageGroupUserPermissionsCreate.tsx +++ b/src/components/right/management/ManageGroupUserPermissionsCreate.tsx @@ -85,7 +85,6 @@ const ManageGroupUserPermissionsCreate: FC = ({ ); }; - export default memo(withGlobal( (global, { chatId }): StateProps => { const chat = selectChat(global, chatId); diff --git a/src/components/test/TestNoRedundancy.tsx b/src/components/test/TestNoRedundancy.tsx index c1b2de23..5474381a 100644 --- a/src/components/test/TestNoRedundancy.tsx +++ b/src/components/test/TestNoRedundancy.tsx @@ -25,21 +25,6 @@ type BOwnProps = Pick & { aValue: number; }; -const TestA: FC = ({ aValue }) => { - // eslint-disable-next-line no-console - console.log('!!! A MOUNT ', { aValue }); - - return ( -
-

A

-
- aValue = {aValue} -
- -
- ); -}; - const TestB: FC = ({ bValue, aValue, derivedAValue }) => { // eslint-disable-next-line no-console console.log('!!! B MOUNT ', { bValue, aValue, derivedAValue }); @@ -65,7 +50,6 @@ const TestB: FC = ({ bValue, aValue, derivedAValue }) = ); }; - const TestBContainer = withGlobal( (global, { aValue }): BStateProps => { // eslint-disable-next-line no-console @@ -79,6 +63,21 @@ const TestBContainer = withGlobal( }, )(TestB); +const TestA: FC = ({ aValue }) => { + // eslint-disable-next-line no-console + console.log('!!! A MOUNT ', { aValue }); + + return ( +
+

A

+
+ aValue = {aValue} +
+ +
+ ); +}; + export default withGlobal( (global): AStateProps => { // @ts-ignore diff --git a/src/components/ui/InfiniteScroll.tsx b/src/components/ui/InfiniteScroll.tsx index ebc112d9..1e11cda6 100644 --- a/src/components/ui/InfiniteScroll.tsx +++ b/src/components/ui/InfiniteScroll.tsx @@ -54,11 +54,11 @@ const InfiniteScroll: FC = ({ } const stateRef = useRef<{ - listItemElements: NodeListOf; - isScrollTopJustUpdated: boolean; - currentAnchor: HTMLDivElement | undefined; - currentAnchorTop: number; - }>({} as any); + listItemElements?: NodeListOf; + isScrollTopJustUpdated?: boolean; + currentAnchor?: HTMLDivElement | undefined; + currentAnchorTop?: number; + }>({}); const [loadMoreBackwards, loadMoreForwards] = useMemo(() => { if (!onLoadMore) { @@ -105,7 +105,7 @@ const InfiniteScroll: FC = ({ if (state.currentAnchor && Array.from(state.listItemElements).includes(state.currentAnchor)) { const { scrollTop } = container; const newAnchorTop = state.currentAnchor.getBoundingClientRect().top; - newScrollTop = scrollTop + (newAnchorTop - state.currentAnchorTop); + newScrollTop = scrollTop + (newAnchorTop - state.currentAnchorTop!); } else { const nextAnchor = state.listItemElements[0]; if (nextAnchor) { @@ -130,8 +130,9 @@ const InfiniteScroll: FC = ({ const handleScroll = useCallback((e: UIEvent) => { if (loadMoreForwards && loadMoreBackwards) { const { - listItemElements, isScrollTopJustUpdated, currentAnchor, currentAnchorTop, + isScrollTopJustUpdated, currentAnchor, currentAnchorTop, } = stateRef.current; + const listItemElements = stateRef.current.listItemElements!; if (isScrollTopJustUpdated) { stateRef.current.isScrollTopJustUpdated = false; diff --git a/src/components/ui/RippleEffect.tsx b/src/components/ui/RippleEffect.tsx index 8c41bb3c..013743ea 100644 --- a/src/components/ui/RippleEffect.tsx +++ b/src/components/ui/RippleEffect.tsx @@ -48,7 +48,7 @@ const RippleEffect: FC = () => { return (
- {ripples.map(({ x, y, size }: Ripple) => ( + {ripples.map(({ x, y, size }) => ( (): LangFn => { +export default (): LangFn => { const forceUpdate = useForceUpdate(); useOnChange(() => { diff --git a/src/hooks/useShowTransition.ts b/src/hooks/useShowTransition.ts index 54c5ac0d..4f7f02c8 100644 --- a/src/hooks/useShowTransition.ts +++ b/src/hooks/useShowTransition.ts @@ -15,7 +15,6 @@ export default ( // СSS class should be added in a separate tick to turn on CSS transition. const [hasOpenClassName, setHasOpenClassName] = useState(isOpen && noOpenTransition); - if (isOpen) { setIsClosed(false); setHasOpenClassName(true); diff --git a/src/lib/gramjs/client/auth.ts b/src/lib/gramjs/client/auth.ts index ac91e0a9..065ac251 100644 --- a/src/lib/gramjs/client/auth.ts +++ b/src/lib/gramjs/client/auth.ts @@ -208,7 +208,7 @@ async function signInUserWithQrCode( } })(); - const updatePromise = new Promise((resolve) => { + const updatePromise = new Promise((resolve) => { client.addEventHandler((update: Api.TypeUpdate) => { if (update instanceof Api.UpdateLoginToken) { resolve(); diff --git a/src/lib/rlottie/RLottie.ts b/src/lib/rlottie/RLottie.ts index d8b823fa..992d0a33 100644 --- a/src/lib/rlottie/RLottie.ts +++ b/src/lib/rlottie/RLottie.ts @@ -27,7 +27,9 @@ const LOW_PRIORITY_MAX_FPS = 30; const HIGH_PRIORITY_CACHE_MODULO = IS_SAFARI ? 2 : 4; const LOW_PRIORITY_CACHE_MODULO = 0; -const workers = new Array(MAX_WORKERS).fill(undefined).map(() => new WorkerConnector(new Worker(new URL('./rlottie.worker.ts', import.meta.url)))); +const workers = new Array(MAX_WORKERS).fill(undefined).map( + () => new WorkerConnector(new Worker(new URL('./rlottie.worker.ts', import.meta.url))), +); let lastWorkerIndex = -1; class RLottie { diff --git a/src/lib/rlottie/rlottie.worker.ts b/src/lib/rlottie/rlottie.worker.ts index fc58f190..24606306 100644 --- a/src/lib/rlottie/rlottie.worker.ts +++ b/src/lib/rlottie/rlottie.worker.ts @@ -12,7 +12,7 @@ declare const self: WorkerGlobalScope; self.importScripts('rlottie-wasm.js'); let rLottieApi: Record; -const rLottieApiPromise = new Promise((resolve) => { +const rLottieApiPromise = new Promise((resolve) => { Module.onRuntimeInitialized = () => { rLottieApi = { init: Module.cwrap('lottie_init', '', []), diff --git a/src/lib/teact/teact-dom.ts b/src/lib/teact/teact-dom.ts index d63c6cde..83ed5207 100644 --- a/src/lib/teact/teact-dom.ts +++ b/src/lib/teact/teact-dom.ts @@ -30,6 +30,7 @@ const MAPPED_ATTRIBUTES: { [k: string]: string } = { const INDEX_KEY_PREFIX = '__indexKey#'; const headsByElement: Record = {}; +// eslint-disable-next-line @typescript-eslint/naming-convention let DEBUG_virtualTreeSize = 1; function render($element?: VirtualElement, parentEl?: HTMLElement | null) { @@ -462,6 +463,7 @@ function updateAttribute(element: HTMLElement, key: string, oldValue: any, newVa } } +// eslint-disable-next-line @typescript-eslint/naming-convention function DEBUG_addToVirtualTreeSize($current: VirtualRealElement | VirtualDomHead) { DEBUG_virtualTreeSize += $current.children.length; diff --git a/src/lib/teact/teact.ts b/src/lib/teact/teact.ts index 351cb741..1e5bdf08 100644 --- a/src/lib/teact/teact.ts +++ b/src/lib/teact/teact.ts @@ -9,11 +9,12 @@ import { removeAllDelegatedListeners } from './dom-events'; export type Props = AnyLiteral; export type FC

= (props: P) => any; +// eslint-disable-next-line @typescript-eslint/naming-convention export type FC_withDebug = FC & { - DEBUG_contentComponentName?: string; -}; + DEBUG_contentComponentName?: string; + }; export enum VirtualElementTypesEnum { Empty, @@ -243,6 +244,7 @@ function buildEmptyElement(): VirtualElementEmpty { return { type: VirtualElementTypesEnum.Empty }; } +// eslint-disable-next-line @typescript-eslint/naming-convention const DEBUG_components: AnyLiteral = {}; document.addEventListener('dblclick', () => { @@ -260,6 +262,7 @@ export function renderComponent(componentInstance: ComponentInstance) { let newRenderedValue; try { + // eslint-disable-next-line @typescript-eslint/naming-convention let DEBUG_startAt: number | undefined; if (DEBUG) { const componentName = componentInstance.name; diff --git a/src/lib/teact/teactn.tsx b/src/lib/teact/teactn.tsx index 1dc78b6d..1000ea6b 100644 --- a/src/lib/teact/teactn.tsx +++ b/src/lib/teact/teactn.tsx @@ -78,6 +78,7 @@ function onDispatch(name: string, payload?: ActionPayload, noThrottle?: boolean) } function updateContainers() { + // eslint-disable-next-line @typescript-eslint/naming-convention let DEBUG_startAt: number | undefined; if (DEBUG) { DEBUG_startAt = performance.now(); diff --git a/src/modules/actions/api/chats.ts b/src/modules/actions/api/chats.ts index 0846dcba..85e584e9 100644 --- a/src/modules/actions/api/chats.ts +++ b/src/modules/actions/api/chats.ts @@ -237,7 +237,7 @@ addReducer('joinChannel', (global, actions, payload) => { addReducer('deleteChatUser', (global, actions, payload) => { (async () => { - const { chatId, userId } : {chatId: number; userId: number} = payload!; + const { chatId, userId } : { chatId: number; userId: number } = payload!; const chat = selectChat(global, chatId); const user = selectUser(global, userId); if (!chat || !user) { @@ -254,7 +254,7 @@ addReducer('deleteChatUser', (global, actions, payload) => { addReducer('deleteChat', (global, actions, payload) => { (async () => { - const { chatId } : {chatId: number } = payload!; + const { chatId } : { chatId: number } = payload!; const chat = selectChat(global, chatId); if (!chat) { return; @@ -742,7 +742,6 @@ addReducer('unlinkDiscussionGroup', (global, actions, payload) => { })(); }); - addReducer('setActiveChatFolder', (global, actions, payload) => { return { ...global, @@ -857,7 +856,6 @@ async function loadChats(listType: 'active' | 'archived', offsetId?: number, off ); }); - if (chatIds.length === 0 && !global.chats.isFullyLoaded[listType]) { global = { ...global, diff --git a/src/modules/actions/api/payments.ts b/src/modules/actions/api/payments.ts index b57f76bf..6a8cce91 100644 --- a/src/modules/actions/api/payments.ts +++ b/src/modules/actions/api/payments.ts @@ -71,7 +71,6 @@ addReducer('getPaymentForm', (global, actions, payload) => { void getPaymentForm(chat, messageId); }); - async function getPaymentForm(chat: ApiChat, messageId: number) { const result = await callApi('getPaymentForm', { chat, messageId }); if (!result) { diff --git a/src/modules/actions/api/users.ts b/src/modules/actions/api/users.ts index 4811b234..df0246a4 100644 --- a/src/modules/actions/api/users.ts +++ b/src/modules/actions/api/users.ts @@ -203,7 +203,6 @@ addReducer('loadProfilePhotos', (global, actions, payload) => { })(); }); - addReducer('setUserSearchQuery', (global, actions, payload) => { const { query } = payload!; diff --git a/src/modules/helpers/chats.ts b/src/modules/helpers/chats.ts index e2a05110..341d6c69 100644 --- a/src/modules/helpers/chats.ts +++ b/src/modules/helpers/chats.ts @@ -211,7 +211,6 @@ export function getChatSlowModeOptions(chat?: ApiChat) { return chat.fullInfo.slowMode; } - export function getChatOrder(chat: ApiChat) { return Math.max( chat.joinDate || 0, diff --git a/src/modules/helpers/messageMedia.ts b/src/modules/helpers/messageMedia.ts index d719aaaf..06d2c590 100644 --- a/src/modules/helpers/messageMedia.ts +++ b/src/modules/helpers/messageMedia.ts @@ -14,7 +14,6 @@ type Target = | 'viewerFull' | 'download'; - export function getMessageContent(message: ApiMessage) { return message.content; } diff --git a/src/modules/helpers/payments.ts b/src/modules/helpers/payments.ts index e980d3f5..223a16fb 100644 --- a/src/modules/helpers/payments.ts +++ b/src/modules/helpers/payments.ts @@ -47,5 +47,5 @@ export function getStripeError(error: { const { message: description, code, param } = error; const { field, message } = param ? STRIPE_ERRORS[param] : STRIPE_ERRORS[code]; - return { field, message, description}; + return { field, message, description }; } diff --git a/src/modules/reducers/bots.ts b/src/modules/reducers/bots.ts index dae4689c..ac4f8e9b 100644 --- a/src/modules/reducers/bots.ts +++ b/src/modules/reducers/bots.ts @@ -1,7 +1,6 @@ import { GlobalState } from '../../global/types'; import { InlineBotSettings } from '../../types'; - export function replaceInlineBotSettings( global: GlobalState, username: string, inlineBotSettings: InlineBotSettings | false, ): GlobalState { diff --git a/src/modules/reducers/messages.ts b/src/modules/reducers/messages.ts index 33c7351e..2193f9e5 100644 --- a/src/modules/reducers/messages.ts +++ b/src/modules/reducers/messages.ts @@ -228,7 +228,6 @@ export function deleteChatMessages( } }); - global = replaceThreadParam(global, chatId, threadId, 'listedIds', listedIds); global = replaceThreadParam(global, chatId, threadId, 'outlyingIds', outlyingIds); global = replaceThreadParam(global, chatId, threadId, 'viewportIds', viewportIds); diff --git a/src/modules/reducers/users.ts b/src/modules/reducers/users.ts index eb77ae8a..070d0a44 100644 --- a/src/modules/reducers/users.ts +++ b/src/modules/reducers/users.ts @@ -68,7 +68,6 @@ export function updateUser(global: GlobalState, userId: number, userUpdate: Part }); } - export function updateUsers(global: GlobalState, updatedById: Record): GlobalState { const updatedUsers = Object.keys(updatedById).map(Number).reduce>((acc, id) => { const updatedUser = getUpdatedUser(global, id, updatedById[id]); diff --git a/src/modules/selectors/payments.ts b/src/modules/selectors/payments.ts index 98c1afbe..330501d0 100644 --- a/src/modules/selectors/payments.ts +++ b/src/modules/selectors/payments.ts @@ -1,4 +1,3 @@ - import { GlobalState } from '../../global/types'; export function selectPaymentChatId(global: GlobalState) { diff --git a/src/serviceWorker/pushNotification.ts b/src/serviceWorker/pushNotification.ts index 97863e71..07518e2d 100644 --- a/src/serviceWorker/pushNotification.ts +++ b/src/serviceWorker/pushNotification.ts @@ -4,7 +4,7 @@ declare const self: ServiceWorkerGlobalScope; enum Boolean { True = '1', - False = '0' + False = '0', } type PushData = { diff --git a/src/types/index.ts b/src/types/index.ts index 52358bc7..ef8a0b87 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -278,7 +278,7 @@ export enum PaymentStep { ShippingInfo, Shipping, PaymentInfo, - Checkout + Checkout, } export const UPLOADING_WALLPAPER_SLUG = 'UPLOADING_WALLPAPER_SLUG'; diff --git a/src/util/fastSmoothScroll.ts b/src/util/fastSmoothScroll.ts index 74b786f9..94663ea2 100644 --- a/src/util/fastSmoothScroll.ts +++ b/src/util/fastSmoothScroll.ts @@ -29,7 +29,6 @@ export default function fastSmoothScroll( return; } - if (getGlobal().settings.byKey.animationLevel === ANIMATION_LEVEL_MIN) { forceDuration = 0; } diff --git a/src/util/files.ts b/src/util/files.ts index 878d4803..e80aa7d9 100644 --- a/src/util/files.ts +++ b/src/util/files.ts @@ -83,7 +83,7 @@ export async function createPosterForVideo(url: string): Promise, - new Promise((resolve, reject) => { + new Promise((resolve, reject) => { video.onseeked = () => { if (!video.videoWidth || !video.videoHeight) { resolve(undefined); diff --git a/src/util/moduleLoader.ts b/src/util/moduleLoader.ts index 43801784..0b8e8796 100644 --- a/src/util/moduleLoader.ts +++ b/src/util/moduleLoader.ts @@ -3,7 +3,7 @@ import { DEBUG } from '../config'; export enum Bundles { Auth, Main, - Extra + Extra, } interface ImportedBundles { diff --git a/src/util/oggToWav.ts b/src/util/oggToWav.ts index 109803a5..8a996d05 100644 --- a/src/util/oggToWav.ts +++ b/src/util/oggToWav.ts @@ -7,7 +7,9 @@ export async function oggToWav(opusData: Blob): Promise { return new Promise((resolve) => { const typedArray = new Uint8Array(arrayBuffer); - let decoderWorker: Worker | undefined = new Worker(new URL('opus-recorder/dist/decoderWorker.min.js', import.meta.url)); + let decoderWorker: Worker | undefined = new Worker( + new URL('opus-recorder/dist/decoderWorker.min.js', import.meta.url), + ); let wavWorker: Worker | undefined = new Worker(new URL('opus-recorder/dist/waveWorker.min.js', import.meta.url)); decoderWorker.onmessage = (e) => { diff --git a/src/util/schedulers.ts b/src/util/schedulers.ts index 837938cc..92b53655 100644 --- a/src/util/schedulers.ts +++ b/src/util/schedulers.ts @@ -122,12 +122,12 @@ function runNow(fn: NoneToVoidFunction) { fn(); } -export const pause = (ms: number) => new Promise((resolve) => { +export const pause = (ms: number) => new Promise((resolve) => { setTimeout(() => resolve(), ms); }); export function rafPromise() { - return new Promise((resolve) => { + return new Promise((resolve) => { fastRaf(resolve); }); } diff --git a/src/util/voiceRecording.ts b/src/util/voiceRecording.ts index c1c00c22..5165951e 100644 --- a/src/util/voiceRecording.ts +++ b/src/util/voiceRecording.ts @@ -3,8 +3,8 @@ import encoderPath from 'file-loader!opus-recorder/dist/encoderWorker.min'; export type Result = { blob: Blob; duration: number; waveform: number[] }; -interface OpusRecorder extends Omit { - new(options: AnyLiteral): OpusRecorder; +interface IOpusRecorder extends Omit { + new(options: AnyLiteral): IOpusRecorder; start(stream?: MediaStreamAudioSourceNode): void; @@ -19,9 +19,9 @@ const BLOB_PARAMS = { type: 'audio/ogg' }; const FFT_SIZE = 64; const MIN_VOLUME = 0.1; -let opusRecorderPromise: Promise<{ default: OpusRecorder }>; -let OpusRecorder: OpusRecorder; -let mediaRecorder: OpusRecorder; +let opusRecorderPromise: Promise<{ default: IOpusRecorder }>; +let OpusRecorder: IOpusRecorder; +let mediaRecorder: IOpusRecorder; export async function init() { if (!opusRecorderPromise) { @@ -84,7 +84,7 @@ async function startMediaRecorder() { await mediaRecorder.start(); } -function subscribeToAnalyzer(recorder: OpusRecorder, cb: Function) { +function subscribeToAnalyzer(recorder: IOpusRecorder, cb: Function) { const source = recorder.sourceNode; const analyser = source.context.createAnalyser(); analyser.fftSize = FFT_SIZE; diff --git a/src/util/webpToPng.ts b/src/util/webpToPng.ts index 909268de..655e2a9c 100644 --- a/src/util/webpToPng.ts +++ b/src/util/webpToPng.ts @@ -2,12 +2,6 @@ import { isWebpSupported } from './environment'; import { dataUriToBlob, blobToDataUri } from './files'; import { pause } from './schedulers'; -type TEncodedImage = { - result: Uint8ClampedArray; - width: number; - height: number; -}; - const WORKER_INITIALIZATION_TIMEOUT = 2000; let canvas: HTMLCanvasElement; @@ -96,7 +90,10 @@ function handleLibWebpMessage(e: MessageEvent) { function getDecodePromise(url: string, blob: Blob): Promise { return new Promise((resolve) => { - worker.requests = worker.requests || new Map(); + if (!worker.requests) { + worker.requests = new Map(); + } + worker.requests.set(url, resolve); worker.postMessage({ id: url, blob }); }); diff --git a/src/util/websync.ts b/src/util/websync.ts index 636afffa..3037d99b 100644 --- a/src/util/websync.ts +++ b/src/util/websync.ts @@ -31,7 +31,7 @@ export const forceWebsync = (authed: boolean) => { if (canRedirect !== authed || ts + WEBSYNC_TIMEOUT <= currentTs) { return Promise.all(WEBSYNC_URLS.map((url) => { - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { const script = document.createElement('script'); const removeElement = () => !!document.body.removeChild(script); diff --git a/tsconfig.json b/tsconfig.json index 1b318180..48637f4f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,6 +21,7 @@ "jsx": "react" }, "include": [ - "src" + "src", + "tests" ] }