import React from "react"; import {Form, Col, Button} from "react-bootstrap"; import style from "./GeneralSettings.module.css" class GeneralSettings extends React.Component { constructor(props) { super(props); this.state = { passwordsupport: false, 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) => { this.setState({ videopath: result.video_path, tvshowpath: result.episode_path, mediacentername: result.mediacenter_name, password: result.password, passwordsupport: result.passwordEnabled }); })); } render() { 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 } 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); fetch('/api/Settings.php', {method: 'POST', body: updateRequest}) .then((response) => response.json() .then((result) => { if (result.success) { // todo 2020-07-10: popup success } else { // todo 2020-07-10: popup error } })); } } export default GeneralSettings;