add timeout

This commit is contained in:
ilia 2022-08-28 12:31:35 +03:00
parent 70fc7c27b4
commit e69b6007a1

View File

@ -8,7 +8,7 @@ import ClipLoader from "react-spinners/ClipLoader";
/* 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;
search_text.replace("\u0005", "")
console.log(search_text)
@ -19,7 +19,7 @@ const processFunction = (context: Word.RequestContext, search_text: string, comm
ignorePunct: true,
ignoreSpace: true
}
).getFirst().insertComment(comment_text);
).getFirst().insertComment(comment_text+ "\n" + "Оценка: " + score.toString());
}
return undefined
}
@ -28,8 +28,10 @@ const processFunction = (context: Word.RequestContext, search_text: string, comm
const App: React.FC = () => {
const [comments, setComments] = React.useState<Word.Comment[]>([]);
const [request_pull, setRequestPull] = React.useState(false)
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(() => {
if (uid.length) {
@ -37,22 +39,33 @@ const App: React.FC = () => {
const data: IEData = await update_state(uid);
console.log(data)
setResponseData(data);
}, 2000)
setRequestPull(false);
}, 10000)
setUid("");
}
if (response_data != undefined) {
Word.run(async (context) => {
var comments = []
var not_defined_fields = []
const response_data_keys = Object.keys(response_data)
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) {
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){
comments.push();
comments.push(comm);
}
}
}
setComments(comments)
setNotDefinedFields(not_defined_fields);
setResponseData(undefined)
//
})
@ -77,6 +90,7 @@ const App: React.FC = () => {
const data: IEUID = await load_docx(documentBody.text);
console.log(data);
setUid(data.uuid);
setRequestPull(true);
})
});
}}
@ -90,83 +104,19 @@ const App: React.FC = () => {
'marginTop': 100
}}>
{
response_data === undefined && uid.length ?
response_data == undefined && request_pull ?
<ClipLoader></ClipLoader> : <div></div>
}
</div>
<ul>
{
not_defined_fields.map((e) => {
<li>{e}</li>
})
}
</ul>
</div>
);
}
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>
// );
// }
// }