componentDidMount() {
window.addEventListener('scroll', this.handleScroll);
},
componentWillUnmount() {
window.removeEventListener('scroll', this.handleScroll);
},
handleScroll=(event)=> {
var hiddenInput = document.createElement("mainNav");
hiddenInput.setAttribute("className", "nav-scrolled nav-scrolled-links top_nums");
},
const logInWithLoagInAndPassword = (login, password, organization, rememberMe) => {
return dispatch => {
return fetch(BASE_URL + '?username=' + login + '&password=' + password + '&customer=' + organization + '&remember=' + remember + '&login=Inloggen&ajax=1', {
method: 'GET',
headers: {
"Access-Control-Allow-Origin": "*"
}
}).then(response => {
return response.json();
}).then(json => {
if (rememberMe) {
localStorage.setItem('sessionid', json.sessionid)
localStorage.setItem('auth', JSON.stringify(json))
} else {
//clear localstorage
}
dispatch({type: AUTH_SUCCESS, payload: json})
}
)
.catch(error => {
console.error('error', error)
dispatch({type: AUTH_ERROR, payload: error})
});
}
}
let data = [{
"id": {
"title": "Id",
"value": 19,
},
"title": {
"title": "Title",
"value": " Режиссёр \"Доктора Хауса\" снимет новый фильм"
},
"slug": {
"title": "Slug",
"value": "slug2334",
}
},
{
"id": {
"title": "Id",
"value": 8,
},
"title": {
"title": "Title",
"value": "Колониальная сказка. «Жги», режиссер Кирилл Плетнев",
},
"slug": {
"title": "Slug",
"value": "6643766f8e8d9b39fcbf818d677f4fbe",
}
}]
let newObj=[];
Object.keys(data).map(
el=>newObj.push({'id':data[el].id.value,'slug':data[el].slug.value,'title':data[el].title.value})
);
class MainPage extends Component {
constructor(props) {
super(props);
this.state = {
newPerson: {
}
};
this.getInputNameValue = this.getInputNameValue.bind(this);
this.getInputSurnameValue = this.getInputSurnameValue.bind(this);
this.getInputCityValue = this.getInputCityValue.bind(this);
this.addToDatabase = this.addToDatabase.bind(this);
}
setNewPerson=(user)=>{
this.setState({
newPerson:user
})
}
addToDatabase() {
fetch(`http://127.0.0.1:3000/add/${this.state.newPerson}`, {
method: 'PUT'
})
<...>
}
render() {
return (
<div>
<InputForm setNewPerson={this.setNewPerson} />
<Footer addToDatabase={this.addToDatabase}/>
</div>
);
}
}
class InputForm extends Component {
constructor(props) {
super(props);
this.state = {
user:{
nameP: '',
surnameP: '',
cityP: '',
value: ''
}
};
this.handleNameChange = this.handleNameChange.bind(this);
this.handleSurnameChange = this.handleSurnameChange.bind(this);
this.handleCityChange = this.handleCityChange.bind(this);
}
handleNameChange(event) {
let user = this.state.user
let newUser = Object.assign(user,{nameP:event.target.value})
this.setState({ user: newUser });
this.props.setNewPerson(this.state.user);
}
handleSurnameChange(event) {
let user = this.state.user
let newUser = Object.assign(user,{surnameP:e.target.value})
this.setState({ user: newUser });
this.props.setNewPerson(this.state.user)
}
handleCityChange(event) {
let user = this.state.user
let newUser = Object.assign(user,{cityP:e.target.value})
this.setState({ user: newUser });
this.props.setNewPerson(this.state.user)
}
render() {
return (
<form className='row form'>
<label className='col-4 form__label' htmlFor='surnameMembers'>Фамилия</label>
<input className='col-6 form-control' id='surnameMembers' name='surnameMembers'
type='text' required value={this.state.surnameP}
onChange={this.handleSurnameChange}
/>
<label className='col-4 form__label' htmlFor='nameMembers'>Имя</label>
<input className='col-6 form-control' id='nameMembers' name='nameMembers'
type='text' required value={this.state.nameP}
onChange={this.handleNameChange}
/>
<label className='col-4 form__label' htmlFor='cityMembers'>Город</label>
<input className='col-6 form-control' id='cityMembers' name='cityMembers'
type='text' required value={this.state.cityP}
onChange={this.handleCityChange}
/>
</form>
);
}
}
onBackPress = () => {
const { dispatch, nav } = this.props
if (nav.index === 0) {
return false
}
dispatch(NavigationActions.back())
return true
}
componentWillReceiveProps(nextProps) {
console.log("nextProps.idcat",nextProps.idcat)
if (nextProps.idcat!==undefined){
fetch(`${ENV.API_PROT}${ENV.API_LINK}/api/${ENV.API_VER_GLOBAL}/categories/${nextProps.idcat}`)
.then(response => response.json())
.then(json => {
console.log(json);
this.setState({
sameNews: json.data,
isLoading: false
});
console.log(this.state.sameNews);
});
}
}