Skip to content

Commit f01c790

Browse files
committed
frontend/frame: add abort button while opening a connection.
1 parent 8aad640 commit f01c790

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

frontend/src/components/Frame.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ChargersState } from '../pages/chargers';
1010
import { Dispatch, StateUpdater, useEffect } from 'preact/hooks';
1111
import { showAlert } from './Alert';
1212
import { useLocation } from 'preact-iso';
13+
import { useTranslation } from 'react-i18next';
1314

1415
interface VirtualNetworkInterfaceSetParentState {
1516
chargersState: Dispatch<StateUpdater<ChargersState>>,
@@ -260,6 +261,7 @@ export class Frame extends Component<FrameProps, FrameState> {
260261
setTimeout(() => sessionStorage.setItem("currentConnection", JSON.stringify(this.props.parentState)))
261262
}
262263

264+
const that = this;
263265
// this is used by the app to close the remote connection via the native app menu.
264266
(window as any).close = () => {
265267
this.props.setParentState({
@@ -268,6 +270,7 @@ export class Frame extends Component<FrameProps, FrameState> {
268270
connectedName: "",
269271
connectedPort: 0,
270272
});
273+
clearTimeout(that.interface.timeout);
271274
this.route("/chargers");
272275
setAppNavigation();
273276
sessionStorage.removeItem("currentConnection");
@@ -289,6 +292,8 @@ export class Frame extends Component<FrameProps, FrameState> {
289292

290293
render() {
291294
const { route } = useLocation();
295+
const {t} = useTranslation("", {useSuspense: false, keyPrefix: "chargers"});
296+
292297
useEffect(() => {
293298
this.route = route;
294299
this.interface = new VirtualNetworkInterface({
@@ -315,6 +320,14 @@ export class Frame extends Component<FrameProps, FrameState> {
315320
i18n.t("chargers.connecting") :
316321
i18n.t("chargers.loading_webinterface")}
317322
</div>
323+
<Button className="col-lg-1 col-md-2 col-sm-3 col-6 mt-3"
324+
variant="outline-warning"
325+
type="button"
326+
onClick={(e) => {
327+
e.stopPropagation();
328+
e.preventDefault();
329+
(window as any).close();
330+
}}>{t("abort")}</Button>
318331
</Row>
319332
<Row className="flex-grow-1 m-0">
320333
<iframe class="p-0" hidden={this.state.show_spinner} width="100%" height="100%" id="interface"></iframe>

frontend/src/locales/de.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const de ={
6666
"decline": "Verwerfen",
6767
"show_more": "Mehr anzeigen",
6868
"show_less": "Weniger anzeigen",
69+
"abort": "Abbrechen",
6970
"connecting": "Verbindung wird aufgebaut",
7071
"loading_webinterface": "Webinterface wird geladen",
7172
"invalid_key": "Die auf dem Gerät gespeicherten Schlüssel scheinen fehlerhaft zu sein",

frontend/src/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const en = {
6969
"decline": "Decline",
7070
"show_more": "Show more",
7171
"show_less": "Show less",
72+
"abort": "Cancel",
7273
"connecting": "Connecting",
7374
"loading_webinterface": "Loading webinterface",
7475
"invalid_key": "The keys saved on the device seem to be corrupted",

frontend/tests/basic.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test('charger lifecycle', async ({ page }) => {
6565
await page.getByRole('row', { name: testUser1Email }).getByRole('button').click();
6666
await page.getByRole('button', { name: 'Save' }).click();
6767
await page.getByRole('button', { name: 'Reboot' }).click();
68-
await page.waitForTimeout(5000);
68+
await page.waitForTimeout(6000);
6969
await page.goto(testDomain);
7070
await expect(page.getByText('NameDevice-IDNoteSortAscending')).toBeVisible();
7171
});
@@ -165,7 +165,7 @@ test('remove charger', async ({page}) => {
165165
await page.getByRole('row', { name: testUser1Email }).getByRole('button').click();
166166
await page.getByRole('button', { name: 'Save' }).click();
167167
await page.getByRole('button', { name: 'Reboot' }).click();
168-
await page.waitForTimeout(1000);
168+
await page.waitForTimeout(6000);
169169
await login(page, testUser2Email, testPassword2);
170170
await expect(page.getByText('NameDevice-IDNoteSortAscending')).toBeVisible();
171171
});

0 commit comments

Comments
 (0)