mirror of
https://github.com/ajnart/homarr.git
synced 2025-10-29 01:26:20 +01:00
Add an option to show active torrents when
completed torrents are hidden
This commit is contained in:
1
next-env.d.ts
vendored
1
next-env.d.ts
vendored
@@ -1,6 +1,5 @@
|
|||||||
/// <reference types="next" />
|
/// <reference types="next" />
|
||||||
/// <reference types="next/image-types/global" />
|
/// <reference types="next/image-types/global" />
|
||||||
/// <reference types="next/navigation-types/compat/navigation" />
|
|
||||||
|
|
||||||
// NOTE: This file should not be edited
|
// NOTE: This file should not be edited
|
||||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
"displayCompletedTorrents": {
|
"displayCompletedTorrents": {
|
||||||
"label": "Display completed torrents"
|
"label": "Display completed torrents"
|
||||||
},
|
},
|
||||||
|
"displayActiveTorrents": {
|
||||||
|
"label": "Show active torrents when completed torrents are hidden"
|
||||||
|
},
|
||||||
"displayStaleTorrents": {
|
"displayStaleTorrents": {
|
||||||
"label": "Display stale torrents"
|
"label": "Display stale torrents"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
"displayCompletedTorrents": {
|
"displayCompletedTorrents": {
|
||||||
"label": "Cacher les torrents terminés"
|
"label": "Cacher les torrents terminés"
|
||||||
},
|
},
|
||||||
|
"displayActiveTorrents": {
|
||||||
|
"label": "Afficher les torrents actifs quand les torrents terminés sont masqués"
|
||||||
|
},
|
||||||
"displayStaleTorrents": {
|
"displayStaleTorrents": {
|
||||||
"label": "Afficher les torrents périmés"
|
"label": "Afficher les torrents périmés"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,13 +20,14 @@ describe('TorrentTile', () => {
|
|||||||
labelFilter: [],
|
labelFilter: [],
|
||||||
labelFilterIsWhitelist: false,
|
labelFilterIsWhitelist: false,
|
||||||
displayCompletedTorrents: true,
|
displayCompletedTorrents: true,
|
||||||
|
displayActiveTorrents: true,
|
||||||
displayStaleTorrents: false,
|
displayStaleTorrents: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const torrents: NormalizedTorrent[] = [
|
const torrents: NormalizedTorrent[] = [
|
||||||
constructTorrent('ABC', 'Nice Torrent', false, 672),
|
constructTorrent('ABC', 'Nice Torrent', false, 672, 672),
|
||||||
constructTorrent('HH', 'I am completed', true, 0),
|
constructTorrent('HH', 'I am completed', true, 0, 0),
|
||||||
constructTorrent('HH', 'I am stale', false, 0),
|
constructTorrent('HH', 'I am stale', false, 0, 0),
|
||||||
];
|
];
|
||||||
|
|
||||||
// act
|
// act
|
||||||
@@ -55,13 +56,14 @@ describe('TorrentTile', () => {
|
|||||||
labelFilter: [],
|
labelFilter: [],
|
||||||
labelFilterIsWhitelist: false,
|
labelFilterIsWhitelist: false,
|
||||||
displayCompletedTorrents: true,
|
displayCompletedTorrents: true,
|
||||||
|
displayActiveTorrents: true,
|
||||||
displayStaleTorrents: true,
|
displayStaleTorrents: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const torrents: NormalizedTorrent[] = [
|
const torrents: NormalizedTorrent[] = [
|
||||||
constructTorrent('ABC', 'Nice Torrent', false, 672),
|
constructTorrent('ABC', 'Nice Torrent', false, 672, 672),
|
||||||
constructTorrent('HH', 'I am completed', true, 0),
|
constructTorrent('HH', 'I am completed', true, 0, 0),
|
||||||
constructTorrent('HH', 'I am stale', false, 0),
|
constructTorrent('HH', 'I am stale', false, 0, 0),
|
||||||
];
|
];
|
||||||
|
|
||||||
// act
|
// act
|
||||||
@@ -74,7 +76,7 @@ describe('TorrentTile', () => {
|
|||||||
expect(filtered.includes(torrents[2])).toBe(true);
|
expect(filtered.includes(torrents[2])).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('filter when completed', () => {
|
it('filter when completed without active torrent', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const widget: ITorrent = {
|
const widget: ITorrent = {
|
||||||
id: 'abc',
|
id: 'abc',
|
||||||
@@ -90,13 +92,14 @@ describe('TorrentTile', () => {
|
|||||||
labelFilter: [],
|
labelFilter: [],
|
||||||
labelFilterIsWhitelist: false,
|
labelFilterIsWhitelist: false,
|
||||||
displayCompletedTorrents: false,
|
displayCompletedTorrents: false,
|
||||||
|
displayActiveTorrents: false,
|
||||||
displayStaleTorrents: true,
|
displayStaleTorrents: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const torrents: NormalizedTorrent[] = [
|
const torrents: NormalizedTorrent[] = [
|
||||||
constructTorrent('ABC', 'Nice Torrent', false, 672),
|
constructTorrent('ABC', 'Nice Torrent', false, 672, 672),
|
||||||
constructTorrent('HH', 'I am completed', true, 0),
|
constructTorrent('HH', 'I am completed', true, 0, 672),
|
||||||
constructTorrent('HH', 'I am stale', false, 0),
|
constructTorrent('HH', 'I am stale', false, 0, 0),
|
||||||
];
|
];
|
||||||
|
|
||||||
// act
|
// act
|
||||||
@@ -109,6 +112,44 @@ describe('TorrentTile', () => {
|
|||||||
expect(filtered.at(1)).toBe(torrents[2]);
|
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', () => {
|
it('filter by label when whitelist', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const widget: ITorrent = {
|
const widget: ITorrent = {
|
||||||
@@ -125,13 +166,14 @@ describe('TorrentTile', () => {
|
|||||||
labelFilter: ['music', 'movie'],
|
labelFilter: ['music', 'movie'],
|
||||||
labelFilterIsWhitelist: true,
|
labelFilterIsWhitelist: true,
|
||||||
displayCompletedTorrents: true,
|
displayCompletedTorrents: true,
|
||||||
|
displayActiveTorrents: true,
|
||||||
displayStaleTorrents: true,
|
displayStaleTorrents: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const torrents: NormalizedTorrent[] = [
|
const torrents: NormalizedTorrent[] = [
|
||||||
constructTorrent('1', 'A sick drop', false, 672, 'music'),
|
constructTorrent('1', 'A sick drop', false, 672, 672, 'music'),
|
||||||
constructTorrent('2', 'I cried', true, 0, 'movie'),
|
constructTorrent('2', 'I cried', true, 0, 0, 'movie'),
|
||||||
constructTorrent('3', 'Great Animations', false, 0, 'anime'),
|
constructTorrent('3', 'Great Animations', false, 0, 0, 'anime'),
|
||||||
];
|
];
|
||||||
|
|
||||||
// act
|
// act
|
||||||
@@ -160,13 +202,14 @@ describe('TorrentTile', () => {
|
|||||||
labelFilter: ['music', 'movie'],
|
labelFilter: ['music', 'movie'],
|
||||||
labelFilterIsWhitelist: false,
|
labelFilterIsWhitelist: false,
|
||||||
displayCompletedTorrents: false,
|
displayCompletedTorrents: false,
|
||||||
|
displayActiveTorrents: false,
|
||||||
displayStaleTorrents: true,
|
displayStaleTorrents: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const torrents: NormalizedTorrent[] = [
|
const torrents: NormalizedTorrent[] = [
|
||||||
constructTorrent('ABC', 'Nice Torrent', false, 672, 'anime'),
|
constructTorrent('ABC', 'Nice Torrent', false, 672, 672, 'anime'),
|
||||||
constructTorrent('HH', 'I am completed', true, 0, 'movie'),
|
constructTorrent('HH', 'I am completed', true, 0, 0, 'movie'),
|
||||||
constructTorrent('HH', 'I am stale', false, 0, 'tv'),
|
constructTorrent('HH', 'I am stale', false, 0, 0, 'tv'),
|
||||||
];
|
];
|
||||||
|
|
||||||
// act
|
// act
|
||||||
@@ -185,6 +228,7 @@ const constructTorrent = (
|
|||||||
name: string,
|
name: string,
|
||||||
isCompleted: boolean,
|
isCompleted: boolean,
|
||||||
downloadSpeed: number,
|
downloadSpeed: number,
|
||||||
|
uploadSpeed: number,
|
||||||
label?: string
|
label?: string
|
||||||
): NormalizedTorrent => ({
|
): NormalizedTorrent => ({
|
||||||
id,
|
id,
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ const definition = defineWidget({
|
|||||||
type: 'switch',
|
type: 'switch',
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
},
|
},
|
||||||
|
displayActiveTorrents: {
|
||||||
|
type: 'switch',
|
||||||
|
defaultValue: true,
|
||||||
|
},
|
||||||
displayStaleTorrents: {
|
displayStaleTorrents: {
|
||||||
type: 'switch',
|
type: 'switch',
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
@@ -194,7 +198,7 @@ function TorrentTile({ widget }: TorrentTileProps) {
|
|||||||
export const filterTorrents = (widget: ITorrent, torrents: NormalizedTorrent[]) => {
|
export const filterTorrents = (widget: ITorrent, torrents: NormalizedTorrent[]) => {
|
||||||
let result = torrents;
|
let result = torrents;
|
||||||
if (!widget.properties.displayCompletedTorrents) {
|
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) {
|
if (widget.properties.labelFilter.length > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user