Extract renderTagBadges helper to eliminate 4x tag-badge rendering duplication
Build and Push Docker Image / build (push) Successful in 36s
Licence Check / Licence compatibility and copyright header verification (push) Failing after 37s
CI / Security audit (push) Successful in 1m2s
CI / Tests & coverage (push) Successful in 1m19s
Build and Push Docker Image / build (push) Successful in 36s
Licence Check / Licence compatibility and copyright header verification (push) Failing after 37s
CI / Security audit (push) Successful in 1m2s
CI / Tests & coverage (push) Successful in 1m19s
This commit is contained in:
+32
-72
@@ -4,6 +4,34 @@ import { state } from '../state.js';
|
|||||||
import { formatSize, formatSpeed, formatEpisodeInfo, escapeHtml } from '../utils/format.js';
|
import { formatSize, formatSpeed, formatEpisodeInfo, escapeHtml } from '../utils/format.js';
|
||||||
import { handleBlocklistSearch } from '../api.js';
|
import { handleBlocklistSearch } from '../api.js';
|
||||||
|
|
||||||
|
export function renderTagBadges(tagBadges, showAll, matchedUserTag) {
|
||||||
|
const fragment = document.createDocumentFragment();
|
||||||
|
|
||||||
|
if (showAll && tagBadges && tagBadges.length > 0) {
|
||||||
|
const unmatched = tagBadges.filter(b => !b.matchedUser);
|
||||||
|
const matched = tagBadges.filter(b => b.matchedUser);
|
||||||
|
for (const b of unmatched) {
|
||||||
|
const badge = document.createElement('span');
|
||||||
|
badge.className = 'download-user-badge unmatched';
|
||||||
|
badge.textContent = b.label;
|
||||||
|
fragment.appendChild(badge);
|
||||||
|
}
|
||||||
|
for (const b of matched) {
|
||||||
|
const badge = document.createElement('span');
|
||||||
|
badge.className = 'download-user-badge';
|
||||||
|
badge.textContent = b.matchedUser;
|
||||||
|
fragment.appendChild(badge);
|
||||||
|
}
|
||||||
|
} else if (matchedUserTag) {
|
||||||
|
const matchedBadge = document.createElement('span');
|
||||||
|
matchedBadge.className = 'download-user-badge';
|
||||||
|
matchedBadge.textContent = matchedUserTag;
|
||||||
|
fragment.appendChild(matchedBadge);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
export function renderDownloads() {
|
export function renderDownloads() {
|
||||||
const downloadsList = document.getElementById('downloads-list');
|
const downloadsList = document.getElementById('downloads-list');
|
||||||
const noDownloads = document.getElementById('no-downloads');
|
const noDownloads = document.getElementById('no-downloads');
|
||||||
@@ -97,27 +125,8 @@ export function updateDownloadCard(card, download) {
|
|||||||
const rightSide = document.createElement('div');
|
const rightSide = document.createElement('div');
|
||||||
rightSide.className = 'download-header-right';
|
rightSide.className = 'download-header-right';
|
||||||
|
|
||||||
if (state.showAll && download.tagBadges && download.tagBadges.length > 0) {
|
const badges = renderTagBadges(download.tagBadges, state.showAll, download.matchedUserTag);
|
||||||
const unmatched = download.tagBadges.filter(b => !b.matchedUser);
|
rightSide.appendChild(badges);
|
||||||
const matched = download.tagBadges.filter(b => b.matchedUser);
|
|
||||||
for (const b of unmatched) {
|
|
||||||
const badge = document.createElement('span');
|
|
||||||
badge.className = 'download-user-badge unmatched';
|
|
||||||
badge.textContent = b.label;
|
|
||||||
rightSide.appendChild(badge);
|
|
||||||
}
|
|
||||||
for (const b of matched) {
|
|
||||||
const badge = document.createElement('span');
|
|
||||||
badge.className = 'download-user-badge';
|
|
||||||
badge.textContent = b.matchedUser;
|
|
||||||
rightSide.appendChild(badge);
|
|
||||||
}
|
|
||||||
} else if (download.matchedUserTag) {
|
|
||||||
const matchedBadge = document.createElement('span');
|
|
||||||
matchedBadge.className = 'download-user-badge';
|
|
||||||
matchedBadge.textContent = download.matchedUserTag;
|
|
||||||
rightSide.appendChild(matchedBadge);
|
|
||||||
}
|
|
||||||
|
|
||||||
header.appendChild(rightSide);
|
header.appendChild(rightSide);
|
||||||
}
|
}
|
||||||
@@ -301,31 +310,8 @@ export function createDownloadCard(download) {
|
|||||||
const rightSide = document.createElement('div');
|
const rightSide = document.createElement('div');
|
||||||
rightSide.className = 'download-header-right';
|
rightSide.className = 'download-header-right';
|
||||||
|
|
||||||
if (state.showAll && download.tagBadges && download.tagBadges.length > 0) {
|
const badges = renderTagBadges(download.tagBadges, state.showAll, download.matchedUserTag);
|
||||||
// In showAll mode: render all tags classified by whether they match an Emby user.
|
rightSide.appendChild(badges);
|
||||||
// Unmatched (no known Emby user) → amber, leftmost.
|
|
||||||
// Matched → show Emby display name in accent colour, rightmost.
|
|
||||||
const unmatched = download.tagBadges.filter(b => !b.matchedUser);
|
|
||||||
const matched = download.tagBadges.filter(b => b.matchedUser);
|
|
||||||
for (const b of unmatched) {
|
|
||||||
const badge = document.createElement('span');
|
|
||||||
badge.className = 'download-user-badge unmatched';
|
|
||||||
badge.textContent = b.label;
|
|
||||||
rightSide.appendChild(badge);
|
|
||||||
}
|
|
||||||
for (const b of matched) {
|
|
||||||
const badge = document.createElement('span');
|
|
||||||
badge.className = 'download-user-badge';
|
|
||||||
badge.textContent = b.matchedUser;
|
|
||||||
rightSide.appendChild(badge);
|
|
||||||
}
|
|
||||||
} else if (download.matchedUserTag) {
|
|
||||||
// Normal (non-showAll) view: show only the current user's matched tag
|
|
||||||
const matchedBadge = document.createElement('span');
|
|
||||||
matchedBadge.className = 'download-user-badge';
|
|
||||||
matchedBadge.textContent = download.matchedUserTag;
|
|
||||||
rightSide.appendChild(matchedBadge);
|
|
||||||
}
|
|
||||||
|
|
||||||
header.appendChild(rightSide);
|
header.appendChild(rightSide);
|
||||||
|
|
||||||
@@ -380,32 +366,6 @@ export function createDownloadCard(download) {
|
|||||||
infoDiv.appendChild(movie);
|
infoDiv.appendChild(movie);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.showAll && download.tagBadges && download.tagBadges.length > 0) {
|
|
||||||
// In showAll mode: render all tags classified by whether they match an Emby user.
|
|
||||||
// Unmatched (no known Emby user) → amber, leftmost.
|
|
||||||
// Matched → show Emby display name in accent colour, rightmost.
|
|
||||||
const unmatched = download.tagBadges.filter(b => !b.matchedUser);
|
|
||||||
const matched = download.tagBadges.filter(b => b.matchedUser);
|
|
||||||
for (const b of unmatched) {
|
|
||||||
const badge = document.createElement('span');
|
|
||||||
badge.className = 'download-user-badge unmatched';
|
|
||||||
badge.textContent = b.label;
|
|
||||||
header.appendChild(badge);
|
|
||||||
}
|
|
||||||
for (const b of matched) {
|
|
||||||
const badge = document.createElement('span');
|
|
||||||
badge.className = 'download-user-badge';
|
|
||||||
badge.textContent = b.matchedUser;
|
|
||||||
header.appendChild(badge);
|
|
||||||
}
|
|
||||||
} else if (download.matchedUserTag) {
|
|
||||||
// Normal (non-showAll) view: show only the current user's matched tag
|
|
||||||
const matchedBadge = document.createElement('span');
|
|
||||||
matchedBadge.className = 'download-user-badge';
|
|
||||||
matchedBadge.textContent = download.matchedUserTag;
|
|
||||||
header.appendChild(matchedBadge);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add client logo
|
// Add client logo
|
||||||
if (download.client) {
|
if (download.client) {
|
||||||
const clientLogoWrapper = document.createElement('span');
|
const clientLogoWrapper = document.createElement('span');
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { state, HISTORY_REFRESH_MS } from '../state.js';
|
|||||||
import { loadHistory as apiLoadHistory } from '../api.js';
|
import { loadHistory as apiLoadHistory } from '../api.js';
|
||||||
import { saveHistoryDays, saveIgnoreAvailable } from '../utils/storage.js';
|
import { saveHistoryDays, saveIgnoreAvailable } from '../utils/storage.js';
|
||||||
import { formatDate, formatEpisodeInfo, escapeHtml } from '../utils/format.js';
|
import { formatDate, formatEpisodeInfo, escapeHtml } from '../utils/format.js';
|
||||||
|
import { renderTagBadges } from './downloads.js';
|
||||||
|
|
||||||
export function initHistoryControls() {
|
export function initHistoryControls() {
|
||||||
const daysInput = document.getElementById('history-days');
|
const daysInput = document.getElementById('history-days');
|
||||||
@@ -146,27 +147,8 @@ export function createHistoryCard(item) {
|
|||||||
header.appendChild(instBadge);
|
header.appendChild(instBadge);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.showAll && item.tagBadges && item.tagBadges.length > 0) {
|
const badges = renderTagBadges(item.tagBadges, state.showAll, item.matchedUserTag);
|
||||||
const unmatched = item.tagBadges.filter(b => !b.matchedUser);
|
header.appendChild(badges);
|
||||||
const matched = item.tagBadges.filter(b => b.matchedUser);
|
|
||||||
for (const b of unmatched) {
|
|
||||||
const badge = document.createElement('span');
|
|
||||||
badge.className = 'download-user-badge unmatched';
|
|
||||||
badge.textContent = b.label;
|
|
||||||
header.appendChild(badge);
|
|
||||||
}
|
|
||||||
for (const b of matched) {
|
|
||||||
const badge = document.createElement('span');
|
|
||||||
badge.className = 'download-user-badge';
|
|
||||||
badge.textContent = b.matchedUser;
|
|
||||||
header.appendChild(badge);
|
|
||||||
}
|
|
||||||
} else if (item.matchedUserTag) {
|
|
||||||
const badge = document.createElement('span');
|
|
||||||
badge.className = 'download-user-badge';
|
|
||||||
badge.textContent = item.matchedUserTag;
|
|
||||||
header.appendChild(badge);
|
|
||||||
}
|
|
||||||
|
|
||||||
info.appendChild(header);
|
info.appendChild(header);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user