import React from 'react'; import {Button, Col, Form} from 'react-bootstrap'; import style from './GeneralSettings.module.css'; import GlobalInfos from '../../utils/GlobalInfos'; import InfoHeaderItem from '../../elements/InfoHeaderItem/InfoHeaderItem'; import {faArchive, faBalanceScaleLeft, faRulerVertical} from '@fortawesome/free-solid-svg-icons'; import {faAddressCard} from '@fortawesome/free-regular-svg-icons'; import {version} from '../../../package.json'; import {APINode, callAPI} from '../../utils/Api'; import {SettingsTypes} from '../../types/ApiTypes'; import {GeneralSuccess} from '../../types/GeneralTypes'; interface state { generalSettings: SettingsTypes.loadGeneralSettingsType; } interface Props {} /** * Component for Generalsettings tag on Settingspage * handles general settings of mediacenter which concerns to all pages */ class GeneralSettings extends React.Component { constructor(props: Props) { super(props); this.state = { generalSettings: { DarkMode: true, DBSize: 0, DifferentTags: 0, EpisodePath: '', MediacenterName: '', Password: '', PasswordEnabled: false, TagsAdded: 0, TMDBGrabbing: false, VideoNr: 0, VideoPath: '' } }; } componentDidMount(): void { this.loadSettings(); } render(): JSX.Element { const themeStyle = GlobalInfos.getThemeStyle(); return ( <>
{ e.preventDefault(); this.saveSettings(); }}> Video Path this.setState({ generalSettings: { ...this.state.generalSettings, VideoPath: ee.target.value } }) } /> TV Show Path this.setState({ generalSettings: { ...this.state.generalSettings, EpisodePath: e.target.value } }) } /> { this.setState({ generalSettings: { ...this.state.generalSettings, PasswordEnabled: !this.state.generalSettings.PasswordEnabled } }); }} /> {this.state.generalSettings.PasswordEnabled ? ( Password this.setState({ generalSettings: { ...this.state.generalSettings, Password: e.target.value } }) } /> ) : null} { this.setState({ generalSettings: { ...this.state.generalSettings, TMDBGrabbing: !this.state.generalSettings.TMDBGrabbing } }); }} /> { GlobalInfos.enableDarkTheme(!GlobalInfos.isDarkTheme()); }} /> The name of the Mediacenter this.setState({ generalSettings: { ...this.state.generalSettings, MediacenterName: e.target.value } }) } />
Version: {version}
); } /** * inital load of already specified settings from backend */ loadSettings(): void { callAPI(APINode.Settings, {action: 'loadGeneralSettings'}, (result: SettingsTypes.loadGeneralSettingsType) => { this.setState({generalSettings: result}); }); } /** * save the selected and typed settings to the backend */ saveSettings(): void { let settings = this.state.generalSettings; if (!this.state.generalSettings.PasswordEnabled) { settings.Password = '-1'; } settings.DarkMode = GlobalInfos.isDarkTheme(); callAPI( APINode.Settings, { action: 'saveGeneralSettings', Settings: settings }, (result: GeneralSuccess) => { if (result.result) { console.log('successfully saved settings'); // todo 2020-07-10: popup success } else { console.log('failed to save settings'); // todo 2020-07-10: popup error } } ); } } export default GeneralSettings;