Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: polishing #21

Merged
merged 7 commits into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19,616 changes: 6,490 additions & 13,126 deletions js/package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"test": "npm run test --workspaces"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"eslint": "^8.8.0",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.4.1",
"typescript": "^4.4.3"
"prettier": "^2.5.1",
"typescript": "^4.5.5"
}
}
4 changes: 2 additions & 2 deletions js/packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"test": "echo 0"
},
"devDependencies": {
"parcel": "^2.0.0",
"typescript": "^4.3.5",
"parcel": "^2.3.2",
"typescript": "^4.5.5",
"tslib": "^2.3.1",
"rimraf": "^3.0.2"
}
Expand Down
2 changes: 1 addition & 1 deletion js/packages/client/src/dom/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @returns {A}
*/
export function getElements<A extends Array<HTMLElement>>(...ids: string[]): A {
// This is unsafe but we know these elements exist when calling the function
// This is unsafe, but we know these elements exist when calling the function
return ids.map(id => {
const el = document.getElementById(id);
if (el === null) throw new Error(`${id} does not exist`);
Expand Down
24 changes: 12 additions & 12 deletions js/packages/client/src/index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<head>
<meta charset="UTF-8" />
<title>Current Song</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div id="song-container" class="vanish">
<div id="image-container" class="hidden"><img id="image" alt='Cover'/></div>
<div id="song-info">
<link rel="stylesheet" href="index.css" />
</head>
<body>
<div id="song-container" class="vanish">
<div id="image-container" class="hidden"><img id="image" alt="Cover" /></div>
<div id="song-info">
<h1 id="title"></h1>
<h2 id="subtitle"></h2>
</div>
<div id="progress" class="hidden"></div>
</div>
<div id="progress" class="hidden"></div>
</div>
<script type="module" src="index.ts"></script>
</body>
<script type="module" src="index.ts"></script>
</body>
</html>
8 changes: 6 additions & 2 deletions js/packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { createProgress } from './progress';
import { smolTree } from './dom/smol-tree';
import { hasImage, hasSubtitle, hasTimeline, isSpotify, makeState, not, State } from './state';
import { animateOnChange, TextChangeAnimation } from './dom/animation';
import { ReconnectingWebsocket } from '../../shared/reconnecting-websocket';
import { EventMap } from './types';
import { formatLocalUrl } from '../../shared/url';
import {
IncomingMessages,
OutgoingMessages,
ReconnectingWebsocket,
} from '../../shared/reconnecting-websocket';

(async function main() {
const [container, imageContainer, imageEl, titleEl, subtitleEl, progressEl] = getElements<
Expand All @@ -28,7 +32,7 @@ import { formatLocalUrl } from '../../shared/url';
[subtitleEl, { hidden: not(hasSubtitle) }],
);

const ws = new ReconnectingWebsocket<EventMap, { Pong: undefined }>(
const ws = new ReconnectingWebsocket<IncomingMessages<EventMap>, OutgoingMessages>(
formatLocalUrl('/api/ws/client', 'ws'),
);
ws.addEventListener('Playing', ({ data }) => {
Expand Down
7 changes: 5 additions & 2 deletions js/packages/client/src/text/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlayInfo } from '../types';
import { PlayInfo } from '../../../shared/types';

const MAX_SAFE_STRING = 50;

Expand Down Expand Up @@ -52,5 +52,8 @@ export function cleanupTitleAndSub(data: TitleData): TitleData {
}

function cleanupTooLongString(str: string): string {
return str.replace(/(:?\(.+\)|\[.+]|{.+})/g, '').replace(/ +/, ' ').trim();
return str
.replace(/(:?\(.+\)|\[.+]|{.+})/g, '')
.replace(/ +/, ' ')
.trim();
}
1 change: 0 additions & 1 deletion js/packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ import { PlayInfo } from '../../shared/types';
export type EventMap = {
Playing: PlayInfo;
Paused: undefined | null;
Ping: undefined;
};
Loading