import React, { useState } from 'react'; import LoadingSpinner from '../Common/LoadingSpinner'; import type { PlexSettings } from '../../../server/lib/settings'; import useSWR from 'swr'; import { useFormik } from 'formik'; import Button from '../Common/Button'; import axios from 'axios'; import LibraryItem from './LibraryItem'; const SettingsPlex: React.FC = () => { const { data, error, revalidate } = useSWR( '/api/v1/settings/plex' ); const [isSyncing, setIsSyncing] = useState(false); const [isUpdating, setIsUpdating] = useState(false); const [submitError, setSubmitError] = useState(null); const formik = useFormik({ initialValues: { hostname: data?.ip, port: data?.port, }, enableReinitialize: true, onSubmit: async (values) => { setIsUpdating(true); try { await axios.post('/api/v1/settings/plex', { ip: values.hostname, port: values.port, } as PlexSettings); revalidate(); } catch (e) { setSubmitError(e.message); } finally { setIsUpdating(false); } }, }); const activeLibraries = data?.libraries .filter((library) => library.enabled) .map((library) => library.id) ?? []; const syncLibraries = async () => { setIsSyncing(true); await axios.get('/api/v1/settings/plex/library', { params: { sync: true, enable: activeLibraries.length > 0 ? activeLibraries.join(',') : undefined, }, }); setIsSyncing(false); revalidate(); }; const toggleLibrary = async (libraryId: string) => { setIsSyncing(true); if (activeLibraries.includes(libraryId)) { await axios.get('/api/v1/settings/plex/library', { params: { enable: activeLibraries.length > 0 ? activeLibraries.filter((id) => id !== libraryId).join(',') : undefined, }, }); } else { await axios.get('/api/v1/settings/plex/library', { params: { enable: [...activeLibraries, libraryId].join(','), }, }); } setIsSyncing(false); revalidate(); }; if (!data && !error) { return ; } return ( <>

Plex Settings

Configure the settings for your Plex server. Overseerr uses your Plex server to scan your library at an interval and see what content is available.

Plex Libraries

These are the libraries Overseerr will scan for titles. If you see no libraries listed, you will need to run at least one sync by clicking the button below. You must first configure and save your plex connection settings before you will be able to retrieve your libraries.

    {data?.libraries.map((library) => ( toggleLibrary(library.id)} /> ))}
); }; export default SettingsPlex;