From 74c6857b832bc100bd4f75af8e627b46e00c8a8e Mon Sep 17 00:00:00 2001 From: hole-thu Date: Thu, 23 Dec 2021 00:13:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E6=9C=AC=E5=9C=B0=E6=94=B6?= =?UTF-8?q?=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Flows.js | 45 ++++++++++++++++++++++++++++++++++++--------- src/flows_api.js | 12 ++++++++++++ 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/Flows.js b/src/Flows.js index 9249305..59251d7 100644 --- a/src/Flows.js +++ b/src/Flows.js @@ -1271,7 +1271,7 @@ export class Flow extends PureComponent { case('list'): return ['最新', '最近回复', '近期热门', '随机']; case('attention'): - return ['线上', '本地'] + return ['线上关注', '本地收藏'] } return [] } @@ -1480,19 +1480,46 @@ class SubFlow extends PureComponent { ...window.saved_attentions, ...json.data.map(post => post.pid) ]) - ).sort().reverse(); + ).sort((a, b) => (b - a)); save_attentions(); } }) .catch(failed); } else if (this.props.submode === 1) { - this.setState({ - title: 'Attention List: Local', - data: [], - export_text: `以下是浏览器本地保存的关注列表,将在下个版本提供直接展示\n\n#${ - window.saved_attentions.join('\n#') - }` - }); + const PERPAGE = 50; + let pids = window.saved_attentions.sort( + (a, b) => (b - a) + ).slice((page - 1) * PERPAGE, page * PERPAGE); + if (pids.length) { + API.get_multi(pids, this.props.token) + .then((json) => { + json.data.forEach((x) => { + if (x.comments) { + let comment_json = { + code: 0, + attention: x.attention, + data: x.comments, + }; + //console.log('My cache', comment_json, x.pid, x.reply) + cache().put(x.pid, parseInt(x.reply, 10), comment_json); + } + }); + this.setState((prev, props) => ({ + chunks: { + title: 'Attention List: Local', + data: prev.chunks.data.concat(json.data), + }, + loading_status: 'done', + })); + }); + } else { + console.log('local attention finished'); + this.setState({ + loading_status: 'done', + mode: 'attention_finished' + }); + return; + } } } else { console.log('nothing to load'); diff --git a/src/flows_api.js b/src/flows_api.js index 47f990d..edec38f 100644 --- a/src/flows_api.js +++ b/src/flows_api.js @@ -239,4 +239,16 @@ export const API = { ); return handle_response(response, true); }, + + get_multi: async (pids, token) => { + let response = await fetch( + API_BASE + '/getmulti?' + pids.map(pid => `pids=${pid}`).join('&'), + { + headers: { + 'User-Token': token, + }, + }, + ); + return handle_response(response, true); + }, };