import React from "react"; import {Button, Col, Form} from "react-bootstrap"; import style from "./GeneralSettings.module.css" import StaticInfos from "../../GlobalInfos"; import darktheme from "../../AppDarkTheme.module.css"; import lighttheme from "../../AppLightTheme.module.css"; class GeneralSettings extends React.Component { constructor(props) { super(props); this.state = { passwordsupport: false, tmdbsupport: null, videopath: "", tvshowpath: "", mediacentername: "", password: "" }; } componentDidMount() { const updateRequest = new FormData(); updateRequest.append('action', 'loadGeneralSettings'); fetch('/api/Settings.php', {method: 'POST', body: updateRequest}) .then((response) => response.json() .then((result) => { console.log(result); this.setState({ videopath: result.video_path, tvshowpath: result.episode_path, mediacentername: result.mediacenter_name, password: result.password, passwordsupport: result.passwordEnabled, tmdbsupport: result.TMDB_grabbing }); })); } render() { const themeStyle = StaticInfos.isDarkTheme() ? darktheme : lighttheme; return ( <>
{ e.preventDefault(); this.saveSettings(); }}> Video Path this.setState({videopath: ee.target.value})}/> TV Show Path this.setState({tvshowpath: e.target.value})}/> { this.setState({passwordsupport: !this.state.passwordsupport}) }} /> {this.state.passwordsupport ? Password this.setState({password: e.target.value})}/> : null } { this.setState({tmdbsupport: !this.state.tmdbsupport}) }} /> { StaticInfos.enableDarkTheme(!StaticInfos.isDarkTheme()); this.forceUpdate(); // todo initiate rerender }} /> The name of the Mediacenter this.setState({mediacentername: e.target.value})}/>
); } saveSettings() { const updateRequest = new FormData(); updateRequest.append('action', 'saveGeneralSettings'); updateRequest.append('password', this.state.passwordsupport ? this.state.password : "-1"); updateRequest.append('videopath', this.state.videopath); updateRequest.append('tvshowpath', this.state.tvshowpath); updateRequest.append('mediacentername', this.state.mediacentername); updateRequest.append("tmdbsupport", this.state.tmdbsupport); fetch('/api/Settings.php', {method: 'POST', body: updateRequest}) .then((response) => response.json() .then((result) => { if (result.success) { 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;