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 `<input multiple='?'>`

* fixup! chore: housekeeping

* code review: use `URL.canParse()`

* Revert "code review: use `URL.canParse()`"

This reverts commit b1a436031ab154d8075762c91dd67d8c9eb954af.
This commit is contained in:
Yat Ho 2024-08-24 04:16:22 +08:00 committed by GitHub
parent 07172d9f4f
commit b5b7d7abde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 23 deletions

View File

@ -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;

View File

@ -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'}`;

View File

@ -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() ||