diff --git a/client/src/javascript/actions/TorrentActions.ts b/client/src/javascript/actions/TorrentActions.ts index ae8fa2e7..00e7d607 100644 --- a/client/src/javascript/actions/TorrentActions.ts +++ b/client/src/javascript/actions/TorrentActions.ts @@ -12,6 +12,7 @@ import type { DeleteTorrentsOptions, MoveTorrentsOptions, SetTorrentContentsPropertiesOptions, + SetTorrentsInitialSeedingOptions, SetTorrentsPriorityOptions, SetTorrentsSequentialOptions, SetTorrentsTrackersOptions, @@ -194,6 +195,19 @@ const TorrentActions = { return undefined; }, + setInitialSeeding: (options: SetTorrentsInitialSeedingOptions) => + axios + .patch(`${baseURI}api/torrents/initial-seeding`, options) + .then((json) => json.data) + .then( + () => { + // do nothing. + }, + () => { + // do nothing. + }, + ), + setPriority: (options: SetTorrentsPriorityOptions) => axios .patch(`${baseURI}api/torrents/priority`, options) diff --git a/client/src/javascript/components/torrent-list/TorrentListContextMenu.tsx b/client/src/javascript/components/torrent-list/TorrentListContextMenu.tsx index b53d9b21..efa46c73 100644 --- a/client/src/javascript/components/torrent-list/TorrentListContextMenu.tsx +++ b/client/src/javascript/components/torrent-list/TorrentListContextMenu.tsx @@ -13,26 +13,23 @@ import UIActions from '../../actions/UIActions'; import type {ContextMenuItem} from '../../stores/UIStore'; -// TODO: need to create a generic component if there are more menu items like this. -const InlineSequentialCheckbox: FC = observer(() => { - const {selectedTorrents} = TorrentStore; +const getLastSelectedTorrent = (): string => TorrentStore.selectedTorrents[TorrentStore.selectedTorrents.length - 1]; - return ( +const InlineTorrentPropertyCheckbox: FC<{property: keyof TorrentProperties}> = observer( + ({property}: {property: keyof TorrentProperties}) => ( - ); -}); + ), +); const handleTorrentDownload = (hash: TorrentProperties['hash']): void => { const {baseURI} = ConfigStore; @@ -124,10 +121,9 @@ const getContextMenuItems = (torrent: TorrentProperties): Array action: 'torrentDetails', label: TorrentContextMenuActions.torrentDetails.id, clickHandler: () => { - const {selectedTorrents} = TorrentStore; UIActions.displayModal({ id: 'torrent-details', - hash: selectedTorrents[selectedTorrents.length - 1], + hash: getLastSelectedTorrent(), }); }, }, @@ -136,9 +132,8 @@ const getContextMenuItems = (torrent: TorrentProperties): Array action: 'torrentDownload', label: TorrentContextMenuActions.torrentDownload.id, clickHandler: (e) => { - const {selectedTorrents} = TorrentStore; e.preventDefault(); - handleTorrentDownload(selectedTorrents[selectedTorrents.length - 1]); + handleTorrentDownload(getLastSelectedTorrent()); }, }, { @@ -149,6 +144,20 @@ const getContextMenuItems = (torrent: TorrentProperties): Array UIActions.displayModal({id: 'generate-magnet'}); }, }, + { + type: 'action', + action: 'setInitialSeeding', + label: TorrentContextMenuActions.setInitialSeeding.id, + clickHandler: () => { + const {selectedTorrents} = TorrentStore; + TorrentActions.setInitialSeeding({ + hashes: selectedTorrents, + isInitialSeeding: !TorrentStore.torrents[getLastSelectedTorrent()].isInitialSeeding, + }); + }, + dismissMenu: false, + labelAction: () => , + }, { type: 'action', action: 'setSequential', @@ -157,11 +166,11 @@ const getContextMenuItems = (torrent: TorrentProperties): Array const {selectedTorrents} = TorrentStore; TorrentActions.setSequential({ hashes: selectedTorrents, - isSequential: !TorrentStore.torrents[selectedTorrents[selectedTorrents.length - 1]].isSequential, + isSequential: !TorrentStore.torrents[getLastSelectedTorrent()].isSequential, }); }, dismissMenu: false, - labelAction: () => , + labelAction: () => , }, { type: 'action', diff --git a/client/src/javascript/constants/TorrentContextMenuActions.ts b/client/src/javascript/constants/TorrentContextMenuActions.ts index 9bd140f2..394c8917 100644 --- a/client/src/javascript/constants/TorrentContextMenuActions.ts +++ b/client/src/javascript/constants/TorrentContextMenuActions.ts @@ -29,6 +29,9 @@ const TorrentContextMenuActions = { generateMagnet: { id: 'torrents.list.context.generate.magnet', }, + setInitialSeeding: { + id: 'torrents.list.context.initial.seeding', + }, setSequential: { id: 'torrents.list.context.sequential', }, diff --git a/client/src/javascript/i18n/strings.compiled.json b/client/src/javascript/i18n/strings.compiled.json index 46ea2aaa..6b049448 100644 --- a/client/src/javascript/i18n/strings.compiled.json +++ b/client/src/javascript/i18n/strings.compiled.json @@ -2221,6 +2221,12 @@ "value": "Generate Magnet Link" } ], + "torrents.list.context.initial.seeding": [ + { + "type": 0, + "value": "Initial Seeding" + } + ], "torrents.list.context.move": [ { "type": 0, diff --git a/client/src/javascript/i18n/strings.json b/client/src/javascript/i18n/strings.json index 00574a2a..7b34107e 100644 --- a/client/src/javascript/i18n/strings.json +++ b/client/src/javascript/i18n/strings.json @@ -317,6 +317,7 @@ "torrents.list.context.move": "Set Torrent Location", "torrents.list.context.pause": "Pause", "torrents.list.context.download": "Download", + "torrents.list.context.initial.seeding": "Initial Seeding", "torrents.list.context.priority": "Priority", "torrents.list.context.remove": "Remove", "torrents.list.context.sequential": "Sequential", diff --git a/shared/constants/defaultFloodSettings.ts b/shared/constants/defaultFloodSettings.ts index f644267a..a330161e 100644 --- a/shared/constants/defaultFloodSettings.ts +++ b/shared/constants/defaultFloodSettings.ts @@ -59,6 +59,7 @@ const defaultFloodSettings: Readonly = { {id: 'torrentDetails', visible: true}, {id: 'torrentDownload', visible: true}, {id: 'generateMagnet', visible: false}, + {id: 'setInitialSeeding', visible: false}, {id: 'setSequential', visible: false}, {id: 'setPriority', visible: false}, ],