From bb008bc0fad7607d34c04e3bcc408866f24f6830 Mon Sep 17 00:00:00 2001 From: hole-thu Date: Fri, 4 Sep 2020 13:11:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/static/fonts_7/icomoon.css | 2 + src/Flows.js | 165 +++++++++++++++++++----------- src/UserAction.js | 2 +- src/flows_api.js | 20 +++- src/infrastructure/functions.js | 2 +- 5 files changed, 127 insertions(+), 64 deletions(-) diff --git a/public/static/fonts_7/icomoon.css b/public/static/fonts_7/icomoon.css index 49071f0..42842e1 100644 --- a/public/static/fonts_7/icomoon.css +++ b/public/static/fonts_7/icomoon.css @@ -108,3 +108,5 @@ .icon-eye-blocked:before { content: "\e9d1"; } +.icon-trash:before { + content: "\1f5d1"; diff --git a/src/Flows.js b/src/Flows.js index 56980d0..6436b52 100644 --- a/src/Flows.js +++ b/src/Flows.js @@ -93,26 +93,27 @@ class Reply extends PureComponent { } render() { - const author = this.props.info.name, - replyText = this.props.info.text; + const {info, color_picker, show_pid, do_filter_name, do_delete} = this.props; + const author = info.name, + replyText = info.text; return (
- {!!this.props.do_filter_name && ( + {!!do_filter_name && ( { - this.props.do_filter_name(this.props.info.name); + do_filter_name(info.name); }} > @@ -120,18 +121,29 @@ class Reply extends PureComponent { )}   {( - {this.props.info.name} + {info.name} )} -
@@ -167,10 +179,10 @@ class FlowItem extends PureComponent { } render() { - let props = this.props; + const {info, is_quote, cached, attention, can_del, do_filter_name, do_delete, timestamp, img_clickable, color_picker, show_pid} = this.props; return ( -
- {!!props.is_quote && ( +
+ {!!is_quote && (
@@ -182,96 +194,106 @@ class FlowItem extends PureComponent { )}
{!!window.LATEST_POST_ID && - parseInt(props.info.pid, 10) > window.LATEST_POST_ID && ( + parseInt(info.pid, 10) > window.LATEST_POST_ID && (
)} - {!!this.props.attention && !this.props.cached && ( + {!!attention && !cached && (
)}
- {!!this.props.do_filter_name && ( + {!!do_filter_name && ( { - this.props.do_filter_name(DZ_NAME); + do_filter_name(DZ_NAME); }} > )} - {!!parseInt(props.info.likenum, 10) && ( + {!!parseInt(info.likenum, 10) && ( - {props.info.likenum}  + {info.likenum}  )} - {!!parseInt(props.info.reply, 10) && ( + {!!parseInt(info.reply, 10) && ( - {props.info.reply}  + {info.reply}  )} - #{props.info.pid} + #{info.pid} + {!!do_delete && !!info.can_del && ( + { + do_delete('pid', info.pid); + }} + > + + + )}   - {props.info.cw !== null && ( - {props.info.cw} + {info.cw !== null && ( + {info.cw} )} -
- {props.info.type === 'image' && ( + {info.type === 'image' && (

- {props.img_clickable ? ( + {img_clickable ? ( { - if (e.target.src === IMAGE_BASE + props.info.url) { - e.target.src = IMAGE_BAK_BASE + props.info.url; + if (e.target.src === IMAGE_BASE + info.url) { + e.target.src = IMAGE_BAK_BASE + info.url; } }} - alt={IMAGE_BASE + props.info.url} + alt={IMAGE_BASE + info.url} /> ) : ( { - if (e.target.src === IMAGE_BASE + props.info.url) { - e.target.src = IMAGE_BAK_BASE + props.info.url; + if (e.target.src === IMAGE_BASE + info.url) { + e.target.src = IMAGE_BAK_BASE + info.url; } }} - alt={IMAGE_BASE + props.info.url} + alt={IMAGE_BASE + info.url} /> )}

)} - {/*{props.info.type==='audio' && }*/} + {/*{info.type==='audio' && }*/}
- {!!(props.attention && props.info.variant.latest_reply) && ( + {!!(attention && info.variant.latest_reply) && (

最新回复{' '} -

)}
@@ -441,6 +463,24 @@ class FlowSidebar extends PureComponent { } } + make_do_delete(token) { + const do_delete = (type, id) => { + console.log('del', type, id, token); + let note = prompt(`将删除${type}=${id}, 备注:`); + if (note !== null) { + API.del(type, id, note, token) + .then((json) => { + alert('删除成功'); + }) + .catch((e) => { + alert('删除失败\n' + e); + console.error(e); + }); + } + } + return do_delete; + } + render() { if (this.state.loading_status === 'loading') return

加载中……

; @@ -484,6 +524,7 @@ class FlowSidebar extends PureComponent { do_filter_name={ replies_cnt[DZ_NAME] > 1 ? this.set_filter_name.bind(this) : null } + do_delete={this.make_do_delete(this.props.token)} /> ); @@ -598,6 +639,7 @@ class FlowSidebar extends PureComponent { ? this.set_filter_name.bind(this) : null } + do_delete={this.make_do_delete(this.props.token)} /> @@ -1036,7 +1078,7 @@ export class Flow extends PureComponent { if (page > this.state.loaded_pages + 1) throw new Error('bad page'); if (page === this.state.loaded_pages + 1) { - //console.log('fetching page', page); + console.log('fetching page', page); cache(); if (this.state.mode === 'list') { API.get_list(page, this.props.token) @@ -1046,19 +1088,20 @@ export class Flow extends PureComponent { let max_id = -1; json.data.forEach((x) => { if (parseInt(x.pid, 10) > max_id) max_id = parseInt(x.pid, 10); - 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); - } - }); localStorage['_LATEST_POST_ID'] = '' + max_id; } + 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: 'News Feed', @@ -1105,10 +1148,10 @@ export class Flow extends PureComponent { let x = json.data; if (x.comments) { let comment_json = { - 'code': 0, - 'attention': x.attention, - 'data': x.comments - } + 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); } diff --git a/src/UserAction.js b/src/UserAction.js index 8c035a0..fdcbb75 100644 --- a/src/UserAction.js +++ b/src/UserAction.js @@ -291,7 +291,7 @@ export class ReplyForm extends Component { }) .catch((e) => { console.error(e); - alert('回复失败'); + alert('回复失败\n' + e); this.setState({ loading_status: 'done', }); diff --git a/src/flows_api.js b/src/flows_api.js index 593caf9..4f27dac 100644 --- a/src/flows_api.js +++ b/src/flows_api.js @@ -39,7 +39,7 @@ export const API = { ); let json = await handle_response(response); // Why delete then put ?? - console.log('Put cache', json, pid, cache_version); + //console.log('Put cache', json, pid, cache_version); cache().put(pid, cache_version, json); json.data = parse_replies(json.data, color_picker); return json; @@ -98,6 +98,24 @@ export const API = { return handle_response(response, true); }, + del: async (type, id, note, token) => { + let data = new URLSearchParams(); + data.append('type', type); + data.append('id', id); + data.append('note', note); + let response = await fetch( + API_BASE + '/delete' + token_param(token), + { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: data, + }, + ); + return handle_response(response, true); + }, + get_list: async (page, token) => { let response = await fetch( API_BASE + '/getlist' + token_param(token) + '&p=' + page, diff --git a/src/infrastructure/functions.js b/src/infrastructure/functions.js index ff2f2f5..d27743e 100644 --- a/src/infrastructure/functions.js +++ b/src/infrastructure/functions.js @@ -1,5 +1,5 @@ export function get_json(res) { - if(!res.ok) throw Error(`错误 ${res.status} ${res.statusText}`); + if(!res.ok) throw Error(`${res.status} ${res.statusText}`); return ( res .text()