Skip to content

Commit e42df2a

Browse files
committed
Unused var cleanup
1 parent fa9a88c commit e42df2a

File tree

5 files changed

+6
-178
lines changed

5 files changed

+6
-178
lines changed

src/app/advanced/[engine]/index.html/page.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import React, { useState } from 'react';
2-
import { getEngine, runTest } from '@/engines';
1+
import React from 'react';
2+
import { getEngine } from '@/engines';
33
import { ShareLinks } from '@/components/ShareLinks';
44
import { notFound } from 'next/navigation';
5-
import { TestInput } from '@/types/TestInput';
6-
import { TestOutput } from '@/types/TestOutput';
7-
import { TestResults } from '@/components/TestResults';
8-
import { Metadata } from 'next';
95
import TestForm from './TestForm';
106

117
export async function generateMetadata({ params }: { params: { engine: string } }) {

src/app/advanced/[engine]/options.html/page.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import React, { useState } from 'react';
2-
import { getEngine, runTest } from '@/engines';
3-
import { ShareLinks } from '@/components/ShareLinks';
1+
import { getEngine } from '@/engines';
42
import { notFound } from 'next/navigation';
5-
import { TestInput } from '@/types/TestInput';
6-
import { TestOutput } from '@/types/TestOutput';
7-
import { TestResults } from '@/components/TestResults';
8-
import { Metadata } from 'next';
93

104
export async function generateMetadata({ params }: { params: { engine: string } }) {
115
const engine = getEngine(params.engine);

src/app/layout.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { Metadata } from "next";
21
import { Navbar } from "@/components/Navbar";
32
import type { Viewport } from 'next'
43

src/app/status.html/page.tsx

Lines changed: 3 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,13 @@
1-
'use client';
2-
/* eslint-disable @next/next/no-img-element */
3-
4-
import React, { useCallback } from 'react';
5-
import { getEngines } from '@/engines';
6-
import Link from 'next/link';
7-
import fetchJsonp from 'fetch-jsonp';
8-
import { EngineStatus } from '@/types/EngineStatus';
91
import { Metadata } from 'next';
2+
import { ResultsTable } from './ResultsTable';
103

114
export const metadata: Metadata = {
125
title: "Backend status - RegexPlanet",
136
description: `Status of RegexPlanet's backend services`,
147
};
158

16-
function getHost(test_url: string) {
17-
const urlObj = new URL(test_url);
18-
if (urlObj.host.endsWith(".gcr.regexplanet.com")) {
19-
return <Link href="https://cloud.google.com/run/">Cloud Run</Link>;
20-
}
21-
if (urlObj.host.endsWith(".appspot.com")) {
22-
return <Link href="https://code.google.com/appengine/">AppEngine</Link>;
23-
}
24-
if (urlObj.host.endsWith(".herokuapp.com")) {
25-
return <Link href="https://www.heroku.com/">Heroku</Link>;
26-
}
27-
return <>
28-
{urlObj.host}
29-
</>
30-
}
31-
32-
const SLOW_TIME_MILLIS = 10 * 1000;
33-
34-
function EngineStatusColumns(status: EngineStatus | undefined ) {
35-
if (!status) {
36-
return (
37-
<>
38-
<td><img src="/images/spinner.gif" alt="loading" /></td>
39-
<td/>
40-
<td />
41-
</>
42-
);
43-
}
44-
if (!status.version) {
45-
return (
46-
<>
47-
<td><img src="/images/cross-circle.png" alt="down" /> Down</td>
48-
<td />
49-
<td />
50-
</>
51-
);
52-
}
53-
54-
if (status.success === false) {
55-
return (
56-
<>
57-
<td><img src="/images/exclamation-red.png" alt="loading" /> Error</td>
58-
<td />
59-
<td />
60-
</>
61-
);
62-
}
63-
64-
if (!status.time_millis) {
65-
return (
66-
<>
67-
<td><img src="/images/exclamation-red.png" alt="loading" /> No time?!?</td>
68-
<td />
69-
<td />
70-
</>
71-
);
72-
}
73-
74-
75-
const icon_url = status.time_millis < SLOW_TIME_MILLIS ? "/images/tick.png" : "/images/exclamation-frame.png";
76-
const text = status.time_millis < SLOW_TIME_MILLIS ? "Success" : "Slow";
77-
78-
return (
79-
<>
80-
<td>
81-
<img src={icon_url} alt="up" /> { text }
82-
</td>
83-
<td>{status.version}</td>
84-
<td>{status.time_millis}</td>
85-
</>
86-
);
87-
}
88-
89-
async function fetchOneResult (url: string): Promise<EngineStatus> {
90-
console.log(`Fetching ${url}`);
91-
const start = Date.now();
92-
try {
93-
const response = await fetchJsonp(url);
94-
const elapsed = Date.now() - start;
95-
if (!response.ok) {
96-
return { success: false, time_millis: elapsed };
97-
}
98-
const data = await response.json();
99-
console.log('fetchone success', url, data);
100-
return {
101-
success: data.success,
102-
version: data.version,
103-
time_millis: elapsed,
104-
};
105-
} catch (err) {
106-
console.log('fetch error', err);
107-
return {
108-
success: false,
109-
version: undefined,
110-
time_millis: Date.now() - start,
111-
};
112-
}
113-
}
114-
1159
export default function Page() {
11610

117-
const [ results, setState ] = React.useState<EngineStatus[]>([]);
118-
119-
const fetchAllResults = useCallback(() => {
120-
console.log("Fetching all results");
121-
getEngines().map((engine, index) => {
122-
fetchOneResult(engine.status_url)
123-
.then((result) => {
124-
console.log(`Got result for ${engine.short_name}`, result, index);
125-
setState(prevResult => {
126-
console.log("Setting state: before", prevResult);
127-
const newResult = [...prevResult];
128-
newResult[index] = result;
129-
console.log("Setting state: after", newResult);
130-
return newResult;
131-
});
132-
});
133-
});
134-
}, []);
135-
136-
React.useEffect(() => {
137-
console.log("useEffect");
138-
fetchAllResults();
139-
}, [fetchAllResults]);
140-
141-
const onRefresh = () => {
142-
console.log("Refreshing");
143-
setState([]);
144-
fetchAllResults();
145-
};
146-
147-
console.log("Rendering", JSON.stringify(results));
14811
return (
14912
<>
15013
<h1>Current Status</h1>
@@ -153,32 +16,9 @@ export default function Page() {
15316
Each engine is running in a separate instance. The table below shows the current status of each engine.
15417
</p>
15518
<p>
156-
The engines should be very responsive: they do not hit a database or do anything but calculate regexes. They should never take longer than a 1 second (1,000 ms in the table above) unless there is a problem with the regex (or the host). Response times of less than 0.1 second (100 ms) are very good.
19+
The engines should be very responsive: they do not hit a database or do anything but calculate regexes. They should never take longer than a second (1,000 ms in the table above) unless there is a problem with the regex (or the host). Response times of less than 0.1 second (100 ms) are very good.
15720
</p>
158-
<table className="table table-striped table-bordered">
159-
<thead>
160-
<tr>
161-
<th>Engine</th>
162-
<th>Status</th>
163-
<th>Version</th>
164-
<th>Time (ms)</th>
165-
<th>Hosted at</th>
166-
</tr>
167-
</thead>
168-
<tbody>
169-
{getEngines().map((engine, index) => (
170-
<tr key={engine.handle}>
171-
<td>
172-
<img className="pe-2" src={engine.logo_icon} alt={engine.short_name} style={{"height": "1.25em"}} />
173-
<Link href={`/advanced/${engine.handle}/index.html`} >{engine.short_name}</Link>
174-
</td>
175-
{EngineStatusColumns(results[index])}
176-
<td>{getHost(engine.test_url)}</td>
177-
</tr>
178-
))}
179-
</tbody>
180-
</table>
181-
<button className="btn btn-primary" onClick={onRefresh}>Refresh</button>
21+
<ResultsTable />
18222
</>
18323
);
18424
}

src/app/support/index.html/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use client';
21
/* eslint-disable @next/next/no-img-element */
32

43
import { Metadata } from 'next';

0 commit comments

Comments
 (0)