加载本地收藏
This commit is contained in:
43
src/Flows.js
43
src/Flows.js
@@ -1271,7 +1271,7 @@ export class Flow extends PureComponent {
|
|||||||
case('list'):
|
case('list'):
|
||||||
return ['最新', '最近回复', '近期热门', '随机'];
|
return ['最新', '最近回复', '近期热门', '随机'];
|
||||||
case('attention'):
|
case('attention'):
|
||||||
return ['线上', '本地']
|
return ['线上关注', '本地收藏']
|
||||||
}
|
}
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
@@ -1480,19 +1480,46 @@ class SubFlow extends PureComponent {
|
|||||||
...window.saved_attentions,
|
...window.saved_attentions,
|
||||||
...json.data.map(post => post.pid)
|
...json.data.map(post => post.pid)
|
||||||
])
|
])
|
||||||
).sort().reverse();
|
).sort((a, b) => (b - a));
|
||||||
save_attentions();
|
save_attentions();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(failed);
|
.catch(failed);
|
||||||
} else if (this.props.submode === 1) {
|
} else if (this.props.submode === 1) {
|
||||||
this.setState({
|
const PERPAGE = 50;
|
||||||
title: 'Attention List: Local',
|
let pids = window.saved_attentions.sort(
|
||||||
data: [],
|
(a, b) => (b - a)
|
||||||
export_text: `以下是浏览器本地保存的关注列表,将在下个版本提供直接展示\n\n#${
|
).slice((page - 1) * PERPAGE, page * PERPAGE);
|
||||||
window.saved_attentions.join('\n#')
|
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 {
|
} else {
|
||||||
console.log('nothing to load');
|
console.log('nothing to load');
|
||||||
|
|||||||
@@ -239,4 +239,16 @@ export const API = {
|
|||||||
);
|
);
|
||||||
return handle_response(response, true);
|
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);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user