Browse Source

click the node on tree to go to the status

pull/4/head
欧醚 5 years ago
parent
commit
4f2275c1e5
1 changed files with 11 additions and 36 deletions
  1. +11
    -36
      app/javascript/mastodon/features/status/index.js

+ 11
- 36
app/javascript/mastodon/features/status/index.js View File

@ -123,19 +123,18 @@ const makeMapStateToProps = () => {
state => state.get('statuses'), state => state.get('statuses'),
], (statusId, contextReplies, statuses) => { ], (statusId, contextReplies, statuses) => {
const getMore = (id) => {
const getMore = (id, notRoot) => {
const replies = contextReplies.get(id); const replies = contextReplies.get(id);
const cur_status = statuses.get(id); const cur_status = statuses.get(id);
const text = cur_status.get('search_index'); const text = cur_status.get('search_index');
return { return {
statusId: id, 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; return treeData;
}); });
@ -482,23 +481,14 @@ class Status extends ImmutablePureComponent {
handleNodeClick = (ev, node) => { handleNodeClick = (ev, node) => {
console.log(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 () { render () {
let ancestors, descendants; let ancestors, descendants;
@ -534,21 +524,6 @@ class Status extends ImmutablePureComponent {
toggleSensitive: this.handleHotkeyToggleSensitive, 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 ( return (
<Column bindToDocument={!multiColumn} label={intl.formatMessage(messages.detailedStatus)}> <Column bindToDocument={!multiColumn} label={intl.formatMessage(messages.detailedStatus)}>
<ColumnHeader <ColumnHeader
@ -568,7 +543,7 @@ class Status extends ImmutablePureComponent {
{showTree ? {showTree ?
<Tree <Tree
data={root}
data={treeData}
height={800} height={800}
width={svgWidth} width={svgWidth}
animated animated

Loading…
Cancel
Save