Skip to content

Commit a1c8d24

Browse files
authored
Typescript support (#4475)
1 parent 0cf4000 commit a1c8d24

File tree

116 files changed

+735
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+735
-403
lines changed

Plan/common/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ tasks.register("bundle", YarnTask) {
140140
dependsOn yarn
141141
inputs.files(fileTree("$rootDir/react/dashboard/src"))
142142
inputs.file("$rootDir/react/dashboard/package.json")
143-
inputs.file("$rootDir/react/dashboard/vite.config.js")
143+
inputs.file("$rootDir/react/dashboard/vite.config.ts")
144+
inputs.file("$rootDir/react/dashboard/tsconfig.json")
145+
inputs.file("$rootDir/react/dashboard/tsconfig.node.json")
144146

145147
outputs.dir("$rootDir/react/dashboard/build")
146148

Plan/react/dashboard/global.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare global {
2+
interface Window {
3+
global: typeof window;
4+
}
5+
}
6+
7+
export {};

Plan/react/dashboard/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
<script src="/pageExtensionApi.js"></script>
2424
<noscript>You need to enable JavaScript to run this app.</noscript>
2525
<div id="root"></div>
26-
<script src="/src/index.jsx" type="module"></script>
26+
<script src="/src/index.tsx" type="module"></script>
2727
</body>
2828
</html>

Plan/react/dashboard/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
"scripts": {
5151
"start": "vite",
52-
"build": "vite build",
52+
"build": "tsc && vite build",
5353
"analyze": "source-map-explorer 'build/static/js/*.js'"
5454
},
5555
"eslintConfig": {
@@ -71,7 +71,10 @@
7171
]
7272
},
7373
"devDependencies": {
74+
"@types/react": "^19.2.14",
75+
"@types/react-dom": "^19.2.3",
7476
"@vitejs/plugin-react": "^5.1.4",
77+
"typescript": "^5.9.3",
7578
"vite": "^7.3.1"
7679
}
7780
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {render, screen} from '@testing-library/react';
2-
import App from './App';
2+
import App from './App.tsx';
33

44
test('renders learn react link', () => {
5-
render(<App/>);
6-
const linkElement = screen.getByText(/learn react/i);
7-
expect(linkElement).toBeInTheDocument();
5+
render(<App/>);
6+
const linkElement = screen.getByText(/learn react/i);
7+
expect(linkElement).toBeInTheDocument();
88
});
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import './style/mobile.css';
66
import 'react-bootstrap-range-slider/dist/react-bootstrap-range-slider.css';
77

88
import {createBrowserRouter, createRoutesFromElements, Navigate, Route, RouterProvider} from "react-router";
9-
import React, {useCallback, useEffect} from "react";
9+
import React, {PropsWithChildren, useCallback, useEffect} from "react";
1010
import {ThemeContextProvider, useTheme} from "./hooks/themeHook";
1111
import axios from "axios";
12-
import ErrorView from "./views/ErrorView";
12+
import ErrorView, {PlanError} from "./views/ErrorView";
1313
import {faMapSigns} from "@fortawesome/free-solid-svg-icons";
1414
import {MetadataContextProvider} from "./hooks/metadataHook";
1515
import {AuthenticationContextProvider} from "./hooks/authenticationHook";
@@ -20,8 +20,8 @@ import {PageExtensionContextProvider} from "./hooks/pageExtensionHook";
2020
import ErrorBoundary from "./components/ErrorBoundary";
2121
import {AlertPopupContextProvider} from "./hooks/context/alertPopupContext";
2222
import {PreferencesContextProvider} from "./hooks/preferencesHook";
23-
import {ThemeStorageContextProvider} from "./hooks/context/themeContextHook.jsx";
24-
import {ThemeStyleCss} from "./components/theme/ThemeStyleCss.jsx";
23+
import {ThemeStorageContextProvider} from "./hooks/context/themeContextHook.js";
24+
import {ThemeStyleCss} from "./components/theme/ThemeStyleCss.js";
2525

2626
const PlayerPage = React.lazy(() => import("./views/layout/PlayerPage"));
2727
const PlayerOverview = React.lazy(() => import("./views/player/PlayerOverview"));
@@ -88,28 +88,28 @@ const GroupsRedirect = () => {
8888
return (<Navigate to={"groups"} replace={true}/>)
8989
}
9090

91-
const ContextProviders = ({children}) => (
91+
const ContextProviders = ({children}: React.PropsWithChildren) => (
9292
<AuthenticationContextProvider>
9393
<MetadataContextProvider>
9494
<PreferencesContextProvider>
95-
<ThemeContextProvider>
96-
<ThemeStorageContextProvider>
97-
<NavigationContextProvider>
98-
<AlertPopupContextProvider>
95+
<AlertPopupContextProvider>
96+
<ThemeContextProvider>
97+
<ThemeStorageContextProvider>
98+
<NavigationContextProvider>
9999
<PageExtensionContextProvider>
100100
{children}
101101
</PageExtensionContextProvider>
102-
</AlertPopupContextProvider>
103-
</NavigationContextProvider>
104-
</ThemeStorageContextProvider>
105-
</ThemeContextProvider>
102+
</NavigationContextProvider>
103+
</ThemeStorageContextProvider>
104+
</ThemeContextProvider>
105+
</AlertPopupContextProvider>
106106
</PreferencesContextProvider>
107107
</MetadataContextProvider>
108108
</AuthenticationContextProvider>
109109
)
110110

111-
const Lazy = ({children}) => {
112-
const fallbackFunction = useCallback((error) => <ErrorView error={error}/>, []);
111+
const Lazy = ({children}: React.PropsWithChildren) => {
112+
const fallbackFunction = useCallback((error: PlanError) => <ErrorView error={error}/>, []);
113113
return (
114114
<React.Suspense fallback={<></>}>
115115
<ErrorBoundary fallbackFunction={fallbackFunction}>
@@ -226,7 +226,7 @@ const router = createBrowserRouter(
226226
), {basename: getBasename()}
227227
);
228228

229-
const Wrapper = ({children}) => {
229+
const Wrapper = ({children}: PropsWithChildren) => {
230230
const {nightModeEnabled} = useTheme();
231231

232232
useEffect(() => {

Plan/react/dashboard/src/components/alert/AlertPopupArea.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
2-
import {useAlertPopupContext} from "../../hooks/context/alertPopupContext";
3-
import LoadIn from "../animation/LoadIn";
2+
import {useAlertPopupContext} from "../../hooks/context/alertPopupContext.tsx";
3+
import LoadIn from "../animation/LoadIn.tsx";
44

55
const Alert = ({alert}) => {
66
const {dismissAlert} = useAlertPopupContext();

Plan/react/dashboard/src/components/animation/LoadIn.jsx renamed to Plan/react/dashboard/src/components/animation/LoadIn.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
import React, {useEffect, useRef, useState} from 'react';
2-
import {Transition} from 'react-transition-group';
1+
import React, {CSSProperties, PropsWithChildren, RefObject, useEffect, useRef, useState} from 'react';
2+
import {Transition, TransitionStatus} from 'react-transition-group';
33

44
const defaultDuration = 250;
55

6-
const LoadIn = ({children, duration}) => {
7-
const nodeRef = useRef();
6+
type Props = {
7+
duration?: number;
8+
} & PropsWithChildren;
9+
10+
type Animation = {
11+
[key in TransitionStatus]: CSSProperties;
12+
};
13+
14+
const LoadIn = ({children, duration}: Props) => {
15+
const nodeRef: RefObject<HTMLDivElement | null> = useRef(null);
816

917
if (!duration) duration = defaultDuration;
1018
const reduceAnimations = window.matchMedia(`(prefers-reduced-motion: reduce)`).matches;
@@ -18,7 +26,7 @@ const LoadIn = ({children, duration}) => {
1826
transform: "scale(0.99)"
1927
}
2028

21-
const transitionStyles = reduceAnimations ? {
29+
const transitionStyles: Animation = reduceAnimations ? {
2230
entering: {
2331
opacity: 1,
2432
},
@@ -30,7 +38,8 @@ const LoadIn = ({children, duration}) => {
3038
},
3139
exiting: {
3240
opacity: 0,
33-
}
41+
},
42+
unmounted: {}
3443
} : {
3544
entering: {
3645
opacity: 1,
@@ -48,6 +57,7 @@ const LoadIn = ({children, duration}) => {
4857
opacity: 0,
4958
transform: "scale(0.99)"
5059
},
60+
unmounted: {}
5161
};
5262

5363
const [visible, setVisible] = useState(false);

Plan/react/dashboard/src/components/cards/common/JoinAddresses.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import LoadIn from "../../animation/LoadIn.jsx";
1+
import LoadIn from "../../animation/LoadIn.tsx";
22
import ExtendableRow from "../../layout/extension/ExtendableRow.jsx";
33
import JoinAddressGraphCard from "../server/graphs/JoinAddressGraphCard.jsx";
44
import {Col} from "react-bootstrap";

Plan/react/dashboard/src/components/cards/common/PlayerRetention.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import LoadIn from "../../animation/LoadIn.jsx";
1+
import LoadIn from "../../animation/LoadIn.tsx";
22
import ExtendableRow from "../../layout/extension/ExtendableRow.jsx";
33
import {Col} from "react-bootstrap";
44
import PlayerRetentionGraphCard from "./PlayerRetentionGraphCard.jsx";

0 commit comments

Comments
 (0)