From 4f2275c1e54d62752d8a762ed8dda134b37ccf1a Mon Sep 17 00:00:00 2001 From: Z Date: Wed, 23 Oct 2019 15:16:10 +0800 Subject: [PATCH] click the node on tree to go to the status --- .../mastodon/features/status/index.js | 47 +++++-------------- 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/app/javascript/mastodon/features/status/index.js b/app/javascript/mastodon/features/status/index.js index 203e32be9..2763c7b0d 100644 --- a/app/javascript/mastodon/features/status/index.js +++ b/app/javascript/mastodon/features/status/index.js @@ -123,19 +123,18 @@ const makeMapStateToProps = () => { state => state.get('statuses'), ], (statusId, contextReplies, statuses) => { - const getMore = (id) => { + const getMore = (id, notRoot) => { const replies = contextReplies.get(id); const cur_status = statuses.get(id); const text = cur_status.get('search_index'); return { statusId: id, - ori_text: text, - name: (text.length > 13 ? text.slice(0,10) + "..." : text) + (cur_status.get('media_attachments').size > 0 ? " [图片]" : " "), - children: replies ? Array.from(replies.map( i => getMore(i) )) : [], + name: ((notRoot && text.length > 13) ? text.slice(0,10) + "..." : text) + (cur_status.get('media_attachments').size > 0 ? " [图片]" : ""), + children: replies ? Array.from(replies.map( i => getMore(i, true) )) : [], } } - let treeData = getMore(statusId) + let treeData = getMore(statusId, false) return treeData; }); @@ -482,23 +481,14 @@ class Status extends ImmutablePureComponent { handleNodeClick = (ev, node) => { console.log(node); - this.setState({activeNode: node}); - } - getRoot = (json) => { - if (json.statusId == this.state.activeNode) { - return json; - } - for (let i = 0; i < json.children.length; i++) { - let childJson = this.getRoot(json.children[i]); - if (childJson) { - return childJson; - } - } - //console.log('fail: ', json.name, ' != ', this.state.activeNode); - return false; - } + if (!this.context.router) { + return; + } + const { status } = this.props; + this.context.router.history.push(`/statuses/${node}`); + } render () { let ancestors, descendants; @@ -534,21 +524,6 @@ class Status extends ImmutablePureComponent { toggleSensitive: this.handleHotkeyToggleSensitive, }; - let root; - if(deep != null && showTree) { - //console.log("activeNode: ", activeNode); - root = activeNode ? this.getRoot(treeData) : treeData; - //console.log('first, root ='); - //console.log(root); - root = root ? root : treeData; - //console.log("treeData: "); - //console.log(treeData); - //console.log("root: "); - //console.log(root); - root.name = root.ori_text; - //console.log(root); - } - return (