Skip to content

Commit 14fe232

Browse files
committed
Make manual link toasts great ~~again~~!
1 parent c7697db commit 14fe232

File tree

1 file changed

+39
-32
lines changed

1 file changed

+39
-32
lines changed

src/pages/utilities/UnrecognizedUtilityTabs/LinkFilesTab.tsx

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from '@mdi/js';
1414
import { Icon } from '@mdi/react';
1515
import cx from 'classnames';
16-
import { filter, find, findIndex, forEach, groupBy, map, orderBy, reduce, toInteger, uniqBy } from 'lodash';
16+
import { countBy, filter, find, findIndex, forEach, groupBy, map, orderBy, reduce, toInteger, uniqBy } from 'lodash';
1717
import { useImmer } from 'use-immer';
1818
import { useDebounceValue } from 'usehooks-ts';
1919

@@ -488,37 +488,44 @@ function LinkFilesTab() {
488488
return;
489489
}
490490

491-
await Promise.all([
492-
...map(none, ({ FileID }) => {
493-
if (FileID === 0) return;
494-
const { path = '<missing file path>' } = showDataMap.get(FileID)!;
495-
toast.warning('Episode linking skipped!', `Path: ${path}`);
496-
}),
497-
...map(oneToOne, ({ EpisodeID, FileID }) => {
498-
const { path = '<missing file path>' } = showDataMap.get(FileID)!;
499-
return linkOneFileToManyEpisodes({ episodeIDs: [EpisodeID], fileId: FileID }, {
500-
onSuccess: () => toast.success('Scheduled a 1:1 mapping for linking!', `Path: ${path}`),
501-
onError: () => toast.error('Failed at 1:1 linking!', `Path: ${path}`),
502-
});
503-
}),
504-
...map(oneToMany, ({ EpisodeIDs, FileID }) => {
505-
const { path = '<missing file path>' } = showDataMap.get(FileID)!;
506-
return linkOneFileToManyEpisodes({ episodeIDs: EpisodeIDs, fileId: FileID }, {
507-
onSuccess: () => toast.success(`Scheduled a 1:${EpisodeIDs.length} mapping for linking!`, `Path: ${path}`),
508-
onError: () => toast.error(`Failed at 1:${EpisodeIDs.length} linked!`, `Path: ${path}`),
509-
});
510-
}),
511-
...map(manyToOne, ({ EpisodeID, FileIDs }) => {
512-
const episode = find(episodes, ['ID', EpisodeID]);
513-
const episodeDetails = episode
514-
? `Episode: ${episode.EpisodeNumber} - ${episode.Title}`
515-
: `Episode: ${EpisodeID}`;
516-
return linkManyFilesToOneEpisode({ episodeID: EpisodeID, fileIDs: FileIDs }, {
517-
onSuccess: () => toast.success(`Scheduled a ${FileIDs.length}:1 mapping for linking!`, episodeDetails),
518-
onError: () => toast.error(`Failed at ${FileIDs.length}:1 linking!`, episodeDetails),
519-
});
520-
}),
521-
]);
491+
forEach(none, ({ FileID }) => {
492+
if (FileID === 0) return;
493+
const { path = '<missing file path>' } = showDataMap.get(FileID)!;
494+
toast.warning('Episode linking skipped!', `Path: ${path}`);
495+
});
496+
497+
await Promise
498+
.allSettled(map(
499+
oneToOne,
500+
({ EpisodeID, FileID }) => linkOneFileToManyEpisodes({ episodeIDs: [EpisodeID], fileId: FileID }),
501+
))
502+
.then((results) => {
503+
const counts = countBy(results, 'status');
504+
if (counts.fulfilled > 0) toast.success(`Scheduled a 1:1 linking for ${counts.fulfilled} files!`);
505+
if (counts.rejected > 0) toast.error(`Failed 1:1 linking for ${counts.rejected} files!`);
506+
});
507+
508+
await Promise
509+
.allSettled(map(
510+
oneToMany,
511+
({ EpisodeIDs, FileID }) => linkOneFileToManyEpisodes({ episodeIDs: EpisodeIDs, fileId: FileID }),
512+
))
513+
.then((results) => {
514+
const counts = countBy(results, 'status');
515+
if (counts.fulfilled > 0) toast.success(`Scheduled a 1:N linking for ${counts.fulfilled} files!`);
516+
if (counts.rejected > 0) toast.error(`Failed 1:N linking for ${counts.rejected} files!`);
517+
});
518+
519+
await Promise
520+
.allSettled(map(
521+
manyToOne,
522+
({ EpisodeID, FileIDs }) => linkManyFilesToOneEpisode({ episodeID: EpisodeID, fileIDs: FileIDs }),
523+
))
524+
.then((results) => {
525+
const counts = countBy(results, 'status');
526+
if (counts.fulfilled > 0) toast.success(`Scheduled an N:1 linking for ${counts.fulfilled} files!`);
527+
if (counts.rejected > 0) toast.error(`Failed N:1 linking for ${counts.rejected} files!`);
528+
});
522529

523530
setLoading({ isLinking: false, isLinkingRunning: false, createdNewSeries: false });
524531
setLinks([]);

0 commit comments

Comments
 (0)