138 lines
4.0 KiB
JavaScript
138 lines
4.0 KiB
JavaScript
// IMPORT MODULES
|
|
import React, { useEffect } from "react";
|
|
import axios from "axios";
|
|
import i18n from '../i18n';
|
|
import '../i18n';
|
|
import { withTranslation } from 'react-i18next';
|
|
|
|
// IMPORT COMPONENTS
|
|
import Breadcrumb from "../components/Global/Breadcrumb";
|
|
|
|
// const Legislation = () => {
|
|
// useEffect(() => {
|
|
// window.scrollTo(0, 0);
|
|
// }, []);
|
|
class Legislation extends React.Component {
|
|
_isMounted = false;
|
|
constructor(props) {
|
|
super(props);
|
|
|
|
this.state = {
|
|
items: [],
|
|
DataisLoaded: false
|
|
};
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.getTodos();
|
|
}
|
|
|
|
async getTodos() {
|
|
this._isMounted = true;
|
|
await axios.get('http://127.0.0.1:8000/api/v1/categories/6')
|
|
.then(res => {
|
|
const items = res.data;
|
|
if (this._isMounted) {
|
|
this.setState({
|
|
items: items,
|
|
DataisLoaded: true
|
|
});
|
|
// let elem = document.querySelector('.law-card-text');
|
|
// if(i18n.language == 'en')
|
|
// {
|
|
// console.log(JSON.parse(this.state.items['data'][0]['posts'][0]['translations'][1]['attribute_data']).title);
|
|
// }
|
|
// else if (i18n.language == 'ru')
|
|
// {
|
|
// elem.innerHTML= this.state.items['data'][0]['posts']['title'];
|
|
// }
|
|
// else {
|
|
// elem.innerHTML= JSON.parse(this.state.items['data'][0]['posts'][1]['translations'][0]['attribute_data']).title;
|
|
// }
|
|
|
|
this._isMounted = false;
|
|
// console.log(this.state.items['data'][0]['posts']);
|
|
console.log('salam_test');
|
|
// console.log(JSON.parse(this.state.items['data'][0]['posts'][0]['translations'][0]['attribute_data']).title );
|
|
|
|
}
|
|
|
|
})
|
|
// console.log('salam');
|
|
// console.log(this.state.items['data']);
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
console.log("etalon gutardy");
|
|
}
|
|
|
|
render() {
|
|
const { DataisLoaded, items } = this.state;
|
|
if (!DataisLoaded) return <div>
|
|
<h1> Pleses wait some time.... </h1> </div> ;
|
|
|
|
if(i18n.language == 'en')
|
|
{
|
|
this.componentDidMount();
|
|
console.log('salam-en');
|
|
|
|
}
|
|
else
|
|
{
|
|
this.componentDidMount();
|
|
console.log('salam-ruru');
|
|
}
|
|
|
|
return (
|
|
<section className="legislation">
|
|
<Breadcrumb path_1="Законодательная база" currentUrl="/legislation" />
|
|
<div className="container">
|
|
<div className="legislation-inner">
|
|
<div className="tab-header">
|
|
<h4 className="tab-header-text" id="tab-header-text">
|
|
Законодательная база
|
|
</h4>
|
|
<div className="tab-header-line"></div>
|
|
</div>
|
|
<div className="law-card-wrapper">
|
|
|
|
{items['data'][0]['posts'].map((item) => (
|
|
<div className="law-card" key={item.id}>
|
|
<p className="law-card-text">
|
|
|
|
{ i18n.language == 'en' &&
|
|
JSON.parse(item['translations'][0]['attribute_data']).title
|
|
}
|
|
{ i18n.language == 'ru' &&
|
|
item.title
|
|
}
|
|
{ i18n.language == 'tm' &&
|
|
JSON.parse(item['translations'][1]['attribute_data']).title
|
|
}
|
|
|
|
</p>
|
|
<p className="law-card-bold">
|
|
{ i18n.language == 'en' &&
|
|
JSON.parse(item['translations'][0]['attribute_data']).content
|
|
}
|
|
{ i18n.language == 'ru' &&
|
|
item.content
|
|
}
|
|
{ i18n.language == 'tm' &&
|
|
JSON.parse(item['translations'][1]['attribute_data']).content
|
|
}
|
|
{/* {item.content} */}
|
|
|
|
</p>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|
|
};
|
|
|
|
export default withTranslation()(Legislation);
|