From 27ecfc4a86f3e35f245c1bca2d1dba57ff7364f2 Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 13 Aug 2024 17:58:49 +0800 Subject: [PATCH] feat: auto enable readability if no content Signed-off-by: Innei --- .../src/modules/entry-content/index.tsx | 69 ++++++++++++++----- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/src/renderer/src/modules/entry-content/index.tsx b/src/renderer/src/modules/entry-content/index.tsx index 72fab596e..880c7520b 100644 --- a/src/renderer/src/modules/entry-content/index.tsx +++ b/src/renderer/src/modules/entry-content/index.tsx @@ -1,3 +1,4 @@ +import { repository } from "@pkg" import { ReadabilityStatus, useEntryInReadabilityStatus, @@ -8,9 +9,8 @@ import { useUISettingKey } from "@renderer/atoms/settings/ui" import { useWhoami } from "@renderer/atoms/user" import { m } from "@renderer/components/common/Motion" import { AutoResizeHeight } from "@renderer/components/ui/auto-resize-height" -import { StyledButton } from "@renderer/components/ui/button" import { ScrollArea } from "@renderer/components/ui/scroll-area" -import { ROUTE_FEED_PENDING } from "@renderer/constants" +import { isWebBuild, ROUTE_FEED_PENDING } from "@renderer/constants" import { useEntryReadabilityToggle } from "@renderer/hooks/biz/useEntryActions" import { useRouteParamsSelector, @@ -81,7 +81,7 @@ function EntryContentRender({ entryId }: { entryId: string }) { const [content, setContent] = useState() const readerRenderInlineStyle = useUISettingKey("readerRenderInlineStyle") - useEffect(() => { + useLayoutEffect(() => { // Fallback data, if local data is broken should fallback to cached query data. const processContent = entry?.entries.content ?? data?.entries.content if (processContent) { @@ -306,7 +306,7 @@ const ReadabilityContent = ({ entryId }: { entryId: string }) => { const result = useEntryReadabilityContent(entryId) const [renderer, setRenderer] = useState(null) - useEffect(() => { + useLayoutEffect(() => { if (!result) return const { content: processContent } = result @@ -322,7 +322,7 @@ const ReadabilityContent = ({ entryId }: { entryId: string }) => { }, [result, parseHtml]) return ( -
+
{result ? (

@@ -330,8 +330,11 @@ const ReadabilityContent = ({ entryId }: { entryId: string }) => { anomalies, please go to the source site to view the original content.

) : ( -
+
+ + Fetching original content and processing... +
)} {renderer} @@ -343,27 +346,57 @@ const NoContent: FC<{ id: string url: string }> = ({ id, url }) => { - const toggle = useEntryReadabilityToggle({ - id, - url, - }) - const status = useEntryInReadabilityStatus(id) - if (status !== ReadabilityStatus.INITIAL) { + + if ( + status !== ReadabilityStatus.INITIAL && + status !== ReadabilityStatus.FAILURE + ) { return null } return (
- No content - {url && window.electron && ( -
- But you can try to get the source site's content and parse and - render it by using the button below. - Readability + {(isWebBuild || status === ReadabilityStatus.FAILURE) && ( + No content + )} + {isWebBuild && ( +
+ + Maybe web app doesn't support this content type. But you can + {" "} + + download + + {" "} + the desktop app. +
)} + {url && window.electron && }
) } + +const ReadabilityAutoToggle = ({ url, id }: { url: string, id: string }) => { + const toggle = useEntryReadabilityToggle({ + id, + url, + }) + const onceRef = useRef(false) + + useEffect(() => { + if (!onceRef.current) { + onceRef.current = true + toggle() + } + }, [toggle]) + + return null +}