Browse Source

Add missing react types, fix typing for linkEvent

unoptim
GreatBearShark 2 years ago
parent
commit
bbda634582
  1. 2
      .eslintignore
  2. 12
      package.json
  3. 12
      src/components/main.tsx
  4. 2
      src/index.tsx
  5. 13
      src/linkEvent.ts
  6. 41
      yarn.lock

2
.eslintignore

@ -1,3 +1,3 @@
fuse.js
translation_report.ts
src/api_tests
src/api_tests

12
package.json

@ -7,13 +7,13 @@
"main": "index.js",
"scripts": {
"api-test": "jest src/api_tests/api.spec.ts",
"build": "parcel build ./src/index.html",
"build_old": "node fuse prod",
"lint": "tsc --noEmit && eslint --report-unused-disable-directives --ext .js,.ts,.tsx src",
"prebuild": "node generate_translations.js",
"prestart": "node generate_translations.js",
"start_old": "node fuse dev",
"start": "parcel serve ./src/index.html -p 4444",
"build": "parcel build ./src/index.html"
"start": "node generate_translations.js && parcel serve ./src/index.html -p 4444",
"start_old": "node fuse dev"
},
"keywords": [],
"dependencies": {
@ -23,7 +23,9 @@
"@types/jwt-decode": "^2.2.1",
"@types/markdown-it": "^0.0.9",
"@types/markdown-it-container": "^2.0.2",
"@types/node": "^13.11.1",
"@types/node": "^14.0.27",
"@types/react": "^16.9.44",
"@types/react-dom": "^16.9.8",
"autosize": "^4.0.2",
"body-scroll-lock": "^3.0.3",
"bootswatch": "^4.3.1",
@ -62,7 +64,7 @@
"ws": "^7.2.3"
},
"devDependencies": {
"@types/jest": "^25.2.1",
"@types/jest": "^26.0.8",
"@types/node-fetch": "^2.5.6",
"eslint": "^6.5.1",
"eslint-plugin-inferno": "^7.14.3",

12
src/components/main.tsx

@ -54,7 +54,7 @@ import {
setupTippy,
} from '../utils';
import { i18n } from '../i18next';
import { Trans } from 'react-i18next';
import { Trans, withTranslation } from 'react-i18next';
import { PATREON_URL } from '../constants';
import { Icon } from './icon';
import { linkEvent } from '../linkEvent';
@ -99,7 +99,7 @@ interface UrlParams {
page?: number;
}
export class Main extends Component<any, MainState> {
class Main extends Component<any, MainState> {
private subscription: Subscription;
private emptyState: MainState = {
subscribedCommunities: [],
@ -195,7 +195,7 @@ export class Main extends Component<any, MainState> {
render() {
return (
<div className="container" style={{ 'maxWidth': '100%' }}>
<div className="container" style={{ maxWidth: '100%' }}>
<div className="row">
<main role="main" className="col-12 col-md-8">
{this.posts()}
@ -227,7 +227,7 @@ export class Main extends Component<any, MainState> {
</h5>
<ul className="list-inline">
{this.state.subscribedCommunities.map(community => (
<li id={community.id} className="list-inline-item">
<li key={community.id} className="list-inline-item">
<CommunityLink
community={{
name: community.community_name,
@ -377,7 +377,7 @@ export class Main extends Component<any, MainState> {
<ul className="mt-1 list-inline small mb-0">
<li className="list-inline-item">{i18n.t('admins')}:</li>
{this.state.siteRes.admins.map(admin => (
<li className="list-inline-item">
<li key={admin.id} className="list-inline-item">
<UserListing
user={{
name: admin.name,
@ -804,3 +804,5 @@ export class Main extends Component<any, MainState> {
}
}
}
export default withTranslation()(Main);

2
src/index.tsx

@ -12,7 +12,7 @@ import React, { Component } from 'react';
import { render } from 'react-dom';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import { I18nextProvider } from 'react-i18next';
import { Main } from './components/main';
import Main from './components/main';
import { Navbar } from './components/navbar';
import { Footer } from './components/footer';
import { Login } from './components/login';

13
src/linkEvent.ts

@ -3,7 +3,7 @@
// helpers from inferno-shared
// https://github.com/infernojs/inferno/blob/master/packages/inferno-shared/src/index.ts
export function isFunction(o: any): o is Function {
return typeof o === "function";
return typeof o === 'function';
}
export function isNull(o: any): o is null {
@ -23,15 +23,16 @@ export interface LinkedEvent<T, E extends Event> {
*/
export function linkEvent<T, E extends Event>(
data: T,
event: (data: T, event: E) => void,
): LinkedEvent<T, E> | null {
event: (data: T, event: E) => void
// @TODO: Properly type this at some point, but i have no idea how to do it with curried functions like this
): any {
if (isFunction(event)) {
return (evt) => event(data, evt)
return evt => event(data, evt);
}
return null; // Return null when event is invalid, to avoid creating unnecessary event handlers
}
// object.event should always be function, otherwise its badly created object.
export function isLinkEventObject(o): o is LinkedEvent<any, any> {
return !isNull(o) && typeof o === "object";
}
return !isNull(o) && typeof o === 'object';
}

41
yarn.lock

@ -2345,10 +2345,10 @@
"@types/istanbul-lib-coverage" "*"
"@types/istanbul-lib-report" "*"
"@types/[email protected]^25.2.1":
version "25.2.1"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-25.2.1.tgz#9544cd438607955381c1bdbdb97767a249297db5"
integrity sha512-msra1bCaAeEdkSyA0CZ6gW1ukMIvZ5YoJkdXw/qhQdsuuDlFTcEUrUw8CLCPt2rVRUfXlClVvK2gvPs9IokZaA==
"@types/[email protected]^26.0.8":
version "26.0.8"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-26.0.8.tgz#f5c5559cf25911ce227f7ce30f1f160f24966369"
integrity sha512-eo3VX9jGASSuv680D4VQ89UmuLZneNxv2MCZjfwlInav05zXVJTzfc//lavdV0GPwSxsXJTy2jALscB7Acqg0g==
dependencies:
jest-diff "^25.2.1"
pretty-format "^25.2.1"
@ -2407,10 +2407,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.2.tgz#160d82623610db590a64e8ca81784e11117e5a54"
integrity sha512-LB2R1Oyhpg8gu4SON/mfforE525+Hi/M1ineICEDftqNVTyFg1aRIeGuTvXAoWHc4nbrFncWtJgMmoyRvuGh7A==
"@types/[email protected]^13.11.1":
version "13.11.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.11.1.tgz#49a2a83df9d26daacead30d0ccc8762b128d53c7"
integrity sha512-eWQGP3qtxwL8FGneRrC5DwrJLGN4/dH1clNTuLfN81HCrxVtxRjygDTUoZJ5ASlDEeo0ppYFQjQIlXhtXpOn6g==
"@types/[email protected]^14.0.27":
version "14.0.27"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.27.tgz#a151873af5a5e851b51b3b065c9e63390a9e0eb1"
integrity sha512-kVrqXhbclHNHGu9ztnAwSncIgJv/FaxmzXJvGXNdcCpV1b8u1/Mi6z6m0vwy0LzKeXFTPLH0NzwmoJ3fNCIq0g==
"@types/[email protected]^2.4.0":
version "2.4.0"
@ -2427,11 +2427,31 @@
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-1.19.1.tgz#33509849f8e679e4add158959fdb086440e9553f"
integrity sha512-5qOlnZscTn4xxM5MeGXAMOsIOIKIbh9e85zJWfBRVPlRMEVawzoPhINYbRGkBZCI8LxvBe7tJCdWiarA99OZfQ==
"@types/[email protected]*":
version "15.7.3"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==
"@types/[email protected]^1.5.1":
version "1.5.4"
resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.4.tgz#15925414e0ad2cd765bfef58842f7e26a7accb24"
integrity sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug==
"@types/[email protected]^16.9.8":
version "16.9.8"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.9.8.tgz#fe4c1e11dfc67155733dfa6aa65108b4971cb423"
integrity sha512-ykkPQ+5nFknnlU6lDd947WbQ6TE3NNzbQAkInC2EKY1qeYdTKp7onFusmYZb+ityzx2YviqT6BXSu+LyWWJwcA==
dependencies:
"@types/react" "*"
"@types/[email protected]*", "@types/[email protected]^16.9.44":
version "16.9.44"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.44.tgz#da84b179c031aef67dc92c33bd3401f1da2fa3bc"
integrity sha512-BtLoJrXdW8DVZauKP+bY4Kmiq7ubcJq+H/aCpRfvPF7RAT3RwR73Sg8szdc2YasbAlWBDrQ6Q+AFM0KwtQY+WQ==
dependencies:
"@types/prop-types" "*"
csstype "^3.0.2"
"@types/[email protected]*":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@types/sizzle/-/sizzle-2.3.2.tgz#a811b8c18e2babab7d542b3365887ae2e4d9de47"
@ -4179,6 +4199,11 @@ [email protected]^2.0.0:
dependencies:
cssom "~0.3.6"
[email protected]^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.2.tgz#ee5ff8f208c8cd613b389f7b222c9801ca62b3f7"
integrity sha512-ofovWglpqoqbfLNOTBNZLSbMuGrblAf1efvvArGKOZMBrIoJeu5UsAipQolkijtyQx5MtAzT/J9IHj/CEY1mJw==
[email protected]^1.0.4:
version "1.0.6"
resolved "https://registry.yarnpkg.com/damerau-levenshtein/-/damerau-levenshtein-1.0.6.tgz#143c1641cb3d85c60c32329e26899adea8701791"

Loading…
Cancel
Save