Browse Source

feat: edit local attention

pull/16/head
hole-thu 3 years ago
parent
commit
9909f1a1c1
  1. 8
      src/Flows.css
  2. 85
      src/Flows.js

8
src/Flows.css

@ -334,7 +334,13 @@
} }
.export-btn { .export-btn {
float: right; position: absolute;
top: -25px;
right: 0;
}
.flow-container {
position: relative;
} }
.flow-submode-choice { .flow-submode-choice {

85
src/Flows.js

@ -1,4 +1,4 @@
import React, { PureComponent } from 'react'; import React, { PureComponent, useState } from 'react';
import copy from 'copy-to-clipboard'; import copy from 'copy-to-clipboard';
import { ColorPicker } from './color_picker'; import { ColorPicker } from './color_picker';
import { split_text, PID_RE } from './text_splitter'; import { split_text, PID_RE } from './text_splitter';
@ -1317,7 +1317,7 @@ class SubFlow extends PureComponent {
title: '', title: '',
data: [], data: [],
}, },
export_text: '', local_attention_text: null,
loading_status: 'done', loading_status: 'done',
error_msg: null, error_msg: null,
}; };
@ -1549,49 +1549,38 @@ class SubFlow extends PureComponent {
gen_export() { gen_export() {
this.setState({ this.setState({
can_export: false, can_export: false,
export_text: local_attention_text: JSON.parse(localStorage['saved_attentions'] || '[]')
'以下是你关注的洞及摘要,复制保存到本地吧。\n\n' + .map((pid) => `#${pid}`)
this.state.chunks.data .join(' '),
.map(
(p) =>
`#${p.pid}: ${this.trunc_string(
p.text.replaceAll('\n', ' '),
50,
)}`,
)
.join('\n\n'),
}); });
} }
render() { render() {
const should_deletion_detect = localStorage['DELETION_DETECT'] === 'on'; const should_deletion_detect = localStorage['DELETION_DETECT'] === 'on';
const { mode, chunks, local_attention_text, search_param } = this.state;
return ( return (
<div className="flow-container"> <div className="flow-container">
{this.state.mode === 'attention_finished' && this.props.submode == 0 && ( {mode === 'attention' &&
<button this.props.submode === 1 &&
className="export-btn" local_attention_text === null && (
type="button" <button
onClick={this.gen_export.bind(this)} className="export-btn"
> type="button"
导出 onClick={this.gen_export.bind(this)}
</button> >
)} 导出/导入
</button>
)}
{this.state.export_text && ( {local_attention_text && (
<div className="box"> <LocalAttentionEditer init_text={local_attention_text} />
<textarea
className="export-textarea"
value={this.state.export_text}
readOnly
/>
</div>
)} )}
<FlowChunk <FlowChunk
title={this.state.chunks.title} title={chunks.title}
list={this.state.chunks.data} list={chunks.data}
mode={this.state.mode} mode={mode}
search_param={this.state.search_param || null} search_param={search_param || null}
show_sidebar={this.props.show_sidebar} show_sidebar={this.props.show_sidebar}
deletion_detect={should_deletion_detect} deletion_detect={should_deletion_detect}
/> />
@ -1627,3 +1616,31 @@ class SubFlow extends PureComponent {
); );
} }
} }
function LocalAttentionEditer(props) {
const [text, setText] = useState(props.init_text);
const PID_RE = /#(\d+)/g;
const save = () => {
let pids = [...text.matchAll(PID_RE)]
.map((m) => parseInt(m[1]))
.sort((a, b) => b - a);
console.log(pids);
window.saved_attentions = pids;
save_attentions();
setText(pids.map((pid) => `#${pid}`).join(' '));
};
return (
<div className="box">
<textarea
className="export-textarea"
value={text}
onChange={(event) => setText(event.target.value)}
/>
<button className="export-btn" type="button" onClick={save}>
保存
</button>
</div>
);
}

Loading…
Cancel
Save