fix(frontend): handle currentLibrary possibly being null on first manual sync

pull/551/head
sct 4 years ago
parent 12db7a065a
commit 93b57a76f1

@ -48,7 +48,7 @@ interface SyncStatus {
running: boolean; running: boolean;
progress: number; progress: number;
total: number; total: number;
currentLibrary: Library; currentLibrary?: Library;
libraries: Library[]; libraries: Library[];
} }
@ -86,12 +86,17 @@ const SettingsPlex: React.FC<SettingsPlexProps> = ({ onComplete }) => {
const syncLibraries = async () => { const syncLibraries = async () => {
setIsSyncing(true); setIsSyncing(true);
await axios.get('/api/v1/settings/plex/library', {
params: { const params: { sync: boolean; enable?: string } = {
sync: true, sync: true,
enable: };
activeLibraries.length > 0 ? activeLibraries.join(',') : undefined,
}, if (activeLibraries.length > 0) {
params.enable = activeLibraries.join(',');
}
await axios.get('/api/v1/settings/plex/library', {
params,
}); });
setIsSyncing(false); setIsSyncing(false);
revalidate(); revalidate();
@ -118,13 +123,16 @@ const SettingsPlex: React.FC<SettingsPlexProps> = ({ onComplete }) => {
const toggleLibrary = async (libraryId: string) => { const toggleLibrary = async (libraryId: string) => {
setIsSyncing(true); setIsSyncing(true);
if (activeLibraries.includes(libraryId)) { if (activeLibraries.includes(libraryId)) {
const params: { enable?: string } = {};
if (activeLibraries.length > 1) {
params.enable = activeLibraries
.filter((id) => id !== libraryId)
.join(',');
}
await axios.get('/api/v1/settings/plex/library', { await axios.get('/api/v1/settings/plex/library', {
params: { params,
enable:
activeLibraries.length > 0
? activeLibraries.filter((id) => id !== libraryId).join(',')
: undefined,
},
}); });
} else { } else {
await axios.get('/api/v1/settings/plex/library', { await axios.get('/api/v1/settings/plex/library', {
@ -369,6 +377,7 @@ const SettingsPlex: React.FC<SettingsPlexProps> = ({ onComplete }) => {
<div className="flex flex-col w-full sm:flex-row"> <div className="flex flex-col w-full sm:flex-row">
{dataSync?.running && ( {dataSync?.running && (
<> <>
{dataSync.currentLibrary && (
<div className="flex items-center mb-2 mr-0 sm:mb-0 sm:mr-2"> <div className="flex items-center mb-2 mr-0 sm:mb-0 sm:mr-2">
<Badge> <Badge>
<FormattedMessage <FormattedMessage
@ -377,17 +386,20 @@ const SettingsPlex: React.FC<SettingsPlexProps> = ({ onComplete }) => {
/> />
</Badge> </Badge>
</div> </div>
)}
<div className="flex items-center"> <div className="flex items-center">
<Badge badgeType="warning"> <Badge badgeType="warning">
<FormattedMessage <FormattedMessage
{...messages.librariesRemaining} {...messages.librariesRemaining}
values={{ values={{
count: dataSync.libraries.slice( count: dataSync.currentLibrary
? dataSync.libraries.slice(
dataSync.libraries.findIndex( dataSync.libraries.findIndex(
(library) => (library) =>
library.id === dataSync.currentLibrary.id library.id === dataSync.currentLibrary?.id
) + 1 ) + 1
).length, ).length
: 0,
}} }}
/> />
</Badge> </Badge>

Loading…
Cancel
Save