diff --git a/src/taskpane/components/App.tsx b/src/taskpane/components/App.tsx index 3cc9238..0db6792 100644 --- a/src/taskpane/components/App.tsx +++ b/src/taskpane/components/App.tsx @@ -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([]); + const [request_pull, setRequestPull] = React.useState(false) const [uid, setUid] = React.useState(""); - const [response_data, setResponseData] = React.useState(); + const [not_defined_fields, setNotDefinedFields] = React.useState([]); + const [response_data, setResponseData] = React.useState(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 ? :
} +
    + { + not_defined_fields.map((e) => { +
  • {e}
  • + }) + } +
); } export default App -// export default class App extends React.Component { -// 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 ( -// -// ); -// } - -// return ( -//
-//
-// -//

-// Modify the source files, then click Run. -//

-// -// Run -// -//
-//
-// ); -// } -// }