Add an option to show active torrents when

completed torrents are hidden
This commit is contained in:
Someone
2023-10-31 11:23:26 +00:00
parent 735d6484e2
commit 2c019e12d6
5 changed files with 71 additions and 18 deletions

1
next-env.d.ts vendored
View File

@@ -1,6 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.

View File

@@ -10,6 +10,9 @@
"displayCompletedTorrents": {
"label": "Display completed torrents"
},
"displayActiveTorrents": {
"label": "Show active torrents when completed torrents are hidden"
},
"displayStaleTorrents": {
"label": "Display stale torrents"
},

View File

@@ -10,6 +10,9 @@
"displayCompletedTorrents": {
"label": "Cacher les torrents terminés"
},
"displayActiveTorrents": {
"label": "Afficher les torrents actifs quand les torrents terminés sont masqués"
},
"displayStaleTorrents": {
"label": "Afficher les torrents périmés"
},

View File

@@ -20,13 +20,14 @@ describe('TorrentTile', () => {
labelFilter: [],
labelFilterIsWhitelist: false,
displayCompletedTorrents: true,
displayActiveTorrents: true,
displayStaleTorrents: false,
},
};
const torrents: NormalizedTorrent[] = [
constructTorrent('ABC', 'Nice Torrent', false, 672),
constructTorrent('HH', 'I am completed', true, 0),
constructTorrent('HH', 'I am stale', false, 0),
constructTorrent('ABC', 'Nice Torrent', false, 672, 672),
constructTorrent('HH', 'I am completed', true, 0, 0),
constructTorrent('HH', 'I am stale', false, 0, 0),
];
// act
@@ -55,13 +56,14 @@ describe('TorrentTile', () => {
labelFilter: [],
labelFilterIsWhitelist: false,
displayCompletedTorrents: true,
displayActiveTorrents: true,
displayStaleTorrents: true,
},
};
const torrents: NormalizedTorrent[] = [
constructTorrent('ABC', 'Nice Torrent', false, 672),
constructTorrent('HH', 'I am completed', true, 0),
constructTorrent('HH', 'I am stale', false, 0),
constructTorrent('ABC', 'Nice Torrent', false, 672, 672),
constructTorrent('HH', 'I am completed', true, 0, 0),
constructTorrent('HH', 'I am stale', false, 0, 0),
];
// act
@@ -74,7 +76,7 @@ describe('TorrentTile', () => {
expect(filtered.includes(torrents[2])).toBe(true);
});
it('filter when completed', () => {
it('filter when completed without active torrent', () => {
// arrange
const widget: ITorrent = {
id: 'abc',
@@ -90,13 +92,14 @@ describe('TorrentTile', () => {
labelFilter: [],
labelFilterIsWhitelist: false,
displayCompletedTorrents: false,
displayActiveTorrents: false,
displayStaleTorrents: true,
},
};
const torrents: NormalizedTorrent[] = [
constructTorrent('ABC', 'Nice Torrent', false, 672),
constructTorrent('HH', 'I am completed', true, 0),
constructTorrent('HH', 'I am stale', false, 0),
constructTorrent('ABC', 'Nice Torrent', false, 672, 672),
constructTorrent('HH', 'I am completed', true, 0, 672),
constructTorrent('HH', 'I am stale', false, 0, 0),
];
// act
@@ -109,6 +112,44 @@ describe('TorrentTile', () => {
expect(filtered.at(1)).toBe(torrents[2]);
});
it('filter when completed with active torrent', () => {
// arrange
const widget: ITorrent = {
id: 'abc',
area: {
type: 'sidebar',
properties: {
location: 'left',
},
},
shape: {},
type: 'torrents-status',
properties: {
labelFilter: [],
labelFilterIsWhitelist: false,
displayCompletedTorrents: false,
displayActiveTorrents: true,
displayStaleTorrents: true,
},
};
const torrents: NormalizedTorrent[] = [
constructTorrent('ABC', 'Nice Torrent', false, 672, 672),
constructTorrent('HH', 'I am completed and uploading', true, 0, 672),
constructTorrent('HH', 'I am completed', true, 0, 0),
constructTorrent('HH', 'I am stale', false, 0, 0),
];
// act
const filtered = filterTorrents(widget, torrents);
// assert
expect(filtered.length).toBe(3);
expect(filtered.at(0)).toBe(torrents[0]);
expect(filtered.at(1)).toBe(torrents[1]);
expect(filtered.includes(torrents[2])).toBe(false);
expect(filtered.at(2)).toBe(torrents[3]);
});
it('filter by label when whitelist', () => {
// arrange
const widget: ITorrent = {
@@ -125,13 +166,14 @@ describe('TorrentTile', () => {
labelFilter: ['music', 'movie'],
labelFilterIsWhitelist: true,
displayCompletedTorrents: true,
displayActiveTorrents: true,
displayStaleTorrents: true,
},
};
const torrents: NormalizedTorrent[] = [
constructTorrent('1', 'A sick drop', false, 672, 'music'),
constructTorrent('2', 'I cried', true, 0, 'movie'),
constructTorrent('3', 'Great Animations', false, 0, 'anime'),
constructTorrent('1', 'A sick drop', false, 672, 672, 'music'),
constructTorrent('2', 'I cried', true, 0, 0, 'movie'),
constructTorrent('3', 'Great Animations', false, 0, 0, 'anime'),
];
// act
@@ -160,13 +202,14 @@ describe('TorrentTile', () => {
labelFilter: ['music', 'movie'],
labelFilterIsWhitelist: false,
displayCompletedTorrents: false,
displayActiveTorrents: false,
displayStaleTorrents: true,
},
};
const torrents: NormalizedTorrent[] = [
constructTorrent('ABC', 'Nice Torrent', false, 672, 'anime'),
constructTorrent('HH', 'I am completed', true, 0, 'movie'),
constructTorrent('HH', 'I am stale', false, 0, 'tv'),
constructTorrent('ABC', 'Nice Torrent', false, 672, 672, 'anime'),
constructTorrent('HH', 'I am completed', true, 0, 0, 'movie'),
constructTorrent('HH', 'I am stale', false, 0, 0, 'tv'),
];
// act
@@ -185,6 +228,7 @@ const constructTorrent = (
name: string,
isCompleted: boolean,
downloadSpeed: number,
uploadSpeed: number,
label?: string
): NormalizedTorrent => ({
id,

View File

@@ -40,6 +40,10 @@ const definition = defineWidget({
type: 'switch',
defaultValue: true,
},
displayActiveTorrents: {
type: 'switch',
defaultValue: true,
},
displayStaleTorrents: {
type: 'switch',
defaultValue: true,
@@ -194,7 +198,7 @@ function TorrentTile({ widget }: TorrentTileProps) {
export const filterTorrents = (widget: ITorrent, torrents: NormalizedTorrent[]) => {
let result = torrents;
if (!widget.properties.displayCompletedTorrents) {
result = result.filter((torrent) => !torrent.isCompleted);
result = result.filter((torrent) => !torrent.isCompleted || (widget.properties.displayActiveTorrents && torrent.uploadSpeed > 0));
}
if (widget.properties.labelFilter.length > 0) {