Skip to content

Commit

Permalink
show error message for multi-articles page
Browse files Browse the repository at this point in the history
  • Loading branch information
yaozhiwang committed Apr 19, 2023
1 parent c90e196 commit c3a2130
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/contents/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { usePageContent } from "./hooks/page-content"
import {
SummaryContent,
SummaryStatus,
isDoneStatus,
isRunningStatus,
useSummaryContent
} from "./hooks/summary-content"
Expand Down Expand Up @@ -159,7 +160,8 @@ const PanelOverlay = () => {
}

if (articleSummary) {
if (articleSummary.status !== SummaryStatus.Finish) {
if (articleSummary.status === SummaryStatus.Generating) {
text += getArticleHeader(pageSummary.length)
text += articleSummary.data
}
}
Expand Down Expand Up @@ -189,15 +191,14 @@ const PanelOverlay = () => {
let text = ""
text += pageSummary
.map((article, idx) => {
let lines = []
if (pageContent.articles.length > 1) {
lines.push(`Article #${idx + 1}`)
let articleText = getArticleHeader(idx)
if (article.status === SummaryStatus.Finish) {
articleText += `Summary: ${article.data}`
} else if (article.status === SummaryStatus.Error) {
articleText += `Error: ${article.data.message}\n`
}
if (pageContent.articles[idx].title) {
lines.push(`Title: ${pageContent.articles[idx].title}`)
lines.push(`Summary: ${article.data}`)
}
return lines.join("\n")

return articleText
})
.join("\n\n")

Expand All @@ -206,7 +207,7 @@ const PanelOverlay = () => {

useEffect(() => {
if (articleSummary) {
if (articleSummary.status === SummaryStatus.Finish) {
if (isDoneStatus(articleSummary.status)) {
const newPageSummary = [...pageSummary]
newPageSummary.push(articleSummary)
if (newPageSummary.length < pageContent.articles.length) {
Expand Down Expand Up @@ -269,6 +270,17 @@ const PanelOverlay = () => {
startSummarizeArticle(pageContentRef.current.articles[0].content)
}

function getArticleHeader(idx: number) {
let text = ""
if (pageContent.articles.length > 1) {
text += `Article #${idx + 1}\n`
}
if (pageContent.articles[idx].title) {
text += `Title: ${pageContent.articles[idx].title}\n`
}
return text
}

return (
<>
{show && position !== undefined ? (
Expand Down
5 changes: 5 additions & 0 deletions tests/multiple-articles.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ <h3> h3-s1-1-2-2 </h3>
h3-s1-1-2-2
</section>
</article>

<article>
<script>document.querySelectorAll("h1")</script>
</article>

<article>
<header>
<h2>Article Title 2</h2>
Expand Down

0 comments on commit c3a2130

Please sign in to comment.