From b5b7d7abdec6ca2e59ea8deb0d4435342805f83a Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Sat, 24 Aug 2024 04:16:22 +0800 Subject: [PATCH] chore: misc WebUI fixes and cleanup (#7037) * chore: housekeeping * fix: use `setCurrentPopup` for drag and drop dialogue * fix: minor typo * chore: removed unused timer * fix: correct value in `` * fixup! chore: housekeeping * code review: use `URL.canParse()` * Revert "code review: use `URL.canParse()`" This reverts commit b1a436031ab154d8075762c91dd67d8c9eb954af. --- web/src/open-dialog.js | 10 +++++----- web/src/prefs-dialog.js | 2 +- web/src/transmission.js | 24 +++++++----------------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/web/src/open-dialog.js b/web/src/open-dialog.js index 9db46a46f..a32db7bb2 100644 --- a/web/src/open-dialog.js +++ b/web/src/open-dialog.js @@ -8,7 +8,7 @@ import { Formatter } from './formatter.js'; import { createDialogContainer, makeUUID } from './utils.js'; export class OpenDialog extends EventTarget { - constructor(controller, remote, url = '', files = []) { + constructor(controller, remote, url = '', files = null) { super(); this.controller = controller; @@ -18,7 +18,7 @@ export class OpenDialog extends EventTarget { this.elements.dismiss.addEventListener('click', () => this._onDismiss()); this.elements.confirm.addEventListener('click', () => this._onConfirm()); document.body.append(this.elements.root); - if (files.length > 0) { + if (files) { this.elements.file_input.files = files; } this._updateFreeSpaceInAddDialog(); @@ -47,8 +47,8 @@ export class OpenDialog extends EventTarget { const path = this.elements.folder_input.value; this.remote.getFreeSpace(path, (dir, bytes) => { if (!this.closed) { - const string = bytes > 0 ? `${Formatter.size(bytes)} Free` : ''; - this.elements.freespace.textContent = string; + this.elements.freespace.textContent = + bytes > 0 ? `${Formatter.size(bytes)} Free` : ''; } }); } @@ -137,7 +137,7 @@ export class OpenDialog extends EventTarget { input.type = 'file'; input.name = 'torrent-files[]'; input.id = input_id; - input.multiple = 'multiple'; + input.multiple = true; workarea.append(input); elements.file_input = input; diff --git a/web/src/prefs-dialog.js b/web/src/prefs-dialog.js index 443e2fbf9..3c1913ba3 100644 --- a/web/src/prefs-dialog.js +++ b/web/src/prefs-dialog.js @@ -15,7 +15,7 @@ import { export class PrefsDialog extends EventTarget { static _initTimeDropDown(e) { for (let index = 0; index < 24 * 4; ++index) { - const hour = Number.parseInt(index / 4, 10); + const hour = index / 4; const mins = (index % 4) * 15; const value = index * 15; const content = `${hour}:${mins || '00'}`; diff --git a/web/src/transmission.js b/web/src/transmission.js index 549f2702b..52c88509d 100644 --- a/web/src/transmission.js +++ b/web/src/transmission.js @@ -51,7 +51,7 @@ export class Transmission extends EventTarget { this.boundPopupCloseListener = this.popupCloseListener.bind(this); - this.isTouch = 'ontouchstart' in window ? true : false; + this.isTouch = 'ontouchstart' in window; this.busyclick = false; // listen to actions @@ -506,7 +506,7 @@ export class Transmission extends EventTarget { if (event_.metaKey) { a.push('Meta'); } - if (event_.shitKey) { + if (event_.shiftKey) { a.push('Shift'); } a.push(event_.key.length === 1 ? event_.key.toUpperCase() : event_.key); @@ -622,7 +622,7 @@ export class Transmission extends EventTarget { static _isValidURL(string) { try { const url = new URL(string); - return url ? true : false; + return Boolean(url); } catch { return false; } @@ -639,9 +639,9 @@ export class Transmission extends EventTarget { return true; } - const type = event_.dataTransfer.types - .filter((t) => ['text/uri-list', 'text/plain'].includes(t)) - .pop(); + const type = event_.dataTransfer.types.findLast((t) => + ['text/uri-list', 'text/plain'].includes(t), + ); for (const uri of event_.dataTransfer .getData(type) .split('\n') @@ -653,7 +653,7 @@ export class Transmission extends EventTarget { const { files } = event_.dataTransfer; if (files.length > 0) { - this.openDialog = new OpenDialog(this, this.remote, '', files); + this.setCurrentPopup(new OpenDialog(this, this.remote, '', files)); } event_.preventDefault(); return false; @@ -1026,9 +1026,6 @@ TODO: fix this when notifications get fixed this._updateFilterSelect(); - clearTimeout(this.refilterTimer); - delete this.refilterTimer; - if (rebuildEverything) { while (list.firstChild) { list.firstChild.remove(); @@ -1127,13 +1124,6 @@ TODO: fix this when notifications get fixed this._rows = rows; this.dirtyTorrents.clear(); - // set the odd/even property - for (const [index, e] of rows.map((row) => row.getElement()).entries()) { - const even = index % 2 === 0; - e.classList.toggle('even', even); - e.classList.toggle('odd', !even); - } - this._updateStatusbar(); if ( old_sel_count !== countSelectedRows() ||