refactor(web): extract mime icon creation to the helper (#6664)

This commit is contained in:
Hendrik Luup 2024-03-04 16:46:25 +02:00 committed by GitHub
parent 7a4677ebd2
commit 98c4eb8487
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 14 deletions

View File

@ -8,6 +8,17 @@ import { Torrent } from './torrent.js';
import { setTextContent } from './utils.js';
const TorrentRendererHelper = {
createIcon: (torrent) => {
const icon = document.createElement('div');
icon.classList.add('icon');
icon.dataset.iconMimeType = torrent
.getPrimaryMimeType()
.split('/', 1)
.pop();
icon.dataset.iconMultifile = torrent.getFileCount() > 1 ? 'true' : 'false';
return icon;
},
formatDL: (t) => {
return `${Formatter.speedBps(t.getDownloadSpeed())}`;
},
@ -254,13 +265,7 @@ export class TorrentRendererFull {
const root = document.createElement('li');
root.className = 'torrent';
const icon = document.createElement('div');
icon.classList.add('icon');
icon.dataset.iconMimeType = torrent
.getPrimaryMimeType()
.split('/', 1)
.pop();
icon.dataset.iconMultifile = torrent.getFileCount() > 1 ? 'true' : 'false';
const icon = TorrentRendererHelper.createIcon(torrent);
const name = document.createElement('div');
name.className = 'torrent-name';
@ -358,13 +363,7 @@ export class TorrentRendererCompact {
const progressbar = document.createElement('div');
progressbar.classList.add('torrent-progress-bar', 'compact');
const icon = document.createElement('div');
icon.classList.add('icon');
icon.dataset.iconMimeType = torrent
.getPrimaryMimeType()
.split('/', 1)
.pop();
icon.dataset.iconMultifile = torrent.getFileCount() > 1 ? 'true' : 'false';
const icon = TorrentRendererHelper.createIcon(torrent);
const details = document.createElement('div');
details.className = 'torrent-peer-details compact';