Skip to content
This repository was archived by the owner on Nov 21, 2023. It is now read-only.

Commit 47fba1e

Browse files
committed
clickable login link on auth errors
1 parent 68587b6 commit 47fba1e

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ This project does not adhere to Semantic Versioning.
99
### Added
1010
* Steam sessions will now be refreshed if required
1111

12+
### Changed
13+
* Authentication errors now include clickable links to the applicable login page
14+
1215
### Docs
1316
* Add readme
1417

src/view/sync.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ section.sync #status-message {
2020
grid-area: 1/3;
2121
}
2222

23+
section.sync #status-message a {
24+
margin-left: 0.25em;
25+
color: inherit;
26+
}
27+
28+
section.sync #status-message a:active,
29+
section.sync #status-message a:hover {
30+
text-decoration: none;
31+
}
32+
2333
section.sync button {
2434
padding: 0.5rem 3.125rem;
2535
background: var(--leetify-pink);

src/view/sync.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
import { EventName, GcpdTab, StatusIcon, SyncStatus } from '../../types/enums';
77
import { isRuntimeMessage, isSyncStatusEventBody, SyncStatusEventBody } from '../../types/interfaces';
88

9+
interface StatusLoginMessage {
10+
loginMessage: string;
11+
loginUrl: string;
12+
message: string;
13+
}
14+
915
export class Sync {
1016
protected readonly statusIconElement = document.querySelector('#status-icon') as HTMLImageElement | null;
1117
protected readonly statusMessageElement = document.querySelector('#status-message') as HTMLElement | null;
@@ -44,7 +50,19 @@ export class Sync {
4450
console.info(new Date().toJSON(), '[SyncStatus]', JSON.stringify(data));
4551

4652
if (this.statusMessageElement) {
47-
this.statusMessageElement.innerText = this.getStatusMessage(data);
53+
const statusMessage = this.getStatusMessage(data);
54+
55+
if (typeof statusMessage === 'string') {
56+
this.statusMessageElement.innerText = statusMessage;
57+
} else {
58+
this.statusMessageElement.innerText = statusMessage.message;
59+
60+
const anchor = document.createElement('a');
61+
anchor.href = statusMessage.loginUrl;
62+
anchor.target = '_blank';
63+
anchor.innerText = statusMessage.loginMessage;
64+
this.statusMessageElement.appendChild(anchor);
65+
}
4866
}
4967

5068
if (this.statusIconElement) {
@@ -89,23 +107,38 @@ export class Sync {
89107
}
90108
}
91109

92-
protected getStatusMessage(data: SyncStatusEventBody): string {
110+
protected getStatusMessage(data: SyncStatusEventBody): string | StatusLoginMessage {
93111
switch (data.status) {
94112
case SyncStatus.BEGINNING_SYNC: return `Requesting matches from Steam... (${data.tab === GcpdTab.WINGMAN ? 'Wingman' : 'Unranked 5v5'})`;
95113
case SyncStatus.FINISHED_GCPD: return `Received ${data.found === 1 ? 'one match' : `${data.found} matches`} from Steam.`;
96114
case SyncStatus.FINISHED_SYNC: return `Synchronized ${data.tab === GcpdTab.WINGMAN ? 'Wingman' : 'Unranked 5v5'} matches.`;
97115
case SyncStatus.GCPD_PARSER_INITIALIZED: return 'Steam GCPD response handler prepared.';
98116
case SyncStatus.GCPD_PARSER_INITIALIZING: return 'Preparing Steam GCPD response handler...';
99117
case SyncStatus.IDLE: return 'Idle. Press the button to sync your matches.';
100-
case SyncStatus.INVALID_GCPD_RESPONSE: return 'Something went wrong (GCPD). Please make sure you\'re logged in to Steam.';
101-
case SyncStatus.LEETIFY_AUTH_FAILED: return 'Could not authenticate with Leetify. Please make sure you\'re logged in.';
102118
case SyncStatus.LEETIFY_AUTH_SUCCESSFUL: return 'Logged in to Leetify.';
103119
case SyncStatus.REQUESTING_GCPD_PAGE: return `Requesting matches from Steam... (Iteration ${data.depth} of up to 16)`;
104-
case SyncStatus.STEAM_AUTH_FAILED: return 'Could not authenticate with Steam. Please make sure you\'re logged in.';
105120
case SyncStatus.UPLOADING_TO_LEETIFY_FAILED: return 'Could not upload matches to Leetify :(';
106121
case SyncStatus.UPLOADING_TO_LEETIFY: return 'Uploading matches to Leetify...';
107122
case SyncStatus.WAITING_FOR_LEETIFY_AUTH: return 'Logging in to Leetify...';
108123

124+
case SyncStatus.INVALID_GCPD_RESPONSE: return {
125+
message: 'Something went wrong (GCPD).',
126+
loginMessage: 'Please make sure you\'re logged in to Steam.',
127+
loginUrl: 'https://steamcommunity.com/my/gcpd/730?tab=matchhistoryscrimmage',
128+
};
129+
130+
case SyncStatus.LEETIFY_AUTH_FAILED: return {
131+
message: 'Could not authenticate with Leetify.',
132+
loginMessage: 'Please make sure you\'re logged in.',
133+
loginUrl: 'https://leetify.com/auth/login',
134+
};
135+
136+
case SyncStatus.STEAM_AUTH_FAILED: return {
137+
message: 'Could not authenticate with Steam.',
138+
loginMessage: 'Please make sure you\'re logged in.',
139+
loginUrl: 'https://steamcommunity.com/my/gcpd/730?tab=matchhistoryscrimmage',
140+
};
141+
109142
case SyncStatus.DONE: {
110143
const now = new Date();
111144
const f = (n: number): string => n.toString().padStart(2, '0');

0 commit comments

Comments
 (0)