mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
fix(frontend): handle currentLibrary possibly being null on first manual sync
This commit is contained in:
@@ -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);
|
||||||
|
|
||||||
|
const params: { sync: boolean; enable?: string } = {
|
||||||
|
sync: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (activeLibraries.length > 0) {
|
||||||
|
params.enable = activeLibraries.join(',');
|
||||||
|
}
|
||||||
|
|
||||||
await axios.get('/api/v1/settings/plex/library', {
|
await axios.get('/api/v1/settings/plex/library', {
|
||||||
params: {
|
params,
|
||||||
sync: true,
|
|
||||||
enable:
|
|
||||||
activeLibraries.length > 0 ? activeLibraries.join(',') : undefined,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
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,25 +377,29 @@ 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 && (
|
||||||
<>
|
<>
|
||||||
<div className="flex items-center mb-2 mr-0 sm:mb-0 sm:mr-2">
|
{dataSync.currentLibrary && (
|
||||||
<Badge>
|
<div className="flex items-center mb-2 mr-0 sm:mb-0 sm:mr-2">
|
||||||
<FormattedMessage
|
<Badge>
|
||||||
{...messages.currentlibrary}
|
<FormattedMessage
|
||||||
values={{ name: dataSync.currentLibrary.name }}
|
{...messages.currentlibrary}
|
||||||
/>
|
values={{ name: dataSync.currentLibrary.name }}
|
||||||
</Badge>
|
/>
|
||||||
</div>
|
</Badge>
|
||||||
|
</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.findIndex(
|
? dataSync.libraries.slice(
|
||||||
(library) =>
|
dataSync.libraries.findIndex(
|
||||||
library.id === dataSync.currentLibrary.id
|
(library) =>
|
||||||
) + 1
|
library.id === dataSync.currentLibrary?.id
|
||||||
).length,
|
) + 1
|
||||||
|
).length
|
||||||
|
: 0,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Badge>
|
</Badge>
|
||||||
|
Reference in New Issue
Block a user