Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to fix analysis panel freeze #938

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 93 additions & 60 deletions app/frontend/src/components/AnalysisPanel/AnalysisPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,82 +78,115 @@ export const AnalysisPanel = ({ answer, activeTab, activeCitation, sourceFile, p
if (sourceFileBlob === undefined) {
if (!isFetchingSourceFileBlob) {
setIsFetchingSourceFileBlob(true);
sourceFileBlobPromise = fetchCitationSourceFile().finally(() => {
if (sourceFileUrl !== undefined) {
sourceFileBlobPromise = fetchCitationSourceFile().finally(() => {
setIsFetchingSourceFileBlob(false);
});
} else {
console.error("sourceFileUrl is undefined");
setIsFetchingSourceFileBlob(false);
});
}
}
await sourceFileBlobPromise;
}
};
fetchSourceFileBlob();
return sourceFileUrl;

if (sourceFileBlob !== undefined) {
fetchSourceFileBlob();

}
return sourceFileUrl ?? '';
}

async function fetchActiveCitationObj() {
async function fetchActiveCitationObj() {
try {
if (!activeCitation) {
console.warn('Active citation is undefined');
setActiveCitationObj(undefined);
return;
}
const citationObj = await getCitationObj(activeCitation);
setActiveCitationObj(citationObj);
console.log(citationObj);
} catch (error) {
// Handle the error here
console.log(error);
}
}

useEffect(() => {
const fetchMarkdownContent = async () => {
try {
const citationObj = await getCitationObj(activeCitation as string);
setActiveCitationObj(citationObj);
console.log(citationObj);
if (!sourceFile) {
console.error('Source file is undefined');
return;
}
const citationURL = getCitationURL();
if (!citationURL) {
throw new Error('Citation URL is undefined');
}
const response = await fetch(citationURL);
const content = await response.text();
setMarkdownContent(content);
} catch (error) {
// Handle the error here
console.log(error);
console.error('Error fetching Markdown content:', error);
}
}
};

fetchMarkdownContent();
}, [sourceFileBlob, sourceFileExt]);

useEffect(() => {
if (!sourceFile) {
return;
}
const fetchMarkdownContent = async () => {
try {
const response = await fetch(getCitationURL());
const content = await response.text();
setMarkdownContent(content);
} catch (error) {
console.error('Error fetching Markdown content:', error);
useEffect(() => {
const fetchPlainTextContent = async () => {
try {
if (!sourceFile) {
console.error('Source file is undefined');
return;
}
};

fetchMarkdownContent();
}, [sourceFileBlob, sourceFileExt]);

useEffect(() => {
const fetchPlainTextContent = async () => {
try {
const response = await fetch(getCitationURL());
const content = await response.text();
setPlainTextContent(content);
} catch (error) {
console.error('Error fetching plain text content:', error);
const citationURL = getCitationURL();
if (!citationURL) {
throw new Error('Citation URL is undefined');
}
};

if (["json", "txt", "xml"].includes(sourceFileExt)) {
fetchPlainTextContent();
const response = await fetch(citationURL);
const content = await response.text();
setPlainTextContent(content);
} catch (error) {
console.error('Error fetching plain text content:', error);
}
}, [sourceFileBlob, sourceFileExt]);
};

if (["json", "txt", "xml"].includes(sourceFileExt)) {
fetchPlainTextContent();
}
}, [sourceFileBlob, sourceFileExt]);

useEffect(() => {
if (activeCitation) {
setInnerPivotTab('indexedFile');
} else {
console.warn('Active citation is undefined');
setActiveCitationObj(undefined);
}

useEffect(() => {
if (activeCitation) {
setInnerPivotTab('indexedFile');
fetchActiveCitationObj();

const fetchSourceFileBlob = async () => {
if (!sourceFile) {
console.error('Source file is undefined');
return;
}
fetchActiveCitationObj();
const fetchSourceFileBlob = async () => {

if (!isFetchingSourceFileBlob) {
setIsFetchingSourceFileBlob(true);
sourceFileBlobPromise = fetchCitationSourceFile().finally(() => {
setIsFetchingSourceFileBlob(false);
});
}
await sourceFileBlobPromise;

};
fetchSourceFileBlob();

}, [activeCitation]);
if (!isFetchingSourceFileBlob) {
setIsFetchingSourceFileBlob(true);
sourceFileBlobPromise = fetchCitationSourceFile().finally(() => {
setIsFetchingSourceFileBlob(false);
});
}
await sourceFileBlobPromise;
};

fetchSourceFileBlob();
}, [activeCitation]);
return (
<Pivot
className={className}
Expand Down Expand Up @@ -221,11 +254,11 @@ export const AnalysisPanel = ({ answer, activeTab, activeCitation, sourceFile, p
)}
</PivotItem>
<PivotItem itemKey="rawFile" headerText="Document">
{getCitationURL() === '' ? (
{getCitationURL() === '' ? (
<Text>Loading...</Text>
) : ["docx", "xlsx", "pptx"].includes(sourceFileExt) ? (
// Treat other Office formats like "xlsx" for the Office Online Viewer
<iframe title="Source File" src={'https://view.officeapps.live.com/op/view.aspx?src=' + encodeURIComponent(getCitationURL()) + "&action=embedview&wdStartOn=" + pageNumber} width="100%" height={citationHeight} />
<iframe title="Source File" src={'https://view.officeapps.live.com/op/view.aspx?src=' + encodeURIComponent(getCitationURL()) + "&action=embedview&wdStartOn=" + (pageNumber ?? '')} width="100%" height={citationHeight} />
) : sourceFileExt === "pdf" ? (
// Use object tag for PDFs because iframe does not support page numbers
<object data={getCitationURL() + "#page=" + pageNumber} type="application/pdf" width="100%" height={citationHeight} />
Expand All @@ -245,4 +278,4 @@ export const AnalysisPanel = ({ answer, activeTab, activeCitation, sourceFile, p

</Pivot>
);
};
};
Loading