Commit 5057bd8e authored by Megha kundar's avatar Megha kundar Committed by Megha kundar
Browse files

Issue #3266660 by Megha_kundar: Replace jQuery.getJSON with axios

parent d0f82fc6
Loading
Loading
Loading
Loading
+15 −2

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+12276 −0

File added.

Preview size limit exceeded, changes collapsed.

+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
    "webpack": "^2.2.1"
  },
  "dependencies": {
    "axios": "^0.26.0",
    "babel-polyfill": "^6.16.0",
    "lodash": "^4.17.4",
    "react": "^15.3.2",
+29 −29
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import Notification from './Notification'
import Post from './Post'

import lodash from 'lodash'
import axios from 'axios';

export default class Posts extends Component {
  constructor() {
@@ -20,18 +21,16 @@ export default class Posts extends Component {
  }

  componentWillMount() {
    // TODO Handle errors
    jQuery.getJSON(this.props.getURL, (posts) => {
    axios.get(this.props.getURL).
      then(posts => {
        if (Array.isArray(posts.content)) {
          this.setState({
            posts: posts.content
          })
          this.props.onPostLoad(posts, document.body)
        }
      else {
        // TODO Handle empty
      }
      })
      .catch((error) => console.log('error', error));

    addEventListener('scroll', this.lazyloadListener)
  }
@@ -63,8 +62,8 @@ export default class Posts extends Component {
    const posts = this.state.posts
    const lastPost = posts[posts.length - 1]
    const url = this.props.getNextURL.replace('%s', lastPost.created)
    // TODO: error handling
    jQuery.getJSON(url, (lazyPosts) => {
    axios.get(url).
      then(lazyPosts => {
        if (lazyPosts && Array.isArray(lazyPosts.content)) {
          if (lazyPosts.content.length != 0) {
            this.setState({
@@ -82,6 +81,7 @@ export default class Posts extends Component {

        this.isloading = false
      })
      .catch((error) => console.log('error', error));
  }

  addPost(post) {
Loading