Skip to content
This repository was archived by the owner on Aug 10, 2024. It is now read-only.

Commit fdee5df

Browse files
committed
⚡️ Improve performance.
1 parent effa676 commit fdee5df

6 files changed

Lines changed: 58 additions & 23 deletions

File tree

electron-builder.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
appId: dev.hextechdocs.lcuexplorer
22
productName: LCU Explorer
3-
copyright: Copyright © 2021 HextechDocs
3+
copyright: Copyright © 2022 HextechDocs
44
directories:
55
output: dist
66
buildResources: resources

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"electron-serve": "^1.1.0",
4040
"electron-store": "^8.0.0",
4141
"lcu-connector": "^2.1.3",
42+
"lodash": "^4.17.21",
4243
"recoil": "^0.4.0",
4344
"sass": "^1.37.5",
4445
"styled-components": "^5.3.0",
@@ -47,6 +48,7 @@
4748
"tracer": "^1.1.5"
4849
},
4950
"devDependencies": {
51+
"@types/lodash": "^4",
5052
"@types/node": "^16.6.1",
5153
"@types/react": "^17.0.17",
5254
"@types/styled-components": "^5.1.12",

renderer/pages/_app.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react";
2+
import type { AppProps } from "next/app";
23
import { RecoilRoot } from "recoil";
34

45
import "css-reset-and-normalize/css/button-reset.min.css";
@@ -8,11 +9,9 @@ import "css-reset-and-normalize/css/reset-and-normalize.min.css";
89
import "swagger-ui/dist/swagger-ui.css";
910
import "../styles/globals.sass";
1011

11-
const LCUExplorer = ({ Component, pageProps }: never): JSX.Element => {
12+
const LCUExplorer = ({ Component, pageProps }: AppProps): JSX.Element => {
1213
return (
1314
<RecoilRoot>
14-
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
15-
{/* @ts-ignore */}
1615
<Component {...pageProps} />
1716
</RecoilRoot>
1817
);

renderer/pages/home.tsx

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,35 @@ import React, { useState, useEffect } from "react";
22
import { ipcRenderer } from "electron";
33
import Swagger from "swagger-ui";
44
import axios, { AxiosResponse } from "axios";
5+
import { isEmpty } from "lodash";
56

67
import Titlebar from "@components/Titlebar";
78

89
type Credentials = {
9-
address: string;
10-
port: number;
11-
username: string;
12-
password: string;
13-
protocol: string;
10+
address?: string;
11+
port?: number;
12+
username?: string;
13+
password?: string;
14+
protocol?: string;
1415
};
1516
type SwaggerUIPlugged = Swagger & {
1617
updateSpec: (specUpdates: any) => void;
1718
};
1819

1920
const BASIC_AUTH = "BasicAuth";
2021

21-
const Home = (): JSX.Element => {
22-
const [swagger, SetSwagger] = useState<SwaggerUIPlugged>();
23-
const [credentials, SetCredentials] = useState<Credentials>();
24-
const [spec, SetSpec] = useState<any>();
22+
const Home: React.FC = () => {
23+
const [swagger, SetSwagger] = useState<any>({});
24+
const [credentials, SetCredentials] = useState<Credentials>({});
25+
const [spec, SetSpec] = useState<any>({});
2526

2627
// Get spec.
2728
useEffect(() => {
29+
if (!isEmpty(spec)) {
30+
console.log("spec is not empty returning");
31+
return;
32+
}
33+
console.warn("spec is empty fetching");
2834
axios
2935
.get("https://www.mingweisamuel.com/lcu-schema/lcu/openapi.json")
3036
.then((res: AxiosResponse<any>) => SetSpec(res.data));
@@ -34,14 +40,17 @@ const Home = (): JSX.Element => {
3440
useEffect(() => {
3541
ipcRenderer.on("credentialspass", (_event, newCredentials) => {
3642
console.log(`FE received credentials: ${JSON.stringify(newCredentials)}`);
37-
SetCredentials(newCredentials);
43+
if (isEmpty(credentials)) {
44+
SetCredentials(newCredentials);
45+
}
3846
});
3947
ipcRenderer.send("fe-ready");
4048
}, []);
4149

4250
// Setup Swagger UI.
4351
useEffect(() => {
4452
const swaggerInst = Swagger({
53+
syntaxHighlight: false,
4554
dom_id: "#swagger",
4655
spec: {
4756
openapi: "3.0.0",
@@ -63,8 +72,13 @@ const Home = (): JSX.Element => {
6372
operationsSorter: "alpha",
6473
tagsSorter: "alpha",
6574
docExpansion: "none",
66-
defaultModelExpandDepth: 1,
75+
defaultModelExpandDepth: 10,
76+
maxDisplayedTags: 100,
77+
tryItOutEnabled: true,
6778
displayRequestDuration: true,
79+
pluginsOptions: {
80+
pluginLoadType: "chain",
81+
},
6882
filter: "",
6983
deepLinking: false, // @ts-ignore
7084
requestInterceptor: (request: any) => {
@@ -77,8 +91,9 @@ const Home = (): JSX.Element => {
7791
spec: {
7892
wrapSelectors: {
7993
allowTryItOutFor: () => () => {
80-
const jsonSpec = system.getState().toJSON().spec.json;
81-
return jsonSpec.servers.length > 0;
94+
// const jsonSpec = system.getState().toJSON().spec.json;
95+
console.log("rerendering");
96+
return true;
8297
},
8398
},
8499
},
@@ -97,7 +112,12 @@ const Home = (): JSX.Element => {
97112
],
98113
onComplete: () => {
99114
console.log("Swagger UI loading complete.");
100-
SetSwagger(swaggerInst);
115+
if (isEmpty(swagger)) {
116+
console.log("swagger is empty applying instance");
117+
SetSwagger(swaggerInst);
118+
} else {
119+
console.log("swagger instance is present");
120+
}
101121
},
102122
}) as SwaggerUIPlugged;
103123
}, []);
@@ -116,6 +136,11 @@ const Home = (): JSX.Element => {
116136

117137
// Update credentials/port from connector.
118138
if (credentials != null) {
139+
if (isEmpty(swagger)) {
140+
console.log("swager is empty and credentials arent null");
141+
return;
142+
}
143+
console.log("updating spec...");
119144
swagger.updateSpec({
120145
servers: [
121146
{
@@ -130,13 +155,18 @@ const Home = (): JSX.Element => {
130155
credentials.password
131156
);
132157
} else {
158+
if (isEmpty(swagger)) {
159+
return;
160+
}
161+
console.log("updating spec");
133162
swagger.updateSpec({
134163
servers: [],
135164
});
136165
}
137166

138167
// Update OpenAPI spec lcu-schema.
139168
if (spec != null) {
169+
console.log("updating spec");
140170
swagger.updateSpec(spec);
141171
}
142172
}, [swagger, credentials, spec]);

renderer/state/Theme.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

yarn.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,13 @@ __metadata:
17611761
languageName: node
17621762
linkType: hard
17631763

1764+
"@types/lodash@npm:^4":
1765+
version: 4.14.186
1766+
resolution: "@types/lodash@npm:4.14.186"
1767+
checksum: ee0c1368a8100bb6efb88335107473a41928fc307ff1ef4ff1278868ccddba9c04c68c36d1ffe3a0392ef4a956e1955f7de3203ec09df4f1655dd1b88485c549
1768+
languageName: node
1769+
linkType: hard
1770+
17641771
"@types/minimatch@npm:*":
17651772
version: 3.0.5
17661773
resolution: "@types/minimatch@npm:3.0.5"
@@ -6958,6 +6965,7 @@ fsevents@^1.2.7:
69586965
version: 0.0.0-use.local
69596966
resolution: "lcu-explorer@workspace:."
69606967
dependencies:
6968+
"@types/lodash": ^4
69616969
"@types/node": ^16.6.1
69626970
"@types/react": ^17.0.17
69636971
"@types/styled-components": ^5.1.12
@@ -6981,6 +6989,7 @@ fsevents@^1.2.7:
69816989
eslint-plugin-react: 7.24.0
69826990
eslint-plugin-react-hooks: 4.2.0
69836991
lcu-connector: ^2.1.3
6992+
lodash: ^4.17.21
69846993
next: ^11.1.1
69856994
nextron: ^7.0.0
69866995
prettier: ^2.3.2

0 commit comments

Comments
 (0)