Browse Source

refactor(YooForum): change `getTopicList` function

dev
kdxcxs 4 years ago
parent
commit
a5e1d8b06a
  1. 14
      src/component/YooForum.js

14
src/component/YooForum.js

@ -14,6 +14,7 @@ export default class YooForum extends Component {
this.state = { this.state = {
hint: '准备中', hint: '准备中',
topics: [], topics: [],
fetchedListPage: 0,
}; };
this.initForum = this.initForum.bind(this); this.initForum = this.initForum.bind(this);
this.getTopicList = this.getTopicList.bind(this); this.getTopicList = this.getTopicList.bind(this);
@ -87,9 +88,7 @@ export default class YooForum extends Component {
'http://eol.ctbu.edu.cn/meol/jpk/course/layout/newpage/index.jsp?courseId=46445', 'http://eol.ctbu.edu.cn/meol/jpk/course/layout/newpage/index.jsp?courseId=46445',
}, },
) )
.then(() => { .then(this.getTopicList)
this.getTopicList();
})
.catch(ShowErrorToast); .catch(ShowErrorToast);
}) })
.catch(ShowErrorToast); .catch(ShowErrorToast);
@ -101,7 +100,8 @@ export default class YooForum extends Component {
.catch(ShowErrorToast); .catch(ShowErrorToast);
} }
getTopicList(page = 1) { getTopicList() {
const page = this.state.fetchedListPage + 1;
this.setState({hint: '获取数据中'}); this.setState({hint: '获取数据中'});
gbkFetch( gbkFetch(
'GET', 'GET',
@ -128,7 +128,11 @@ export default class YooForum extends Component {
current.next().text(), current.next().text(),
); );
}); });
this.setState({topics: [...this.state.topics, ...newTopics], hint: ''}); this.setState({
topics: [...this.state.topics, ...newTopics],
hint: '',
fetchedListPage: page,
});
}); });
} }

Loading…
Cancel
Save