From a5e1d8b06a987fb4dc192bdf3a9f528ca6c77fa4 Mon Sep 17 00:00:00 2001 From: kdxcxs Date: Sat, 5 Dec 2020 17:22:29 +0800 Subject: [PATCH] refactor(YooForum): change `getTopicList` function --- src/component/YooForum.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/component/YooForum.js b/src/component/YooForum.js index 521d21c..4b496e5 100644 --- a/src/component/YooForum.js +++ b/src/component/YooForum.js @@ -14,6 +14,7 @@ export default class YooForum extends Component { this.state = { hint: '准备中', topics: [], + fetchedListPage: 0, }; this.initForum = this.initForum.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', }, ) - .then(() => { - this.getTopicList(); - }) + .then(this.getTopicList) .catch(ShowErrorToast); }) .catch(ShowErrorToast); @@ -101,7 +100,8 @@ export default class YooForum extends Component { .catch(ShowErrorToast); } - getTopicList(page = 1) { + getTopicList() { + const page = this.state.fetchedListPage + 1; this.setState({hint: '获取数据中'}); gbkFetch( 'GET', @@ -128,7 +128,11 @@ export default class YooForum extends Component { current.next().text(), ); }); - this.setState({topics: [...this.state.topics, ...newTopics], hint: ''}); + this.setState({ + topics: [...this.state.topics, ...newTopics], + hint: '', + fetchedListPage: page, + }); }); }