Skip to content

Commit f444d05

Browse files
authored
Add websocket login frontend (#187)
* Add websocket login frontend * Format
1 parent 66151d1 commit f444d05

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

src/components/sections/styles.module.scss

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100

101101
.headerText,
102102
.smallShadowText,
103+
.tinyShadowText,
103104
.shadowText {
104105
color: #fff;
105106
}
@@ -109,6 +110,10 @@
109110
}
110111
.smallShadowText {
111112
filter: drop-shadow(0 1.65px 1px rgba(0, 0, 0, 0.3));
113+
font-size: 2rem;
114+
}
115+
.tinyShadowText {
116+
filter: drop-shadow(0 1px 0.6px rgba(0, 0, 0, 0.3));
112117
}
113118

114119
.icons {
@@ -301,3 +306,37 @@
301306
.contributing {
302307
font-size: 1.05rem;
303308
}
309+
310+
.buttonWrapper {
311+
display: flex;
312+
gap: 2rem;
313+
margin: 1rem 0;
314+
315+
.actionButton {
316+
appearance: none;
317+
border: none;
318+
color: var(--always-light);
319+
cursor: pointer;
320+
filter: drop-shadow(0 3.3px 2px rgba(0, 0, 0, 0.3));
321+
font-size: 1.25rem;
322+
padding: 0.75rem 1.25rem;
323+
z-index: 100000;
324+
325+
&:hover {
326+
filter: brightness(1.2) drop-shadow(0 3.3px 2px rgba(0, 0, 0, 0.3));
327+
}
328+
}
329+
330+
.acceptButton {
331+
background-color: var(--confirm);
332+
}
333+
334+
.rejectButton {
335+
background-color: var(--last-fm);
336+
}
337+
}
338+
339+
.whiteLink {
340+
color: #fff;
341+
text-decoration: underline;
342+
}

src/routes/websocket.tsx

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import {
2+
Accessor,
3+
Match,
4+
Setter,
5+
Switch,
6+
createSignal,
7+
onMount,
8+
} from 'solid-js';
9+
import styles from '../components/sections/styles.module.scss';
10+
11+
enum State {
12+
Waiting = 'WAITING',
13+
Rejected = 'REJECTED',
14+
Accepted = 'ACCEPTED',
15+
Confirmed = 'CONFIRMED',
16+
}
17+
18+
declare global {
19+
interface Window {
20+
wsState: Accessor<State>;
21+
setWSState: Setter<State>;
22+
}
23+
}
24+
25+
export default function WebSocket() {
26+
const [params, setParams] = createSignal<URLSearchParams>();
27+
28+
onMount(() => {
29+
setParams(new URLSearchParams(window.location.search));
30+
31+
const [a, b] = createSignal(State.Waiting);
32+
window.wsState = a;
33+
window.setWSState = b;
34+
});
35+
36+
return (
37+
<header class={styles.header} id="header">
38+
<Switch>
39+
<Match
40+
when={
41+
!params()?.get('applicationName') ||
42+
!params()?.get('userApiUrl')
43+
}
44+
>
45+
<h1 class={styles.smallShadowText}>Missing parameters</h1>
46+
</Match>
47+
48+
<Match when={window.wsState() === State.Waiting}>
49+
<h1 class={styles.smallShadowText}>
50+
{params()?.get('applicationName')} would like to receive
51+
data from Web Scrobbler at URL{' '}
52+
{params()?.get('userApiUrl')}.
53+
</h1>
54+
<div class={styles.buttonWrapper}>
55+
<button
56+
class={`${styles.actionButton} ${styles.acceptButton}`}
57+
onClick={() => window.setWSState(State.Accepted)}
58+
>
59+
Accept
60+
</button>
61+
<button
62+
class={`${styles.actionButton} ${styles.rejectButton}`}
63+
onClick={() => window.setWSState(State.Rejected)}
64+
>
65+
Reject
66+
</button>
67+
</div>
68+
<p class={styles.tinyShadowText}>
69+
Note: Web Scrobbler does no verification of
70+
applications.
71+
</p>
72+
</Match>
73+
74+
<Match when={window.wsState() === State.Accepted}>
75+
<h1 class={styles.smallShadowText}>
76+
Waiting for communications with extension...
77+
</h1>
78+
<p class={styles.tinyShadowText}>
79+
This shouldn&apos;t take more than a couple of seconds.
80+
Did you{' '}
81+
<a href="./" class={styles.whiteLink}>
82+
install Web Scrobbler?
83+
</a>
84+
</p>
85+
</Match>
86+
87+
<Match when={window.wsState() === State.Rejected}>
88+
<h1 class={styles.smallShadowText}>
89+
Rejected data access for{' '}
90+
{params()?.get('applicationName')}
91+
</h1>
92+
</Match>
93+
94+
<Match when={window.wsState() === State.Confirmed}>
95+
<h1 class={styles.smallShadowText}>
96+
You have given data access to{' '}
97+
{params()?.get('applicationName')}!
98+
</h1>
99+
<p class={styles.tinyShadowText}>
100+
Note that you may have to restart your browser for the
101+
changes to take effect.
102+
</p>
103+
</Match>
104+
</Switch>
105+
</header>
106+
);
107+
}

0 commit comments

Comments
 (0)