|
| 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'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