mirror of
https://github.com/Ai-hack-MAGNUM-OPUS/word-plugin.git
synced 2024-11-22 00:06:35 +03:00
add timeout
This commit is contained in:
parent
70fc7c27b4
commit
e69b6007a1
|
@ -8,7 +8,7 @@ import ClipLoader from "react-spinners/ClipLoader";
|
||||||
/* global Word, require */
|
/* global Word, require */
|
||||||
|
|
||||||
|
|
||||||
const processFunction = (context: Word.RequestContext, search_text: string, comment_text: string) => {
|
const processFunction = (context: Word.RequestContext, search_text: string, comment_text: string, score: number) => {
|
||||||
//if (search_text.includes("\u")) return undefined;
|
//if (search_text.includes("\u")) return undefined;
|
||||||
search_text.replace("\u0005", "")
|
search_text.replace("\u0005", "")
|
||||||
console.log(search_text)
|
console.log(search_text)
|
||||||
|
@ -19,7 +19,7 @@ const processFunction = (context: Word.RequestContext, search_text: string, comm
|
||||||
ignorePunct: true,
|
ignorePunct: true,
|
||||||
ignoreSpace: true
|
ignoreSpace: true
|
||||||
}
|
}
|
||||||
).getFirst().insertComment(comment_text);
|
).getFirst().insertComment(comment_text+ "\n" + "Оценка: " + score.toString());
|
||||||
}
|
}
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,10 @@ const processFunction = (context: Word.RequestContext, search_text: string, comm
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
|
|
||||||
const [comments, setComments] = React.useState<Word.Comment[]>([]);
|
const [comments, setComments] = React.useState<Word.Comment[]>([]);
|
||||||
|
const [request_pull, setRequestPull] = React.useState(false)
|
||||||
const [uid, setUid] = React.useState("");
|
const [uid, setUid] = React.useState("");
|
||||||
const [response_data, setResponseData] = React.useState<IEData>();
|
const [not_defined_fields, setNotDefinedFields] = React.useState<string[]>([]);
|
||||||
|
const [response_data, setResponseData] = React.useState<IEData>(undefined);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (uid.length) {
|
if (uid.length) {
|
||||||
|
@ -37,22 +39,33 @@ const App: React.FC = () => {
|
||||||
const data: IEData = await update_state(uid);
|
const data: IEData = await update_state(uid);
|
||||||
console.log(data)
|
console.log(data)
|
||||||
setResponseData(data);
|
setResponseData(data);
|
||||||
}, 2000)
|
setRequestPull(false);
|
||||||
|
}, 10000)
|
||||||
setUid("");
|
setUid("");
|
||||||
}
|
}
|
||||||
if (response_data != undefined) {
|
if (response_data != undefined) {
|
||||||
Word.run(async (context) => {
|
Word.run(async (context) => {
|
||||||
var comments = []
|
var comments = []
|
||||||
|
var not_defined_fields = []
|
||||||
const response_data_keys = Object.keys(response_data)
|
const response_data_keys = Object.keys(response_data)
|
||||||
for (var i = 0; i < response_data_keys.length; ++i) {
|
for (var i = 0; i < response_data_keys.length; ++i) {
|
||||||
|
if (!response_data[response_data_keys[i]].length) {
|
||||||
|
not_defined_fields.push(response_data_keys[i])
|
||||||
|
}
|
||||||
for (var j = 0; j < response_data[response_data_keys[i]].length; ++j) {
|
for (var j = 0; j < response_data[response_data_keys[i]].length; ++j) {
|
||||||
var comm = processFunction(context, response_data[response_data_keys[i]][j][0], response_data_keys[i]);
|
var comm = processFunction(
|
||||||
|
context,
|
||||||
|
response_data[response_data_keys[i]][j][0],
|
||||||
|
response_data_keys[i],
|
||||||
|
response_data[response_data_keys[i]][j][1]
|
||||||
|
);
|
||||||
if (comm != undefined){
|
if (comm != undefined){
|
||||||
comments.push();
|
comments.push(comm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setComments(comments)
|
setComments(comments)
|
||||||
|
setNotDefinedFields(not_defined_fields);
|
||||||
setResponseData(undefined)
|
setResponseData(undefined)
|
||||||
//
|
//
|
||||||
})
|
})
|
||||||
|
@ -77,6 +90,7 @@ const App: React.FC = () => {
|
||||||
const data: IEUID = await load_docx(documentBody.text);
|
const data: IEUID = await load_docx(documentBody.text);
|
||||||
console.log(data);
|
console.log(data);
|
||||||
setUid(data.uuid);
|
setUid(data.uuid);
|
||||||
|
setRequestPull(true);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
@ -90,83 +104,19 @@ const App: React.FC = () => {
|
||||||
'marginTop': 100
|
'marginTop': 100
|
||||||
}}>
|
}}>
|
||||||
{
|
{
|
||||||
response_data === undefined && uid.length ?
|
response_data == undefined && request_pull ?
|
||||||
<ClipLoader></ClipLoader> : <div></div>
|
<ClipLoader></ClipLoader> : <div></div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
<ul>
|
||||||
|
{
|
||||||
|
not_defined_fields.map((e) => {
|
||||||
|
<li>{e}</li>
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
export default App
|
export default App
|
||||||
// export default class App extends React.Component<AppProps, AppState> {
|
|
||||||
// constructor(props, context) {
|
|
||||||
// super(props, context);
|
|
||||||
// this.state = {
|
|
||||||
// listItems: [],
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// componentDidMount() {
|
|
||||||
// this.setState({
|
|
||||||
// listItems: [
|
|
||||||
// {
|
|
||||||
// icon: "Ribbon",
|
|
||||||
// primaryText: "Achieve more with Office integration",
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// icon: "Unlock",
|
|
||||||
// primaryText: "Unlock features and functionality",
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// icon: "Design",
|
|
||||||
// primaryText: "Create and visualize like a pro",
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// click = async () => {
|
|
||||||
// return Word.run(async (context) => {
|
|
||||||
// /**
|
|
||||||
// * Insert your Word code here
|
|
||||||
// */
|
|
||||||
|
|
||||||
// // insert a paragraph at the end of the document.
|
|
||||||
// const paragraph = context.document.body.insertParagraph("Hello World", Word.InsertLocation.end);
|
|
||||||
|
|
||||||
// // change the paragraph color to blue.
|
|
||||||
// paragraph.font.color = "blue";
|
|
||||||
|
|
||||||
// await context.sync();
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
|
|
||||||
// render() {
|
|
||||||
// const { title, isOfficeInitialized } = this.props;
|
|
||||||
|
|
||||||
// if (!isOfficeInitialized) {
|
|
||||||
// return (
|
|
||||||
// <Progress
|
|
||||||
// title={title}
|
|
||||||
// logo={require("./../../../assets/logo-filled.png")}
|
|
||||||
// message="Please sideload your addin to see app body."
|
|
||||||
// />
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return (
|
|
||||||
// <div className="ms-welcome">
|
|
||||||
// <Header logo={require("./../../../assets/logo-filled.png")} title={this.props.title} message="Welcome" />
|
|
||||||
// <HeroList message="Discover what Office Add-ins can do for you today!" items={this.state.listItems}>
|
|
||||||
// <p className="ms-font-l">
|
|
||||||
// Modify the source files, then click <b>Run</b>.
|
|
||||||
// </p>
|
|
||||||
// <DefaultButton className="ms-welcome__action" iconProps={{ iconName: "ChevronRight" }} onClick={this.click}>
|
|
||||||
// Run
|
|
||||||
// </DefaultButton>
|
|
||||||
// </HeroList>
|
|
||||||
// </div>
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user