This commit is contained in:
Kenneth Jannette
2024-03-11 02:21:40 -05:00
parent bb570a3186
commit 6ad82a7171

View File

@@ -156,42 +156,46 @@ const DocEditPage = (props) => {
} }
} }
async function getParsedRequests(docId, zib) { async function getParsedRequests(docId, docType) {
try { try {
fetch(`${apiUrl}/v1/get-parsed-requests/${documentId}/${zib}`, { const response = await fetch(
method: "GET", `${apiUrl}/getParsedRequests/${docId}/${docType}`,
}) {
.then(function (response) { method: "GET",
return response.json(); }
}) );
.then((data) => { const res = await response.json();
const respArray = data[0].responses; return res;
const result = respArray?.map((item, index) => {
let obj = {};
obj["showInputEle"] = false;
obj["resp"] = item.text;
obj["index"] = index;
return obj;
});
setParsedRogs(result);
});
} catch (err) { } catch (err) {
console.log("Error occured:", err); console.log("Error occured:", err);
} }
} }
useEffect(() => {
if (!documentId) {
return;
}
getParsedRequests(documentId, docType)
.then((data) => {
console.log(
"-------------------------data in useEffect for getParsedRequests",
data
);
})
.catch((err) => console.log(err));
}, [documentId]);
async function getCompletions(docId, docType) { async function getCompletions(docId, docType) {
if (!docId || !docType) { if (!docId || !docType) {
return; return;
} }
const response = await fetch( const response = await fetch(
`${apiUrl}/v1/get-completions/${docId}/${docType}`, `${apiUrl}/v1/get-parsed-requests/${docId}/${docType}`,
{ {
method: "GET", method: "GET",
} }
); );
const req = await response.json(); const req = await response.json();
console.log("req", req);
return req; return req;
} }
@@ -218,21 +222,32 @@ const DocEditPage = (props) => {
} }
getCompletions(documentId, docType) getCompletions(documentId, docType)
.then((data) => {}) .then((data) => {
console.log("data in getCompletions", data);
})
.catch((err) => console.log(err)); .catch((err) => console.log(err));
}, [documentId, docType]); }, [documentId, docType]);
/*
useEffect(() => { useEffect(() => {
if (!documentId || !docType) { if (!documentId || !docType) {
return; return;
} }
getParsedRequests(documentId, docType) getParsedRequests(documentId, docType)
.then((data) => {}) .then((data) => {
.catch((err) => console.log(err)); const resp = data[0].responses.map((item, index) => {
// NEVER CHANGE THIS:
return { showInputEle: false, resp: item.text, index: index };
});
return resp;
})
.then((resp) => {
setParsedRogs(resp);
})
.catch((err) => {
console.log("Error getting parsed requestas:", err);
});
}, [documentId, docType]); }, [documentId, docType]);
*/
async function postEditedResponses(docId, docType) { async function postEditedResponses(docId, docType) {
let obj = {}; let obj = {};
obj["type"] = docType; obj["type"] = docType;
@@ -436,7 +451,7 @@ const DocEditPage = (props) => {
const handleBack = () => { const handleBack = () => {
navigate(`/documents`); navigate(`/documents`);
}; };
console.log("parsedrogs", parsedRogs);
const editingContent = () => { const editingContent = () => {
return ( return (
<> <>