api fetch language full worked

This commit is contained in:
gerchek 2022-01-09 20:27:00 +05:00
parent b96290f32c
commit 40ca3639f3
2 changed files with 43 additions and 59 deletions

File diff suppressed because one or more lines are too long

View File

@ -12,7 +12,7 @@ import Breadcrumb from "../components/Global/Breadcrumb";
import NoveltyIMG from "../img/noveltyImg.jpg";
class Novelty extends React.Component {
_isMounted = false;
constructor(props) {
super(props);
@ -26,72 +26,47 @@ class Novelty extends React.Component {
}
componentDidMount() {
// this.mounted = true;
if(i18n.language == 'en')
this.getTodos();
}
getTodos() {
this._isMounted = true;
axios.get('http://127.0.0.1:8000/api/v1/posts/'+this.props.match.params.slug)
.then(res =>
{
const items = res.data;
if (this._isMounted) {
this.setState({
items: items,
DataisLoaded: true
});
let elem = document.querySelector('.novelty-text');
if(i18n.language == 'ru')
{
this.getTodosEn();
elem.innerHTML= this.state.items['data'][0][0]['content'];
}
else
{
this.getTodosRu();
}
}
// componentWillUnmount(){
// this.getTodosEn();
// this.getTodosRu();
// }
getTodosEn() {
axios.get('http://127.0.0.1:8000/api/v1/posts/'+this.props.match.params.slug)
.then(res =>
{
const items = res.data;
this.setState({
items: items,
DataisLoaded: true
});
let elem = document.querySelector('.novelty-text');
if(elem)
{
elem.innerHTML= JSON.parse(this.state.items['data'][0][0]['translations'][0]['attribute_data']).content;
}
}
}
)
}
componentWillUnmount() {
}
)
this._isMounted = false;
console.log("salam");
}
getTodosRu() {
axios.get('http://127.0.0.1:8000/api/v1/posts/'+this.props.match.params.slug)
.then(res =>
{
const items = res.data;
this.setState({
items: items,
DataisLoaded: true
});
let elem = document.querySelector('.novelty-text');
if(elem)
{
elem.innerHTML= this.state.items['data'][0][0]['content'];
}
}
)
}
render() {
// console.log(this.state.items);
// console.log(this.state.items.data);
// console.log(this.state.test+'salam');
const { t } = this.props;
const { DataisLoaded, items } = this.state;
if (!DataisLoaded) return <div>
@ -104,7 +79,6 @@ class Novelty extends React.Component {
}
else
{
this.componentDidMount();
}