Skip to content

Commit

Permalink
Added queued seeding status, restored original "downloading" and
Browse files Browse the repository at this point in the history
"seeding" status text for API use
  • Loading branch information
FinalDoom authored and FinalDoom committed Oct 2, 2021
1 parent c474d1a commit a6f7860
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const TorrentStatusIcon: FC<TorrentStatusIconProps> = memo(({status}: TorrentSta
return <Spinner />;
case 'downloading':
return <Start />;
case 'queued':
case 'downloading-queued':
case 'seeding-queued':
return <Queued />;
case 'seeding':
return <Start />;
Expand Down
4 changes: 2 additions & 2 deletions client/src/javascript/components/sidebar/SidebarFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const SidebarFilter: FC<SidebarFilterProps> = ({

const classNames = classnames('sidebar-filter__item', {
'is-active': isActive,
'queued': slug === 'queued',
'queued': 'downloading-queued' || slug === 'seeding-queued',
});

let name = _name;
Expand All @@ -41,7 +41,7 @@ const SidebarFilter: FC<SidebarFilterProps> = ({
name = i18n._('filter.untagged');
}

if (slug === 'checking' || slug === 'error' || slug === 'queued') {
if (slug === 'checking' || slug === 'error' || slug === 'downloading-queued' || slug === 'seeding-queued') {
if (count === 0) {
return null;
}
Expand Down
7 changes: 6 additions & 1 deletion client/src/javascript/components/sidebar/StatusFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ const StatusFilters: FC = observer(() => {
},
{
label: i18n._('filter.status.queued'),
slug: 'queued',
slug: 'downloading-queued',
icon: <Queued />,
},
{
label: i18n._('filter.status.seeding'),
slug: 'seeding',
icon: <UploadSmall />,
},
{
label: i18n._('filter.status.queued'),
slug: 'seeding-queued',
icon: <Queued />,
},
{
label: i18n._('filter.status.checking'),
slug: 'checking',
Expand Down
9 changes: 9 additions & 0 deletions client/src/javascript/stores/TorrentStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {TorrentProperties, TorrentList} from '@shared/types/Torrent';

import SettingStore from './SettingStore';
import TorrentFilterStore from './TorrentFilterStore';
import { TorrentStatus } from '@shared/constants/torrentStatusMap';

class TorrentStore {
selectedTorrents: Array<string> = [];
Expand Down Expand Up @@ -37,6 +38,14 @@ class TorrentStore {
type: 'status',
filter: statusFilter,
});
if (['downloading','seeding'].includes(statusFilter)) {
const queuedStatus = statusFilter + '-queued' as TorrentStatus;
filteredTorrents = filterTorrents(filteredTorrents, {
type: 'status',
filter: queuedStatus,
negated: true,
});
}
}

if (tagFilter !== '') {
Expand Down
18 changes: 14 additions & 4 deletions client/src/javascript/util/filterTorrents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,48 @@ import type {TorrentStatus} from '@shared/constants/torrentStatusMap';
interface StatusFilter {
type: 'status';
filter: TorrentStatus;
negated?: boolean;
}

interface TrackerFilter {
type: 'tracker';
filter: string;
negated?: boolean;
}

interface TagFilter {
type: 'tag';
filter: string;
negated?: boolean;
}

function filterTorrents(
torrentList: TorrentProperties[],
opts: StatusFilter | TrackerFilter | TagFilter,
): TorrentProperties[] {
const {type, filter} = opts;
const {type, filter, negated} = opts;

if (filter !== '') {
if (type === 'status') {
return torrentList.filter((torrent) => torrent.status.includes(filter as TorrentStatus));
return torrentList.filter((torrent) => {
const included = torrent.status.includes(filter as TorrentStatus);
return included && !negated || !included && negated;
});
}
if (type === 'tracker') {
return torrentList.filter((torrent) => torrent.trackerURIs.includes(filter));
return torrentList.filter((torrent) => {
const included = torrent.trackerURIs.includes(filter);
return included && !negated || !included && negated;
});
}
if (type === 'tag') {
return torrentList.filter((torrent) => {
if (filter === 'untagged') {
return torrent.tags.length === 0;
}

return torrent.tags.includes(filter);
const included = torrent.tags.includes(filter);
return included && !negated || !included && negated;
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion client/src/javascript/util/torrentStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ export const torrentStatusClasses = (
'torrent--is-completed': status.includes('complete'),
'torrent--is-checking': status.includes('checking'),
'torrent--is-inactive': status.includes('inactive'),
'torrent--is-queued': status.includes('downloading-queued') || status.includes('seeding-queued'),
});

export const torrentStatusEffective = (status: TorrentProperties['status']): TorrentProperties['status'][number] => {
let result: TorrentProperties['status'][number] = 'stopped';

['error', 'checking', 'stopped', 'downloading', 'queued', 'seeding'].some((state) => {
['error', 'checking', 'stopped', 'downloading', 'downloading-queued', 'seeding', 'seeding-queued'].some((state) => {
if (status.includes(state as TorrentProperties['status'][number])) {
result = state as TorrentProperties['status'][number];
return true;
Expand Down
8 changes: 4 additions & 4 deletions server/services/Transmission/util/torrentPropertiesUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const getTorrentStatus = (
case TransmissionTorrentStatus.TR_STATUS_CHECK_WAIT:
statuses.push('checking');
break;
case TransmissionTorrentStatus.TR_STATUS_DOWNLOAD_WAIT:
statuses.push('downloading-queued');
case TransmissionTorrentStatus.TR_STATUS_DOWNLOAD:
statuses.push('downloading');
if (rateDownload > 0) {
Expand All @@ -25,11 +27,9 @@ const getTorrentStatus = (
statuses.push('inactive');
}
break;
case TransmissionTorrentStatus.TR_STATUS_DOWNLOAD_WAIT:
statuses.push('queued', 'inactive');
break;
case TransmissionTorrentStatus.TR_STATUS_SEED:
case TransmissionTorrentStatus.TR_STATUS_SEED_WAIT:
statuses.push('seeding-queued');
case TransmissionTorrentStatus.TR_STATUS_SEED:
statuses.push('seeding');
if (rateUpload > 0) {
statuses.push('active');
Expand Down
3 changes: 2 additions & 1 deletion shared/constants/torrentStatusMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const torrentStatusMap = [
'error',
'inactive',
'active',
'queued',
'downloading-queued',
'seeding-queued',
] as const;

export type TorrentStatus = typeof torrentStatusMap[number];
Expand Down

0 comments on commit a6f7860

Please sign in to comment.