Skip to content

Commit 32d5856

Browse files
author
n1tsua
authored
fix: fix click event target and add message to login fail event (#19)
1 parent 847ce61 commit 32d5856

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

src/initialize.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,20 @@ function rewriteLinks() {
6363
"click",
6464
(event) => {
6565
rewriteTargets();
66+
let target = "";
67+
if (event.target instanceof Element) {
68+
if (event.target.id) {
69+
target = `#${event.target.id}`;
70+
} else if (event.target.classList.length) {
71+
target = `.${event.target.classList.value.replaceAll(" ", ".")}`;
72+
} else {
73+
target = event.target.tagName;
74+
}
75+
}
6676
sendMessageToTestBox(CLICK, {
6777
x: event.x,
6878
y: event.y,
69-
target: event.target,
79+
target,
7080
});
7181
},
7282
false

src/messaging/outgoing.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ type HealthCheckEvent = {
2222
type ClickEvent = {
2323
x: number;
2424
y: number;
25-
target: any;
25+
target?: string;
26+
};
27+
28+
type LoginFailEvent = {
29+
message?: string;
2630
};
2731

2832
export interface TestBoxOutgoingEvents {
@@ -35,7 +39,7 @@ export interface TestBoxOutgoingEvents {
3539
[INITIALIZE_FAIL]: undefined;
3640
[LOGIN_ACK]: undefined;
3741
[LOGIN_SUCCESS]: undefined;
38-
[LOGIN_FAIL]: undefined;
42+
[LOGIN_FAIL]: LoginFailEvent;
3943
[LOGIN_NO_CREDS]: undefined;
4044
[NAVIGATE_ACK]: undefined;
4145
}

src/utils/login.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { sendMessageToTestBox } from "../messaging";
22
import { LOGIN_FAIL, LOGIN_SUCCESS } from "../messaging/outgoing";
33
import { IncomingEventHandlers, LoginEvent } from "../messaging/incoming";
4+
import { error, info } from "./logging";
45

56
export let loggingIn = false;
67

@@ -9,22 +10,24 @@ export async function autoLogin(
910
router: Partial<IncomingEventHandlers>
1011
) {
1112
let nextUrl: string | boolean;
13+
let errorMessage: string;
1214
loggingIn = true;
1315
try {
1416
const func = router["login"];
1517
if (!func) {
16-
console.log("No login callback exists!");
18+
info("No login callback exists!");
1719
sendMessageToTestBox(LOGIN_FAIL);
1820
return;
1921
}
2022
nextUrl = await func(data);
2123
} catch (e) {
22-
console.log(e);
24+
error(e);
25+
errorMessage = e.message;
2326
nextUrl = false;
2427
}
2528

2629
if (nextUrl === false) {
27-
sendMessageToTestBox(LOGIN_FAIL);
30+
sendMessageToTestBox(LOGIN_FAIL, { message: errorMessage });
2831
} else {
2932
sendMessageToTestBox(LOGIN_SUCCESS);
3033
}

0 commit comments

Comments
 (0)