import { ImageResolution } from '@jellyfin/sdk/lib/generated-client/models/image-resolution';
import { getConfigurationApi } from '@jellyfin/sdk/lib/utils/api/configuration-api';
import Alert from '@mui/material/Alert';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import MenuItem from '@mui/material/MenuItem';
import Stack from '@mui/material/Stack';
import TextField from '@mui/material/TextField';
import Typography from '@mui/material/Typography';
import { useCountries } from 'apps/dashboard/features/libraries/api/useCountries';
import { useCultures } from 'apps/dashboard/features/libraries/api/useCultures';
import { getImageResolutionOptions } from 'apps/dashboard/features/libraries/utils/metadataOptions';
import Loading from 'components/loading/LoadingComponent';
import Page from 'components/Page';
import ServerConnections from 'components/ServerConnections';
import { QUERY_KEY, useConfiguration } from 'hooks/useConfiguration';
import globalize from 'lib/globalize';
import React from 'react';
import { type ActionFunctionArgs, Form, useActionData, useNavigation } from 'react-router-dom';
import { ActionData } from 'types/actionData';
import { queryClient } from 'utils/query/queryClient';
export const action = async ({ request }: ActionFunctionArgs) => {
const api = ServerConnections.getCurrentApi();
if (!api) throw new Error('No Api instance available');
const formData = await request.formData();
const data = Object.fromEntries(formData);
const { data: config } = await getConfigurationApi(api).getConfiguration();
config.PreferredMetadataLanguage = data.Language.toString();
config.MetadataCountryCode = data.Country.toString();
config.DummyChapterDuration = parseInt(data.DummyChapterDuration.toString(), 10);
config.ChapterImageResolution = data.ChapterImageResolution.toString() as ImageResolution;
await getConfigurationApi(api)
.updateConfiguration({ serverConfiguration: config });
void queryClient.invalidateQueries({
queryKey: [ QUERY_KEY ]
});
return {
isSaved: true
};
};
export const Component = () => {
const {
data: config,
isPending: isConfigPending,
isError: isConfigError
} = useConfiguration();
const {
data: cultures,
isPending: isCulturesPending,
isError: isCulturesError
} = useCultures();
const {
data: countries,
isPending: isCountriesPending,
isError: isCountriesError
} = useCountries();
const navigation = useNavigation();
const actionData = useActionData() as ActionData | undefined;
const isSubmitting = navigation.state === 'submitting';
const imageResolutions = getImageResolutionOptions();
if (isConfigPending || isCulturesPending || isCountriesPending) {
return ;
}
return (
{isConfigError || isCulturesError || isCountriesError ? (
{globalize.translate('MetadataImagesLoadError')}
) : (
)}
);
};
Component.displayName = 'MetadataImagesPage';